Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️(dependencies) update python dependencies #104

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 1 addition & 82 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
jbpenrath marked this conversation as resolved.
Show resolved Hide resolved

# 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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 18 additions & 17 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,35 +44,36 @@ 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
time-machine==2.8.2
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
Expand Down
58 changes: 26 additions & 32 deletions tests/apps/core/test_core_utils_generate_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"
),
)

Expand Down