Skip to content

Commit

Permalink
chore(lint): linted with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Oct 30, 2023
1 parent f5d5ccc commit 35b0bc9
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 149 deletions.
5 changes: 2 additions & 3 deletions api/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ def main():
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
msg = "Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?"
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
msg,
) from exc
execute_from_command_line(sys.argv)

Expand Down
3 changes: 2 additions & 1 deletion api/outdated/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UniqueBooleanField(models.BooleanField):
by providing a list of field names as `together` param.
Example:
-------
```
>>> class Email(models.Model):
... user = models.ForeignKey(User)
Expand Down Expand Up @@ -61,6 +62,6 @@ class RepositoryURLField(models.CharField):
RegexValidator(
regex=r"^([-_\w]+\.[-._\w]+)\/([-_\w]+)\/([-_\w]+)$",
message="Invalid repository url",
)
),
]
description = "Field for git repository URLs."
7 changes: 3 additions & 4 deletions api/outdated/oidc_auth/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ def verify_claims(self, claims):

for claim in claims_to_verify:
if claim not in claims:
raise SuspiciousOperation(f'Couldn\'t find "{claim}" claim')
msg = f'Couldn\'t find "{claim}" claim'
raise SuspiciousOperation(msg)

def get_or_create_user(self, access_token, *args):
claims = self.get_userinfo(access_token, *args)

self.verify_claims(claims)

user = OIDCUser(access_token, claims)

return user
return OIDCUser(access_token, claims)
2 changes: 1 addition & 1 deletion api/outdated/oidc_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __str__(self):


class OIDCUser(BaseUser):
def __init__(self, token: str, claims: dict):
def __init__(self, token: str, claims: dict) -> None:
super().__init__()

self.claims = claims
Expand Down
4 changes: 2 additions & 2 deletions api/outdated/oidc_auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class IsAuthenticated(BasePermission):
def has_permission(self, request, view):
def has_permission(self, request, _):
return bool(request.user and request.user.is_authenticated)

def has_object_permission(self, request, view, obj):
def has_object_permission(self, request, view, _):
return self.has_permission(request, view)
15 changes: 12 additions & 3 deletions api/outdated/oidc_auth/tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
],
)
def test_authentication(
db, rf, authentication_header, authenticated, error, requests_mock, settings, claims
db,
rf,
authentication_header,
authenticated,
error,
requests_mock,
settings,
claims,
):
assert User.objects.count() == 0

Expand All @@ -44,7 +51,8 @@ def test_authentication(


@pytest.mark.parametrize(
"modified_claim", ["email", "first_name", "last_name", "username"]
"modified_claim",
["email", "first_name", "last_name", "username"],
)
def test_authentication_claims_changed(
db,
Expand All @@ -71,7 +79,8 @@ def test_authentication_idp_502(
settings,
):
requests_mock.get(
settings.OIDC_OP_USER_ENDPOINT, status_code=status.HTTP_502_BAD_GATEWAY
settings.OIDC_OP_USER_ENDPOINT,
status_code=status.HTTP_502_BAD_GATEWAY,
)

request = rf.get("/openid", HTTP_AUTHORIZATION="Bearer Token")
Expand Down
12 changes: 7 additions & 5 deletions api/outdated/outdated/factories.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import random
from datetime import date, timedelta
from datetime import timedelta

from django.utils import timezone
from factory import Faker, Sequence, SubFactory, Trait, post_generation
from factory.django import DjangoModelFactory

from ..user.factories import UserFactory
from outdated.user.factories import UserFactory

from . import models

PROVIDERS = ["PIP", "NPM"]
Expand All @@ -31,12 +33,12 @@ class Meta:

class Params:
undefined = Trait(end_of_life=None)
outdated = Trait(end_of_life=date.today())
outdated = Trait(end_of_life=timezone.datetime.now().date())
warning = Trait(
end_of_life=date.today() + timedelta(days=150),
end_of_life=timezone.datetime.now().date() + timedelta(days=150),
)
up_to_date = Trait(
end_of_life=date.today() + timedelta(days=365),
end_of_life=timezone.datetime.now().date() + timedelta(days=365),
)


Expand Down
6 changes: 3 additions & 3 deletions api/outdated/outdated/management/commands/syncproject.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand

from ...models import Project
from ...synchroniser import Synchroniser
from outdated.outdated.models import Project
from outdated.outdated.synchroniser import Synchroniser


class Command(BaseCommand):
Expand All @@ -10,7 +10,7 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("project_name", type=str)

def handle(self, *args, **options):
def handle(self, *_, **options):
project_name = options["project_name"]
try:
project = Project.objects.get(name__iexact=project_name)
Expand Down
5 changes: 2 additions & 3 deletions api/outdated/outdated/management/commands/syncprojects.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from asyncio import gather

from outdated.commands import AsyncCommand

from ...models import Project
from ...synchroniser import Synchroniser
from outdated.outdated.models import Project
from outdated.outdated.synchroniser import Synchroniser


class Command(AsyncCommand):
Expand Down
16 changes: 9 additions & 7 deletions api/outdated/outdated/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import date, timedelta
from datetime import timedelta

from django.db import models
from django.db.models.functions import Lower
from django.utils import timezone

from outdated.models import RepositoryURLField, UniqueBooleanField, UUIDModel

from ..user.models import User
from outdated.user.models import User

STATUS_OPTIONS = {
"outdated": "OUTDATED",
Expand All @@ -21,7 +21,7 @@
"NPM": "https://registry.npmjs.org/%s",
}

PROVIDER_CHOICES = [(provider, provider) for provider in PROVIDER_OPTIONS.keys()]
PROVIDER_CHOICES = [(provider, provider) for provider in PROVIDER_OPTIONS]


class Dependency(UUIDModel):
Expand Down Expand Up @@ -62,9 +62,9 @@ class Meta:
def status(self):
if not self.end_of_life:
return STATUS_OPTIONS["undefined"]
elif date.today() >= self.end_of_life:
if timezone.datetime.now().date() >= self.end_of_life:
return STATUS_OPTIONS["outdated"]
elif date.today() + timedelta(days=150) >= self.end_of_life:
if timezone.datetime.now().date() + timedelta(days=150) >= self.end_of_life:
return STATUS_OPTIONS["warning"]
return STATUS_OPTIONS["up_to_date"]

Expand Down Expand Up @@ -123,7 +123,9 @@ def __str__(self):
class Maintainer(UUIDModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
project = models.ForeignKey(
Project, on_delete=models.CASCADE, related_name="maintainers"
Project,
on_delete=models.CASCADE,
related_name="maintainers",
)
is_primary = UniqueBooleanField(default=False, together=["project"])

Expand Down
8 changes: 5 additions & 3 deletions api/outdated/outdated/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Meta:
class ReleaseVersionSerializer(serializers.ModelSerializer):
status = serializers.ReadOnlyField()
included_serializers = {
"dependency": "outdated.outdated.serializers.DependencySerializer"
"dependency": "outdated.outdated.serializers.DependencySerializer",
}

class Meta:
Expand All @@ -22,7 +22,7 @@ class Meta:

class VersionSerializer(serializers.ModelSerializer):
included_serializers = {
"release_version": "outdated.outdated.serializers.ReleaseVersionSerializer"
"release_version": "outdated.outdated.serializers.ReleaseVersionSerializer",
}

class Meta:
Expand All @@ -43,7 +43,9 @@ class Meta:

class ProjectSerializer(serializers.ModelSerializer):
maintainers = serializers.ResourceRelatedField(
many=True, read_only=True, required=False
many=True,
read_only=True,
required=False,
)

included_serializers = {
Expand Down
Loading

0 comments on commit 35b0bc9

Please sign in to comment.