🚨(pylint) make pylint work and fix issues found
Pylint was not installed and wrongly configured. After making it work, we fix all the issues found so it can be added to our CI requirements.
This commit is contained in:
committed by
Samuel Paccoud
parent
eeec372957
commit
8ebfb8715d
@@ -2,7 +2,9 @@
|
||||
Test suite for generated openapi schema.
|
||||
"""
|
||||
import json
|
||||
from io import StringIO
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.test import Client
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
"""
|
||||
Test contacts API endpoints in People's core app.
|
||||
"""
|
||||
import random
|
||||
from unittest import mock
|
||||
|
||||
from django.test.utils import override_settings
|
||||
|
||||
import pytest
|
||||
from rest_framework.test import APIClient
|
||||
from rest_framework_simplejwt.tokens import AccessToken
|
||||
|
||||
from core import factories, models
|
||||
from core.api import serializers
|
||||
@@ -120,7 +116,7 @@ def test_api_contacts_list_authenticated_by_full_name():
|
||||
dave = factories.BaseContactFactory(full_name="David Bowman")
|
||||
nicole = factories.BaseContactFactory(full_name="Nicole Foole")
|
||||
frank = factories.BaseContactFactory(full_name="Frank Poole")
|
||||
heywood = factories.BaseContactFactory(full_name="Heywood Floyd")
|
||||
factories.BaseContactFactory(full_name="Heywood Floyd")
|
||||
|
||||
# Full query should work
|
||||
response = APIClient().get(
|
||||
@@ -433,7 +429,7 @@ def test_api_contacts_create_authenticated_existing_override():
|
||||
jwt_token = OIDCToken.for_user(user)
|
||||
|
||||
base_contact = factories.BaseContactFactory()
|
||||
contact = factories.ContactFactory(base=base_contact, owner=user)
|
||||
factories.ContactFactory(base=base_contact, owner=user)
|
||||
|
||||
response = APIClient().post(
|
||||
"/api/v1.0/contacts/",
|
||||
|
||||
@@ -6,7 +6,6 @@ from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from rest_framework.test import APIClient
|
||||
from rest_framework_simplejwt.tokens import AccessToken
|
||||
|
||||
from core import factories, models
|
||||
from core.api import serializers
|
||||
@@ -38,7 +37,7 @@ def test_api_team_accesses_list_authenticated_unrelated():
|
||||
jwt_token = OIDCToken.for_user(user)
|
||||
|
||||
team = factories.TeamFactory()
|
||||
accesses = factories.TeamAccessFactory.create_batch(3, team=team)
|
||||
factories.TeamAccessFactory.create_batch(3, team=team)
|
||||
|
||||
# Accesses for other teams to which the user is related should not be listed either
|
||||
other_access = factories.TeamAccessFactory(user=user)
|
||||
@@ -82,8 +81,7 @@ def test_api_team_accesses_list_authenticated_related():
|
||||
assert response.status_code == 200
|
||||
content = response.json()
|
||||
assert len(content["results"]) == 3
|
||||
id_sorter = lambda x: x["id"]
|
||||
assert sorted(content["results"], key=id_sorter) == sorted(
|
||||
assert sorted(content["results"], key=lambda x: x["id"]) == sorted(
|
||||
[
|
||||
{
|
||||
"id": str(user_access.id),
|
||||
@@ -104,7 +102,7 @@ def test_api_team_accesses_list_authenticated_related():
|
||||
"abilities": access2.get_abilities(user),
|
||||
},
|
||||
],
|
||||
key=id_sorter,
|
||||
key=lambda x: x["id"],
|
||||
)
|
||||
|
||||
|
||||
@@ -576,7 +574,7 @@ def test_api_team_accesses_update_owner_except_owner():
|
||||
jwt_token = OIDCToken.for_user(user)
|
||||
|
||||
team = factories.TeamFactory(users=[(user, "owner")])
|
||||
other_user = factories.UserFactory()
|
||||
factories.UserFactory()
|
||||
access = factories.TeamAccessFactory(
|
||||
team=team,
|
||||
role=random.choice(["administrator", "member"]),
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
"""
|
||||
Test users API endpoints in the People core app.
|
||||
"""
|
||||
import random
|
||||
from unittest import mock
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from django.test.utils import override_settings
|
||||
|
||||
import pytest
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
@@ -151,6 +145,8 @@ def test_api_users_create_authenticated():
|
||||
"language": "fr-fr",
|
||||
"password": "mypassword",
|
||||
},
|
||||
format="json",
|
||||
HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
|
||||
)
|
||||
assert response.status_code == 404
|
||||
assert "Not Found" in response.content.decode("utf-8")
|
||||
@@ -161,7 +157,7 @@ def test_api_users_update_anonymous():
|
||||
"""Anonymous users should not be able to update users via the API."""
|
||||
user = factories.UserFactory()
|
||||
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
|
||||
response = APIClient().put(
|
||||
@@ -176,21 +172,24 @@ def test_api_users_update_anonymous():
|
||||
}
|
||||
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
assert value == old_user_values[key]
|
||||
|
||||
|
||||
def test_api_users_update_authenticated_self():
|
||||
"""
|
||||
Authenticated users should be able to update their own user but only "language" and "timezone" fields.
|
||||
Authenticated users should be able to update their own user but only "language"
|
||||
and "timezone" fields.
|
||||
"""
|
||||
identity = factories.IdentityFactory()
|
||||
user = identity.user
|
||||
jwt_token = OIDCToken.for_user(user)
|
||||
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = dict(
|
||||
serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
)
|
||||
|
||||
response = APIClient().put(
|
||||
f"/api/v1.0/users/{user.id!s}/",
|
||||
@@ -201,7 +200,7 @@ def test_api_users_update_authenticated_self():
|
||||
|
||||
assert response.status_code == 200
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
if key in ["language", "timezone"]:
|
||||
assert value == new_user_values[key]
|
||||
@@ -215,7 +214,7 @@ def test_api_users_update_authenticated_other():
|
||||
jwt_token = OIDCToken.for_user(identity.user)
|
||||
|
||||
user = factories.UserFactory()
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
|
||||
response = APIClient().put(
|
||||
@@ -227,7 +226,7 @@ def test_api_users_update_authenticated_other():
|
||||
|
||||
assert response.status_code == 403
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
assert value == old_user_values[key]
|
||||
|
||||
@@ -236,8 +235,10 @@ def test_api_users_patch_anonymous():
|
||||
"""Anonymous users should not be able to patch users via the API."""
|
||||
user = factories.UserFactory()
|
||||
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = dict(
|
||||
serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
)
|
||||
|
||||
for key, new_value in new_user_values.items():
|
||||
response = APIClient().patch(
|
||||
@@ -251,21 +252,24 @@ def test_api_users_patch_anonymous():
|
||||
}
|
||||
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
assert value == old_user_values[key]
|
||||
|
||||
|
||||
def test_api_users_patch_authenticated_self():
|
||||
"""
|
||||
Authenticated users should be able to patch their own user but only "language" and "timezone" fields.
|
||||
Authenticated users should be able to patch their own user but only "language"
|
||||
and "timezone" fields.
|
||||
"""
|
||||
identity = factories.IdentityFactory()
|
||||
user = identity.user
|
||||
jwt_token = OIDCToken.for_user(user)
|
||||
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = dict(
|
||||
serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
)
|
||||
|
||||
for key, new_value in new_user_values.items():
|
||||
response = APIClient().patch(
|
||||
@@ -277,7 +281,7 @@ def test_api_users_patch_authenticated_self():
|
||||
assert response.status_code == 200
|
||||
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
if key in ["language", "timezone"]:
|
||||
assert value == new_user_values[key]
|
||||
@@ -291,8 +295,10 @@ def test_api_users_patch_authenticated_other():
|
||||
jwt_token = OIDCToken.for_user(identity.user)
|
||||
|
||||
user = factories.UserFactory()
|
||||
old_user_values = serializers.UserSerializer(instance=user).data
|
||||
new_user_values = serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
old_user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
new_user_values = dict(
|
||||
serializers.UserSerializer(instance=factories.UserFactory()).data
|
||||
)
|
||||
|
||||
for key, new_value in new_user_values.items():
|
||||
response = APIClient().put(
|
||||
@@ -304,7 +310,7 @@ def test_api_users_patch_authenticated_other():
|
||||
assert response.status_code == 403
|
||||
|
||||
user.refresh_from_db()
|
||||
user_values = serializers.UserSerializer(instance=user).data
|
||||
user_values = dict(serializers.UserSerializer(instance=user).data)
|
||||
for key, value in user_values.items():
|
||||
assert value == old_user_values[key]
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
import pytest
|
||||
|
||||
from core import factories, models
|
||||
from core import factories
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_models_contacts_base_self():
|
||||
contact.save()
|
||||
|
||||
error_message = (
|
||||
"{'__all__': ['A contact cannot point to a base contact that itself points to another "
|
||||
"{'__all__': ['A contact cannot point to a base contact that itself points to a "
|
||||
"base contact.', 'A contact cannot be based on itself.']}"
|
||||
)
|
||||
assert str(excinfo.value) == error_message
|
||||
@@ -45,7 +45,7 @@ def test_models_contacts_base_to_base():
|
||||
factories.ContactFactory(base=contact)
|
||||
|
||||
error_message = (
|
||||
"{'__all__': ['A contact cannot point to a base contact that itself points to another "
|
||||
"{'__all__': ['A contact cannot point to a base contact that itself points to a "
|
||||
"base contact.']}"
|
||||
)
|
||||
assert str(excinfo.value) == error_message
|
||||
@@ -103,7 +103,7 @@ def test_models_contacts_profile_owned_by_other():
|
||||
|
||||
def test_models_contacts_data_valid():
|
||||
"""Contact information matching the jsonschema definition should be valid"""
|
||||
contact = factories.ContactFactory(
|
||||
factories.ContactFactory(
|
||||
data={
|
||||
"emails": [
|
||||
{"type": "Work", "value": "john.doe@work.com"},
|
||||
@@ -157,7 +157,7 @@ def test_models_contacts_data_invalid():
|
||||
}
|
||||
)
|
||||
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "{'data': [\"Validation error in 'emails.0.type': 'invalid type' is not one of ['Work', 'Home', 'Other']\"]}"
|
||||
assert str(excinfo.value) == (
|
||||
"{'data': [\"Validation error in 'emails.0.type': 'invalid type' is not one of ['Work', "
|
||||
"'Home', 'Other']\"]}"
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_models_identities_is_main_automatic():
|
||||
def test_models_identities_is_main_exists():
|
||||
"""A user should always keep one and only one of its identities as main."""
|
||||
user = factories.UserFactory()
|
||||
main_identity, secondary_identity = factories.IdentityFactory.create_batch(
|
||||
main_identity, _secondary_identity = factories.IdentityFactory.create_batch(
|
||||
2, user=user
|
||||
)
|
||||
|
||||
@@ -127,8 +127,8 @@ def test_models_identities_sub_null():
|
||||
models.Identity.objects.create(user=user, sub=None)
|
||||
|
||||
|
||||
def test_models_identities_sub_null():
|
||||
"""The "sub" field should not be null."""
|
||||
def test_models_identities_sub_blank():
|
||||
"""The "sub" field should not be blank."""
|
||||
user = factories.UserFactory()
|
||||
with pytest.raises(ValidationError, match="This field cannot be blank."):
|
||||
models.Identity.objects.create(user=user, email="david@example.com", sub="")
|
||||
@@ -165,9 +165,9 @@ def test_models_identities_sub_spaces():
|
||||
with pytest.raises(ValidationError) as excinfo:
|
||||
factories.IdentityFactory(sub="a b")
|
||||
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "{'sub': ['Enter a valid sub. This value may contain only letters, numbers, and @/./+/-/_ characters.']}"
|
||||
assert str(excinfo.value) == (
|
||||
"{'sub': ['Enter a valid sub. This value may contain only letters, numbers, "
|
||||
"and @/./+/-/_ characters.']}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
import pytest
|
||||
|
||||
from core import factories, models
|
||||
from core import factories
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
@@ -72,7 +72,9 @@ def test_models_team_access_get_abilities_authenticated():
|
||||
|
||||
|
||||
def test_models_team_access_get_abilities_for_owner_of_self_allowed():
|
||||
"""Check abilities of self access for the owner of a team when there is more than one user left."""
|
||||
"""
|
||||
Check abilities of self access for the owner of a team when there is more than one user left.
|
||||
"""
|
||||
access = factories.TeamAccessFactory(role="owner")
|
||||
factories.TeamAccessFactory(team=access.team, role="owner")
|
||||
abilities = access.get_abilities(access.user)
|
||||
|
||||
@@ -41,7 +41,7 @@ def test_models_teams_name_max_length():
|
||||
factories.TeamFactory(name="a " * 50)
|
||||
with pytest.raises(
|
||||
ValidationError,
|
||||
match="Ensure this value has at most 100 characters \(it has 102\).",
|
||||
match=r"Ensure this value has at most 100 characters \(it has 102\)\.",
|
||||
):
|
||||
factories.TeamFactory(name="a " * 51)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ Unit tests for the User model
|
||||
from unittest import mock
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test.utils import override_settings
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
Reference in New Issue
Block a user