Skip to content

Commit a750f8f

Browse files
committed
Fixed linter findings, formatted code
1 parent 00a1a35 commit a750f8f

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

INDEX.rst

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ testcontainers-python facilitates the use of Docker containers for functional an
3636
modules/redis/README
3737
modules/selenium/README
3838
modules/k3s/README
39+
modules/registry/README
3940

4041
Getting Started
4142
---------------

modules/registry/testcontainers/registry/__init__.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import time
22
from io import BytesIO
33
from tarfile import TarFile, TarInfo
4-
from typing import Optional
4+
from typing import TYPE_CHECKING, Optional
55

66
import bcrypt
7-
from requests import Response, get
7+
from requests import get
88
from requests.auth import HTTPBasicAuth
99
from requests.exceptions import ConnectionError, ReadTimeout
10+
1011
from testcontainers.core.container import DockerContainer
1112
from testcontainers.core.waiting_utils import wait_container_is_ready
1213

14+
if TYPE_CHECKING:
15+
from requests import Response
16+
17+
1318
class DockerRegistryContainer(DockerContainer):
1419
# https://docs.docker.com/registry/
1520
credentials_path: str = "/htpasswd/credentials.txt"
@@ -18,8 +23,8 @@ def __init__(
1823
self,
1924
image: str = "registry:2",
2025
port: int = 5000,
21-
username: str = None,
22-
password: str = None,
26+
username: Optional[str] = None,
27+
password: Optional[str] = None,
2328
**kwargs,
2429
) -> None:
2530
super().__init__(image=image, **kwargs)
@@ -34,11 +39,9 @@ def _copy_credentials(self) -> None:
3439
self.password.encode("utf-8"),
3540
bcrypt.gensalt(rounds=12, prefix=b"2a"),
3641
).decode("utf-8")
37-
content = f"{self.username}:{hashed_password}".encode("utf-8")
42+
content: bytes = f"{self.username}:{hashed_password}".encode("utf-8") # noqa: UP012
3843

39-
with BytesIO() as tar_archive_object, TarFile(
40-
fileobj=tar_archive_object, mode="w"
41-
) as tmp_tarfile:
44+
with BytesIO() as tar_archive_object, TarFile(fileobj=tar_archive_object, mode="w") as tmp_tarfile:
4245
tarinfo: TarInfo = TarInfo(name=self.credentials_path)
4346
tarinfo.size = len(content)
4447
tarinfo.mtime = time.time()
@@ -65,7 +68,7 @@ def start(self):
6568
else:
6669
super().start()
6770

68-
self._readiness_probe()
71+
self._readiness_probe()
6972
return self
7073

7174
def get_registry(self) -> str:

modules/registry/tests/test_registry.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

66
REGISTRY_USERNAME: str = "foo"
7-
REGISTRY_PASSWORD: str ="bar"
7+
REGISTRY_PASSWORD: str = "bar"
8+
89

910
def test_registry():
1011
with DockerRegistryContainer().with_bind_ports(5000, 5000) as registry_container:
@@ -16,9 +17,9 @@ def test_registry():
1617

1718

1819
def test_registry_with_authentication():
19-
with DockerRegistryContainer(
20-
username=REGISTRY_USERNAME, password=REGISTRY_PASSWORD
21-
).with_bind_ports(5000, 5000) as registry_container:
20+
with DockerRegistryContainer(username=REGISTRY_USERNAME, password=REGISTRY_PASSWORD).with_bind_ports(
21+
5000, 5000
22+
) as registry_container:
2223
url: str = f"http://{registry_container.get_registry()}/v2/_catalog"
2324

2425
response: Response = get(url, auth=HTTPBasicAuth(REGISTRY_USERNAME, REGISTRY_PASSWORD))

0 commit comments

Comments
 (0)