diff --git a/poetry.lock b/poetry.lock index f5ed52e..94d41d9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -359,6 +359,22 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "faker" +version = "15.3.4" +description = "Faker is a Python package that generates fake data for you." +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "Faker-15.3.4-py3-none-any.whl", hash = "sha256:c2a2ff9dd8dfd991109b517ab98d5cb465e857acb45f6b643a0e284a9eb2cc76"}, + {file = "Faker-15.3.4.tar.gz", hash = "sha256:2d5443724f640ce07658ca8ca8bbd40d26b58914e63eec6549727869aa67e2cc"}, +] + +[package.dependencies] +python-dateutil = ">=2.4" +typing-extensions = {version = ">=3.10.0.1", markers = "python_version < \"3.8\""} + [[package]] name = "flake8" version = "3.9.2" @@ -962,6 +978,23 @@ typing-extensions = ">=4.2.0" dotenv = ["python-dotenv (>=0.10.4)"] email = ["email-validator (>=1.0.3)"] +[[package]] +name = "pydantic-factories" +version = "1.15.0" +description = "Mock data generation for pydantic based models and python dataclasses" +category = "dev" +optional = false +python-versions = ">=3.7,<4.0" +files = [ + {file = "pydantic_factories-1.15.0-py3-none-any.whl", hash = "sha256:04e1f125cb28cbe745f2fece4bd2b419786395dc7efabac74fe037dc5397490a"}, + {file = "pydantic_factories-1.15.0.tar.gz", hash = "sha256:5c0636a2c5f357390d0a528e70754b139b431dd675109c481c06c494b3b26432"}, +] + +[package.dependencies] +faker = "*" +pydantic = ">=1.10.0" +typing-extensions = "*" + [[package]] name = "pyflakes" version = "2.3.1" @@ -1531,16 +1564,19 @@ files = [ [[package]] name = "types-beautifulsoup4" -version = "4.11.6.1" +version = "4.11.6.2" description = "Typing stubs for beautifulsoup4" category = "dev" optional = false python-versions = "*" files = [ - {file = "types-beautifulsoup4-4.11.6.1.tar.gz", hash = "sha256:d46be8f409ddccb6daaa9d118484185e70bcf552085c39c6d05b157cd1462e04"}, - {file = "types_beautifulsoup4-4.11.6.1-py3-none-any.whl", hash = "sha256:c1f803367a2b07ad4fdac40ddbea557010dc4ddd1ee92d801f317eb02e2e3c72"}, + {file = "types-beautifulsoup4-4.11.6.2.tar.gz", hash = "sha256:dbeb2f82f2d79878107238ab50291361563ae5db99e198a68e91dbb4c0f37b3f"}, + {file = "types_beautifulsoup4-4.11.6.2-py3-none-any.whl", hash = "sha256:4994a3b5ce66467977d9ce65031f5e212f23af66941669a59f50a1801260d9db"}, ] +[package.dependencies] +types-html5lib = "*" + [[package]] name = "types-dateparser" version = "1.1.4.4" @@ -1553,6 +1589,18 @@ files = [ {file = "types_dateparser-1.1.4.4-py3-none-any.whl", hash = "sha256:5b0c8845167981f68f090894aa371bddbd0371341b90c3f868ac9524cd0a6b69"}, ] +[[package]] +name = "types-html5lib" +version = "1.1.11.10" +description = "Typing stubs for html5lib" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "types-html5lib-1.1.11.10.tar.gz", hash = "sha256:90eeffad04010bf67bcccf77b9cc6cf4783eec13cbd22ebbaaf20f24d5f2ca11"}, + {file = "types_html5lib-1.1.11.10-py3-none-any.whl", hash = "sha256:18c34ce51eac062321b224365b3aee5b5cdc1613872ed8469c9c0c4ccd3e02e9"}, +] + [[package]] name = "types-humanfriendly" version = "10.0.1.3" @@ -1567,14 +1615,14 @@ files = [ [[package]] name = "types-redis" -version = "4.3.21.7" +version = "4.4.0.0" description = "Typing stubs for redis" category = "dev" optional = false python-versions = "*" files = [ - {file = "types-redis-4.3.21.7.tar.gz", hash = "sha256:f9baac41fcafb0b8ec655893feebc5d8bd189da05062d03b4566a16c092fc08c"}, - {file = "types_redis-4.3.21.7-py3-none-any.whl", hash = "sha256:834e816a84fc570aa96551a9252b0df164ac671bc09e4708e2f8e2b129449ef1"}, + {file = "types-redis-4.4.0.0.tar.gz", hash = "sha256:7d826d458e9a6dbd7d4f21fdf6d7c39ba2e2f3474c8a348000241965860a0edf"}, + {file = "types_redis-4.4.0.0-py3-none-any.whl", hash = "sha256:cc3832caab14f86af2c62ac3c865694df925df525b8083509035842ecb6b5950"}, ] [[package]] @@ -1721,4 +1769,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "ea1fd278a3dc000ed3d374c9006b959014cf8f67c62c99bc4b15aeeca2e64311" +content-hash = "73237cfcb4d545f3e1e170c084fae328a7a253135bb99bdb8d5750dc627936c3" diff --git a/pynyaata/cache/simple.py b/pynyaata/cache/simple.py index 9987f38..3c2eded 100644 --- a/pynyaata/cache/simple.py +++ b/pynyaata/cache/simple.py @@ -14,7 +14,7 @@ class SimpleCache(Cache): if key in CACHE_DATA: data, timeout = CACHE_DATA[key] - if datetime.now() > timeout + timedelta(seconds=CACHE_TIMEOUT): + if datetime.now() < timeout + timedelta(seconds=CACHE_TIMEOUT): return data else: CACHE_DATA.pop(key) diff --git a/pynyaata/types.py b/pynyaata/types.py index cdf7724..52ae5ad 100644 --- a/pynyaata/types.py +++ b/pynyaata/types.py @@ -30,7 +30,7 @@ class RemoteFile(BaseModel): name: str link: HttpUrl comment: int = 0 - comment_url: HttpUrl + comment_url: Optional[HttpUrl] magnet: Optional[str] torrent: Optional[HttpUrl] size: Optional[ByteSize] diff --git a/pyproject.toml b/pyproject.toml index a88e080..ff07df6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,13 +35,15 @@ black = "22.12.0" flake8-alphabetize = "0.0.19" flake8-black = "0.3.6" mypy = "0.991" -types-beautifulsoup4 = "4.11.6.1" +pytest = "7.2.0" +types-beautifulsoup4 = "4.11.6.2" types-dateparser = "1.1.4.4" types-humanfriendly = "10.0.1.3" -types-redis = "4.3.21.7" +types-redis = "4.4.0.0" types-requests = "2.28.11.7" djlint = "1.9.3" flake8 = "3.9.2" +pydantic-factories = "1.15.0" [build-system] @@ -52,3 +54,7 @@ build-backend = "poetry.core.masonry.api" [tool.djlint] extension = "j2" profile = "jinja" + + +[tool.mypy] +plugins = ["pydantic.mypy"] diff --git a/tests/cache_test.py b/tests/cache_test.py new file mode 100644 index 0000000..4858262 --- /dev/null +++ b/tests/cache_test.py @@ -0,0 +1,14 @@ +from pydantic_factories import ModelFactory + +from pynyaata.cache import client +from pynyaata.types import RemoteFile + + +class RemoteFileFactory(ModelFactory): + __model__ = RemoteFile + + +def test_cache_data(): + remote = RemoteFileFactory.build() + client.set("test", remote) + assert client.get("test") == remote