From d85ed395b71dab022bcdf8757776646302e0ecd2 Mon Sep 17 00:00:00 2001 From: saxix Date: Fri, 5 Jul 2024 18:25:53 +0200 Subject: [PATCH] updates --- .flake8 | 3 +- .github/codeql/codeql-config.yml | 2 +- .pdm-python | 2 +- docker/bin/wait-for-it.sh | 2 +- docker/conf/mime.types | 2 +- manage.py | 4 +- pdm.lock | 90 ++++++++++++++++++- pyproject.toml | 1 + src/hope_country_workspace/config/__init__.py | 13 ++- .../config/fragments/celery.py | 1 - .../config/fragments/csp.py | 3 +- src/hope_country_workspace/config/settings.py | 1 - src/hope_country_workspace/tenant/config.py | 2 +- src/hope_country_workspace/tenant/db.py | 3 +- src/hope_country_workspace/tenant/utils.py | 6 -- tests/tenant/test_tenant_backend.py | 4 +- 16 files changed, 116 insertions(+), 23 deletions(-) diff --git a/.flake8 b/.flake8 index 784c638..15c6267 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,6 @@ [flake8] max-complexity = 12 -max-line-length = 120 +max-line-length = 88 exclude = .*/ __pycache__ @@ -12,3 +12,4 @@ exclude = per-file-ignores = src/**/migrations/*.py:E501 src/**/upgrade.py:E731 + src/**/upgrade.py:E731 diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml index 979cf37..955fcce 100644 --- a/.github/codeql/codeql-config.yml +++ b/.github/codeql/codeql-config.yml @@ -1,4 +1,4 @@ name: 'App CodeQL Config' paths-ignore: - - '**/tests/**' \ No newline at end of file + - '**/tests/**' diff --git a/.pdm-python b/.pdm-python index a9ff23a..4d4f30c 100644 --- a/.pdm-python +++ b/.pdm-python @@ -1 +1 @@ -/Users/sax/Documents/data/PROGETTI/UNICEF/hope-country-workspace/.venv/bin/python \ No newline at end of file +/Users/sax/Documents/data/PROGETTI/UNICEF/hope-country-workspace/.venv/bin/python diff --git a/docker/bin/wait-for-it.sh b/docker/bin/wait-for-it.sh index 5d868ec..4d473c4 100644 --- a/docker/bin/wait-for-it.sh +++ b/docker/bin/wait-for-it.sh @@ -179,4 +179,4 @@ if [[ $WAITFORIT_CLI != "" ]]; then exec "${WAITFORIT_CLI[@]}" else exit $WAITFORIT_RESULT -fi \ No newline at end of file +fi diff --git a/docker/conf/mime.types b/docker/conf/mime.types index 8c6daa1..ec6469d 100644 --- a/docker/conf/mime.types +++ b/docker/conf/mime.types @@ -2184,4 +2184,4 @@ video/x-sgi-movie movie x-conference/x-cooltalk ice x-epoc/x-sisx-app sisx -x-world/x-vrml vrm vrml wrl \ No newline at end of file +x-world/x-vrml vrm vrml wrl diff --git a/manage.py b/manage.py index 4b0471f..84aeee7 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,9 @@ sys.path.insert(0, SRC) if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hope_country_workspace.config.settings") + os.environ.setdefault( + "DJANGO_SETTINGS_MODULE", "hope_country_workspace.config.settings" + ) from django.core.management import execute_from_command_line diff --git a/pdm.lock b/pdm.lock index a3f16e9..f4a60d6 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:8744d30ad35acc7ffb7119daa600cc8b2557e66f380d27f20ecc3104ba587ae6" +content_hash = "sha256:bff7331d24703aa007cb86ab745ffa3e16edf0d199c28ea41d9f12278aa422e7" [[package]] name = "amqp" @@ -147,6 +147,17 @@ files = [ {file = "cffi-1.16.0.tar.gz", hash = "sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0"}, ] +[[package]] +name = "cfgv" +version = "3.4.0" +requires_python = ">=3.8" +summary = "Validate configuration and produce human readable error messages." +groups = ["dev"] +files = [ + {file = "cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9"}, + {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, +] + [[package]] name = "charset-normalizer" version = "3.3.2" @@ -378,6 +389,16 @@ files = [ {file = "defusedxml-0.8.0rc2.tar.gz", hash = "sha256:138c7d540a78775182206c7c97fe65b246a2f40b29471e1a2f1b0da76e7a3942"}, ] +[[package]] +name = "distlib" +version = "0.3.8" +summary = "Distribution utilities" +groups = ["dev"] +files = [ + {file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"}, + {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, +] + [[package]] name = "django" version = "5.0.6" @@ -736,6 +757,17 @@ files = [ {file = "fancycompleter-0.9.1.tar.gz", hash = "sha256:09e0feb8ae242abdfd7ef2ba55069a46f011814a80fe5476be48f51b00247272"}, ] +[[package]] +name = "filelock" +version = "3.15.4" +requires_python = ">=3.8" +summary = "A platform independent file lock." +groups = ["dev"] +files = [ + {file = "filelock-3.15.4-py3-none-any.whl", hash = "sha256:6ca1fffae96225dab4c6eaf1c4f4f28cd2568d3ec2a44e15a08520504de468e7"}, + {file = "filelock-3.15.4.tar.gz", hash = "sha256:2207938cbc1844345cb01a5a95524dae30f0ce089eba5b00378295a17e3e90cb"}, +] + [[package]] name = "flake8" version = "7.1.0" @@ -766,6 +798,17 @@ files = [ {file = "freezegun-1.5.1.tar.gz", hash = "sha256:b29dedfcda6d5e8e083ce71b2b542753ad48cfec44037b3fc79702e2980a89e9"}, ] +[[package]] +name = "identify" +version = "2.5.36" +requires_python = ">=3.8" +summary = "File identification library for Python" +groups = ["dev"] +files = [ + {file = "identify-2.5.36-py2.py3-none-any.whl", hash = "sha256:37d93f380f4de590500d9dba7db359d0d3da95ffe7f9de1753faa159e71e7dfa"}, + {file = "identify-2.5.36.tar.gz", hash = "sha256:e5e00f54165f9047fbebeb4a560f9acfb8af4c88232be60a488e9b68d122745d"}, +] + [[package]] name = "idna" version = "3.7" @@ -847,6 +890,17 @@ files = [ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] +[[package]] +name = "nodeenv" +version = "1.9.1" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +summary = "Node.js virtual environment builder" +groups = ["dev"] +files = [ + {file = "nodeenv-1.9.1-py2.py3-none-any.whl", hash = "sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9"}, + {file = "nodeenv-1.9.1.tar.gz", hash = "sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f"}, +] + [[package]] name = "oauthlib" version = "3.2.2" @@ -917,6 +971,24 @@ files = [ {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, ] +[[package]] +name = "pre-commit" +version = "3.7.1" +requires_python = ">=3.9" +summary = "A framework for managing and maintaining multi-language pre-commit hooks." +groups = ["dev"] +dependencies = [ + "cfgv>=2.0.0", + "identify>=1.0.0", + "nodeenv>=0.11.1", + "pyyaml>=5.1", + "virtualenv>=20.10.0", +] +files = [ + {file = "pre_commit-3.7.1-py2.py3-none-any.whl", hash = "sha256:fae36fd1d7ad7d6a5a1c0b0d5adb2ed1a3bda5a21bf6c3e5372073d7a11cd4c5"}, + {file = "pre_commit-3.7.1.tar.gz", hash = "sha256:8ca3ad567bc78a4972a3f1a477e94a79d4597e8140a6e0b651c5e33899c3654a"}, +] + [[package]] name = "prompt-toolkit" version = "3.0.47" @@ -1516,6 +1588,22 @@ files = [ {file = "vine-5.1.0.tar.gz", hash = "sha256:8b62e981d35c41049211cf62a0a1242d8c1ee9bd15bb196ce38aefd6799e61e0"}, ] +[[package]] +name = "virtualenv" +version = "20.26.3" +requires_python = ">=3.7" +summary = "Virtual Python Environment builder" +groups = ["dev"] +dependencies = [ + "distlib<1,>=0.3.7", + "filelock<4,>=3.12.2", + "platformdirs<5,>=3.9.1", +] +files = [ + {file = "virtualenv-20.26.3-py3-none-any.whl", hash = "sha256:8cc4a31139e796e9a7de2cd5cf2489de1217193116a8fd42328f1bd65f434589"}, + {file = "virtualenv-20.26.3.tar.gz", hash = "sha256:4c43a2a236279d9ea36a0d76f98d84bd6ca94ac4e0f4a3b9d46d05e10fea542a"}, +] + [[package]] name = "waitress" version = "3.0.0" diff --git a/pyproject.toml b/pyproject.toml index 1f4ecab..08097c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ dev = [ "responses>=0.25.3", "pytest-factoryboy>=2.7.0", "django-webtest>=1.9.11", + "pre-commit>=3.7.1", ] [tool.black] diff --git a/src/hope_country_workspace/config/__init__.py b/src/hope_country_workspace/config/__init__.py index a99bde3..59d648d 100644 --- a/src/hope_country_workspace/config/__init__.py +++ b/src/hope_country_workspace/config/__init__.py @@ -17,6 +17,13 @@ def setting(anchor: str) -> str: return f"@see {DJANGO_HELP_BASE}#{anchor}" +def celery_doc(anchor: str) -> str: + return ( + f"@see https://docs.celeryq.dev/en/stable/" + f"userguide/configuration.html#{anchor}" + ) + + class Group(Enum): DJANGO = 1 @@ -46,18 +53,18 @@ class Group(Enum): "CELERY_TASK_ALWAYS_EAGER": ( bool, False, - "https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_always_eager", + f"{celery_doc}#std-setting-task_always_eager", True, ), "CELERY_TASK_EAGER_PROPAGATES": ( bool, True, - "https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-eager-propagates", + f"{celery_doc}#task-eager-propagates", ), "CELERY_VISIBILITY_TIMEOUT": ( int, 1800, - "https://docs.celeryq.dev/en/stable/userguide/configuration.html#broker-transport-options", + f"{celery_doc}#broker-transport-options", ), "CSRF_COOKIE_SECURE": (bool, True, setting("csrf-cookie-secure")), "DATABASE_URL": ( diff --git a/src/hope_country_workspace/config/fragments/celery.py b/src/hope_country_workspace/config/fragments/celery.py index ee15ce5..2d192f3 100644 --- a/src/hope_country_workspace/config/fragments/celery.py +++ b/src/hope_country_workspace/config/fragments/celery.py @@ -1,7 +1,6 @@ from ..settings import env # type: ignore[attr-defined] CELERY_ACCEPT_CONTENT = ["pickle", "json", "application/text", "application/json"] -# CELERY_BROKER_TRANSPORT_OPTIONS = {"visibility_timeout": int(CELERY_BROKER_VISIBILITY_VAR)} CELERY_BROKER_URL = env("CELERY_BROKER_URL") CELERY_BROKER_VISIBILITY_VAR = env("CELERY_VISIBILITY_TIMEOUT") diff --git a/src/hope_country_workspace/config/fragments/csp.py b/src/hope_country_workspace/config/fragments/csp.py index a0e02fb..773433f 100644 --- a/src/hope_country_workspace/config/fragments/csp.py +++ b/src/hope_country_workspace/config/fragments/csp.py @@ -1,4 +1,5 @@ -# CSP_DEFAULT_SRC = ["'self'", "'unsafe-inline'", "'same-origin'", "fonts.googleapis.com", 'fonts.gstatic.com', 'data:', +# CSP_DEFAULT_SRC = ["'self'", "'unsafe-inline'", "'same-origin'", +# "fonts.googleapis.com", 'fonts.gstatic.com', 'data:', # 'blob:', "cdn.redoc.ly"] CSP_DEFAULT_SRC = ["'self'", "'unsafe-inline'"] CSP_STYLE_SRC = [ diff --git a/src/hope_country_workspace/config/settings.py b/src/hope_country_workspace/config/settings.py index 089e6f1..822cbcf 100644 --- a/src/hope_country_workspace/config/settings.py +++ b/src/hope_country_workspace/config/settings.py @@ -190,7 +190,6 @@ DEFAULT_FROM_EMAIL = "hope@unicef.org" -# EMAIL_BACKEND = "djcelery_email.backends.CeleryEmailBackend" # TODO: when ready, add djcelery_email EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" EMAIL_HOST = env("EMAIL_HOST", default="") EMAIL_HOST_USER = env("EMAIL_HOST_USER", default="") diff --git a/src/hope_country_workspace/tenant/config.py b/src/hope_country_workspace/tenant/config.py index a3fa191..2d73be7 100644 --- a/src/hope_country_workspace/tenant/config.py +++ b/src/hope_country_workspace/tenant/config.py @@ -39,7 +39,7 @@ def __init__(self, prefix: str): setting_changed.connect(self._on_setting_changed) def _set_attr(self, prefixed_name: str, value: "Any") -> None: - name = prefixed_name[(len(self.prefix) + 1) :] + name = prefixed_name[(len(self.prefix) + 1) :] # noqa setattr(self, name, value) @cached_property diff --git a/src/hope_country_workspace/tenant/db.py b/src/hope_country_workspace/tenant/db.py index 5274bde..d62a6c5 100644 --- a/src/hope_country_workspace/tenant/db.py +++ b/src/hope_country_workspace/tenant/db.py @@ -18,7 +18,8 @@ def get_tenant_filter(self) -> "Dict[str, Any]": tenant_filter_field = self.model.Tenant.tenant_filter_field if not tenant_filter_field: raise ValueError( - f"Set 'tenant_filter_field' on {self} or override `get_queryset()` to enable queryset filtering" + f"Set 'tenant_filter_field' on {self} or override " + f"`get_queryset()` to enable queryset filtering" ) if tenant_filter_field == "__all__": return {} diff --git a/src/hope_country_workspace/tenant/utils.py b/src/hope_country_workspace/tenant/utils.py index 60d0021..aa49137 100644 --- a/src/hope_country_workspace/tenant/utils.py +++ b/src/hope_country_workspace/tenant/utils.py @@ -83,9 +83,3 @@ def process_response( if response: state.set_cookies(response) state.reset() - - # @contextlib.contextmanager - # def context(self, request: "AuthHttpRequest", response: "HttpResponse|None" = None) -> "Iterator[None]": - # self.process_request(request) - # yield - # self.process_response(request, response) diff --git a/tests/tenant/test_tenant_backend.py b/tests/tenant/test_tenant_backend.py index 635b49f..ecaf793 100644 --- a/tests/tenant/test_tenant_backend.py +++ b/tests/tenant/test_tenant_backend.py @@ -5,6 +5,8 @@ from django.contrib.auth.models import AnonymousUser import pytest +from pytest_factoryboy import register +from testutils.factories import UserFactory from testutils.perms import user_grant_permissions from hope_country_workspace.state import state @@ -15,8 +17,6 @@ _DATA = namedtuple("_DATA", "afg,ukr") -from pytest_factoryboy import register -from testutils.factories import UserFactory register(UserFactory)