Skip to content

Commit 6b11268

Browse files
authored
fix(registry): module typed (#811)
1 parent e90d308 commit 6b11268

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

modules/registry/testcontainers/registry/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from io import BytesIO
33
from tarfile import TarFile, TarInfo
4-
from typing import TYPE_CHECKING, Optional
4+
from typing import TYPE_CHECKING, Any, Optional
55

66
import bcrypt
77
from requests import get
@@ -25,7 +25,7 @@ def __init__(
2525
port: int = 5000,
2626
username: Optional[str] = None,
2727
password: Optional[str] = None,
28-
**kwargs,
28+
**kwargs: Any,
2929
) -> None:
3030
super().__init__(image=image, **kwargs)
3131
self.port: int = port
@@ -35,6 +35,8 @@ def __init__(
3535

3636
def _copy_credentials(self) -> None:
3737
# Create credentials and write them to the container
38+
if self.password is None:
39+
raise ValueError("Password cannot be None")
3840
hashed_password: str = bcrypt.hashpw(
3941
self.password.encode("utf-8"),
4042
bcrypt.gensalt(rounds=12, prefix=b"2a"),
@@ -44,7 +46,7 @@ def _copy_credentials(self) -> None:
4446
with BytesIO() as tar_archive_object, TarFile(fileobj=tar_archive_object, mode="w") as tmp_tarfile:
4547
tarinfo: TarInfo = TarInfo(name=self.credentials_path)
4648
tarinfo.size = len(content)
47-
tarinfo.mtime = time.time()
49+
tarinfo.mtime = int(time.time())
4850

4951
tmp_tarfile.addfile(tarinfo, BytesIO(content))
5052
tar_archive_object.seek(0)
@@ -54,12 +56,13 @@ def _copy_credentials(self) -> None:
5456
def _readiness_probe(self) -> None:
5557
url: str = f"http://{self.get_registry()}/v2"
5658
if self.username and self.password:
57-
response: Response = get(url, auth=HTTPBasicAuth(self.username, self.password), timeout=1)
59+
auth_response: Response = get(url, auth=HTTPBasicAuth(self.username, self.password), timeout=1)
60+
auth_response.raise_for_status()
5861
else:
5962
response: Response = get(url, timeout=1)
60-
response.raise_for_status()
63+
response.raise_for_status()
6164

62-
def start(self):
65+
def start(self) -> "DockerRegistryContainer":
6366
if self.username and self.password:
6467
self.with_env("REGISTRY_AUTH_HTPASSWD_REALM", "local-registry")
6568
self.with_env("REGISTRY_AUTH_HTPASSWD_PATH", self.credentials_path)

modules/registry/tests/test_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
REGISTRY_PASSWORD: str = "bar"
88

99

10-
def test_registry():
10+
def test_registry() -> None:
1111
with DockerRegistryContainer().with_bind_ports(5000, 5000) as registry_container:
1212
url: str = f"http://{registry_container.get_registry()}/v2/_catalog"
1313

@@ -16,7 +16,7 @@ def test_registry():
1616
assert response.status_code == 200
1717

1818

19-
def test_registry_with_authentication():
19+
def test_registry_with_authentication() -> None:
2020
with DockerRegistryContainer(username=REGISTRY_USERNAME, password=REGISTRY_PASSWORD).with_bind_ports(
2121
5000, 5000
2222
) as registry_container:

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ module = ['wrapt.*']
345345
# wrapt doesn't have type annotations
346346
ignore_missing_imports = true
347347

348+
[[tool.mypy.overrides]]
349+
module = ['requests.*']
350+
# requests doesn't have type annotations
351+
ignore_missing_imports = true
352+
348353
[build-system]
349354
requires = ["poetry-core"]
350355
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)