From 61c07c7a056a7bf50d0c522dda0a46700c02c899 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:33:40 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E2=AC=86=EF=B8=8F(dependencies)=20update?= =?UTF-8?q?=20python=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0d601e894..4f44b1a43 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,8 +33,8 @@ install_requires = djangorestframework django-parler>=2.0.1 django-redis>=4.11.0 - djangorestframework-simplejwt==5.2.0 - PyJWT==2.1.0 + djangorestframework-simplejwt==5.2.2 + PyJWT==2.6.0 python-dateutil==2.8.2 package_dir = =src @@ -44,35 +44,35 @@ zip_safe = True [options.extras_require] dev = bandit==1.7.4 - black==22.3.0 + black==22.10.0 cssselect==1.1.0 defer==1.0.4 factory-boy==3.2.1 - flake8==4.0.1 + flake8==5.0.4 htmlmin==0.1.12 ipdb==0.13.9 - ipython==8.3.0 + ipython==8.5.0 isort==5.10.1 - lxml==4.8.0 - mysqlclient==2.1.0 - msgpack==1.0.3 - pylint==2.13.7 + lxml==4.9.1 + mysqlclient==2.1.1 + msgpack==1.0.4 + pylint==2.15.5 pylint-django==2.5.3 - pytest==7.1.2 - pytest-cov==3.0.0 + pytest==7.1.3 + pytest-cov==4.0.0 pytest-django==4.5.2 - responses==0.20.0 + responses==0.22.0 drf-yasg==1.21.4 ci = - twine==4.0.0 + twine==4.0.1 sandbox = - django-configurations==2.3.2 + django-configurations==2.4 django-cors-headers==3.13.0 - dockerflow==2022.1.0 + dockerflow==2022.8.0 factory-boy==3.2.1 gunicorn==20.1.0 - psycopg2-binary==2.9.3 - sentry-sdk==1.5.10 + psycopg2-binary==2.9.4 + sentry-sdk==1.10.1 [options.packages.find] where = src From d8c406df390368710e4c4fa1a29c5a129f1f40fd Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Wed, 7 Dec 2022 23:25:35 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9E=95(backend)=20install=20time-machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Time machine is library to travel through time easily within our tests. --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 4f44b1a43..d2705ee6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,6 +62,7 @@ dev = pytest-cov==4.0.0 pytest-django==4.5.2 responses==0.22.0 + time-machine==2.8.2 drf-yasg==1.21.4 ci = twine==4.0.1 From f4f0f41c34bcd8a0ebbc36ca4b93c738257beb4e Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Mon, 24 Oct 2022 19:00:03 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85(backend)=20update=20jwt=20tokens?= =?UTF-8?q?=20within=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With upgrade of PyJWT 2.6.0 jwt token header has changed, so we have to update our tests comparing jwt tokens. --- .../core/test_core_utils_generate_token.py | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/tests/apps/core/test_core_utils_generate_token.py b/tests/apps/core/test_core_utils_generate_token.py index 1fff1e325..c871debc5 100644 --- a/tests/apps/core/test_core_utils_generate_token.py +++ b/tests/apps/core/test_core_utils_generate_token.py @@ -3,15 +3,14 @@ """ import datetime import random -from unittest import mock from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.test import TestCase from django.test.utils import override_settings -from django.utils import timezone import jwt +import time_machine from magnify.apps.core.factories import UserFactory from magnify.apps.core.utils import generate_token @@ -31,29 +30,27 @@ class TokenUtilsTestCase(TestCase): """Test suite for utils related to the JWT token.""" + @time_machine.travel(datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc)) def test_utils_generate_token_anonymous(self): """Generate a JWT token for a guest.""" - now = datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc) # Test token with a fix admin status - with mock.patch.object(timezone, "now", return_value=now): - token = generate_token(AnonymousUser(), "my-room", is_admin=True) + token = generate_token(AnonymousUser(), "my-room", is_admin=True) self.assertEqual( token, ( - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6MTkwNzcxMjA" - "wMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9pZCIsInN1YiI6Im1lZXQ" - "uaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsidXNlciI6eyJhdmF0YXIiOiJhdmF0YXI" - "uanBnIiwibmFtZSI6Imd1ZXN0IiwiZW1haWwiOiIifX19.yzGbUJywsVqL0WAbzslIoUovLuAKeLBqXs" - "N3h0sPaMo" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6M" + "TkwNzcxMjAwMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9" + "pZCIsInN1YiI6Im1lZXQuaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsid" + "XNlciI6eyJhdmF0YXIiOiJhdmF0YXIuanBnIiwibmFtZSI6Imd1ZXN0IiwiZW1haWwiOiI" + "ifX19.mCcDVhhWyWfOEGTpiNdemQlPURTCFGh-AWOrLFY2Tds" ), ) # Test payload with a random admin status is_admin = random.choice([True, False]) # nosec - with mock.patch.object(timezone, "now", return_value=now): - token = generate_token(AnonymousUser(), "my-room", is_admin=is_admin) + token = generate_token(AnonymousUser(), "my-room", is_admin=is_admin) payload = jwt.decode( token, @@ -77,30 +74,28 @@ def test_utils_generate_token_anonymous(self): }, ) + @time_machine.travel(datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc)) def test_utils_generate_token_authenticated(self): """Generate a token for a quidam user.""" user = UserFactory(username="mickael", email="mickael@example.com") - now = datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc) # Test token with a fix admin status - with mock.patch.object(timezone, "now", return_value=now): - token = generate_token(user, "my-room", is_admin=True) + token = generate_token(user, "my-room", is_admin=True) self.assertEqual( token, ( - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6MTkwNzcxMjA" - "wMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9pZCIsInN1YiI6Im1lZXQ" - "uaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsidXNlciI6eyJhdmF0YXIiOiJhdmF0YXI" - "uanBnIiwibmFtZSI6Im1pY2thZWwiLCJlbWFpbCI6Im1pY2thZWxAZXhhbXBsZS5jb20ifX19.sU6tEi" - "0SKOAheTcS4BCXMhYz1ntiTvKi1uAAiuPNP3k" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6M" + "TkwNzcxMjAwMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9" + "pZCIsInN1YiI6Im1lZXQuaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsid" + "XNlciI6eyJhdmF0YXIiOiJhdmF0YXIuanBnIiwibmFtZSI6Im1pY2thZWwiLCJlbWFpbCI" + "6Im1pY2thZWxAZXhhbXBsZS5jb20ifX19.0pKgUY7362CaQZYXYgAysot431giCertbe4B" + "IOlJ3_8" ), ) - # Test payload with a random admin status is_admin = random.choice([True, False]) # nosec - with mock.patch.object(timezone, "now", return_value=now): - token = generate_token(user, "my-room", is_admin=is_admin) + token = generate_token(user, "my-room", is_admin=is_admin) payload = jwt.decode( token, @@ -128,25 +123,24 @@ def test_utils_generate_token_authenticated(self): }, ) + @time_machine.travel(datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc)) def test_utils_generate_token_staff(self): """Generate a token for a staff user.""" user = UserFactory( username="mickael", email="mickael@example.com", is_staff=True ) - now = datetime.datetime(2030, 6, 15, tzinfo=datetime.timezone.utc) is_admin = random.choice([True, False]) # nosec - - with mock.patch.object(timezone, "now", return_value=now): - token = generate_token(user, "my-room", is_admin=is_admin) + token = generate_token(user, "my-room", is_admin=is_admin) self.assertEqual( token, ( - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6MTkwNzcxMjA" - "wMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9pZCIsInN1YiI6Im1lZXQ" - "uaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsidXNlciI6eyJhdmF0YXIiOiJhdmF0YXI" - "uanBnIiwibmFtZSI6Im1pY2thZWwiLCJlbWFpbCI6Im1pY2thZWxAZXhhbXBsZS5jb20ifX19.sU6tEi" - "0SKOAheTcS4BCXMhYz1ntiTvKi1uAAiuPNP3k" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDc3MTI2MDAsImlhdCI6M" + "TkwNzcxMjAwMCwibW9kZXJhdG9yIjp0cnVlLCJhdWQiOiJqaXRzaSIsImlzcyI6ImFwcF9" + "pZCIsInN1YiI6Im1lZXQuaml0c2kiLCJyb29tIjoibXktcm9vbSIsImNvbnRleHQiOnsid" + "XNlciI6eyJhdmF0YXIiOiJhdmF0YXIuanBnIiwibmFtZSI6Im1pY2thZWwiLCJlbWFpbCI" + "6Im1pY2thZWxAZXhhbXBsZS5jb20ifX19.0pKgUY7362CaQZYXYgAysot431giCertbe4B" + "IOlJ3_8" ), ) From c5fe07f8a6f4183c3618bedeea212c738cc86141 Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Mon, 24 Oct 2022 19:24:07 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=9A=A8(backend)=20upgrade=20pylint=20?= =?UTF-8?q?configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some pylint options have been deleted, we have to upgrade .pylintrc accordingly. --- .pylintrc | 83 +------------------------------------------------------ 1 file changed, 1 insertion(+), 82 deletions(-) diff --git a/.pylintrc b/.pylintrc index 3b78465c8..9779df194 100644 --- a/.pylintrc +++ b/.pylintrc @@ -54,81 +54,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=apply-builtin, - backtick, - bad-continuation - bad-inline-option, - bad-python3-import, - basestring-builtin, - buffer-builtin, - cmp-builtin, - cmp-method, - coerce-builtin, - coerce-method, - delslice-method, - deprecated-itertools-function, - deprecated-pragma, - deprecated-str-translate-call, - deprecated-string-function, - deprecated-types-field, - dict-items-not-iterating, - dict-iter-method, - dict-keys-not-iterating, - dict-values-not-iterating, - dict-view-method, - div-method, - django-not-configured, - eq-without-hash, - exception-message-attribute, - execfile-builtin, - file-builtin, - file-ignored, - filter-builtin-not-iterating, - getslice-method, - hex-method, - idiv-method, - import-star-module-level, - indexing-exception, - input-builtin, - intern-builtin, - invalid-str-codec, - locally-disabled, - locally-enabled, - long-builtin, - long-suffix, - map-builtin-not-iterating, - metaclass-assignment, - next-method-called, - next-method-defined, - no-absolute-import, - non-ascii-bytes-literal, - nonzero-method, - oct-method, - old-division, - old-ne-operator, - old-octal-literal, - old-raise-syntax, - parameter-unpacking, - print-statement, - raising-string, - range-builtin-not-iterating, - raw_input-builtin, - raw-checker-failed, - rdiv-method, - reduce-builtin, - reload-builtin, - round-builtin, - setslice-method, - standarderror-builtin, - suppressed-message, - sys-max-int, - unichr-builtin, - unicode-builtin, - unpacking-in-except, - useless-suppression, - using-cmp-argument, - xrange-builtin, - zip-builtin-not-iterating, +disable=django-not-configured # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -309,13 +235,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no