Skip to content

Commit

Permalink
Linting the whole codecov codebase
Browse files Browse the repository at this point in the history
Running

```
black .
isort --profile=black .
```

on the codebase
  • Loading branch information
ThiagoCodecov committed Oct 28, 2021
1 parent ff68189 commit d2a7e51
Show file tree
Hide file tree
Showing 328 changed files with 1,613 additions and 1,709 deletions.
8 changes: 3 additions & 5 deletions billing/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import stripe
import json
import time

from unittest.mock import patch

import stripe
from django.conf import settings

from rest_framework.test import APITestCase, APIRequestFactory
from rest_framework.reverse import reverse
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory, APITestCase

from codecov_auth.tests.factories import OwnerFactory
from core.tests.factories import RepositoryFactory
Expand Down
1 change: 0 additions & 1 deletion billing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from .views import StripeWebhookHandler


urlpatterns = [
path("stripe/webhooks", StripeWebhookHandler.as_view(), name="stripe-webhook"),
]
18 changes: 8 additions & 10 deletions billing/views.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import logging
import stripe
import json
import logging

from rest_framework.views import APIView
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework import status

import stripe
from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned
from rest_framework import status
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView

from codecov_auth.models import Owner
from codecov_auth.constants import PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS
from services.segment import SegmentService
from codecov_auth.models import Owner
from services.billing import BillingService
from services.segment import SegmentService

from .constants import StripeHTTPHeaders, StripeWebhookEvents


if settings.STRIPE_API_KEY:
stripe.api_key = settings.STRIPE_API_KEY

Expand Down
12 changes: 5 additions & 7 deletions codecov/commands/executor.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
from utils.services import get_long_service_name

from codecov_auth.commands.owner import OwnerCommands
from core.commands.repository import RepositoryCommands
from core.commands.commit import CommitCommands
from core.commands.branch import BranchCommands
from compare.commands.compare import CompareCommands
from core.commands.branch import BranchCommands
from core.commands.commit import CommitCommands
from core.commands.pull import PullCommands

from core.commands.repository import RepositoryCommands
from utils.services import get_long_service_name

mapping = {
"commit": CommitCommands,
"owner": OwnerCommands,
"repository": RepositoryCommands,
"branch": BranchCommands,
"compare": CompareCommands,
"pull": PullCommands
"pull": PullCommands,
}


Expand Down
1 change: 1 addition & 0 deletions codecov/commands/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth.models import AnonymousUser

from core.commands.commit import CommitCommands

from ..base import BaseCommand, BaseInteractor


Expand Down
5 changes: 3 additions & 2 deletions codecov/commands/tests/test_executor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.contrib.auth.models import AnonymousUser
from django.test import RequestFactory
from django.urls import ResolverMatch
from django.contrib.auth.models import AnonymousUser

from codecov_auth.commands.owner import OwnerCommands
from ..executor import Executor, get_executor_from_request, get_executor_from_command

from ..executor import Executor, get_executor_from_command, get_executor_from_request


def test_get_executor_from_request():
Expand Down
18 changes: 6 additions & 12 deletions codecov/settings_base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from corsheaders.defaults import default_headers

from utils.config import get_config, get_settings_module, SettingsModule
import os

from corsheaders.defaults import default_headers

from utils.config import SettingsModule, get_config, get_settings_module

# SECURITY WARNING: keep the secret key used in production secret!
# TODO: get this out of source control
Expand Down Expand Up @@ -105,15 +105,9 @@
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
]


Expand Down
2 changes: 1 addition & 1 deletion codecov/settings_dev.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .settings_base import *
import logging

from .settings_base import *

DEBUG = True
ALLOWED_HOSTS = get_config("setup", "api_allowed_hosts", default=["localhost"])
Expand Down
6 changes: 4 additions & 2 deletions codecov/settings_enterprise.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .settings_base import *
import os
from urllib.parse import urlparse

from utils.config import get_config, get_settings_module

from .settings_base import *

DEBUG = False
THIS_POD_IP = os.environ.get("THIS_POD_IP")
ALLOWED_HOSTS = get_config("setup", "api_allowed_hosts", default=["*"])
Expand Down Expand Up @@ -73,4 +75,4 @@
ALLOWED_HOSTS.append(API_DOMAIN)
# Referenced at module level of services/billing.py, so it needs to be defined
STRIPE_API_KEY = None
SILENCED_SYSTEM_CHECKS = ['urls.W002']
SILENCED_SYSTEM_CHECKS = ["urls.W002"]
3 changes: 2 additions & 1 deletion codecov/settings_prod.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .settings_base import *
import os

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from .settings_base import *

DEBUG = False
THIS_POD_IP = os.environ.get("THIS_POD_IP")
Expand Down
5 changes: 3 additions & 2 deletions codecov/settings_staging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .settings_base import *
import os

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
import os

from .settings_base import *

DEBUG = False
THIS_POD_IP = os.environ.get("THIS_POD_IP")
Expand Down
1 change: 0 additions & 1 deletion codecov/settings_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .settings_base import *


DEBUG = True
ALLOWED_HOSTS = ["localhost"]
WEBHOOK_URL = "" # NGROK TUNNEL HERE
Expand Down
5 changes: 2 additions & 3 deletions codecov/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json

import pytest
from django.conf import settings
from django.test.client import Client
from django.test import TestCase

import pytest
from django.test.client import Client


class ViewTest(TestCase):
Expand Down
7 changes: 3 additions & 4 deletions codecov/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf import settings
from django.contrib import admin
from django.urls import path, include, re_path
from django.urls import include, path, re_path

from internal_api.constants import INTERNAL_API_PREFIX
from codecov import views
from internal_api.constants import INTERNAL_API_PREFIX

urlpatterns = [
path("billing/", include("billing.urls")),
Expand All @@ -13,8 +13,7 @@
path("health/", views.health),
path("", views.health),
path(
"<str:service>/<str:owner_username>/<str:repo_name>/",
include("graphs.urls"),
"<str:service>/<str:owner_username>/<str:repo_name>/", include("graphs.urls"),
),
path("upload/", include("upload.urls")),
]
Expand Down
2 changes: 1 addition & 1 deletion codecov/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect

from core.models import Version

Expand Down
1 change: 1 addition & 0 deletions codecov/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
and os.getenv("OPENTELEMETRY_CODECOV_RATE")
):
from open_telemetry import instrument

instrument()

application = get_wsgi_application()
13 changes: 6 additions & 7 deletions codecov_auth/authentication/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from django.utils import timezone
from django.contrib.auth.backends import BaseBackend
import hashlib
import hmac
import logging
from base64 import b64decode
import hmac
import hashlib

from rest_framework import authentication
from rest_framework import exceptions
from django.contrib.auth.backends import BaseBackend
from django.utils import timezone
from rest_framework import authentication, exceptions

from codecov_auth.models import Session, Owner
from codecov_auth.helpers import decode_token_from_cookie
from codecov_auth.models import Owner, Session
from utils.config import get_config
from utils.services import get_long_service_name

Expand Down
8 changes: 3 additions & 5 deletions codecov_auth/authentication/repo_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from django.utils import timezone
from rest_framework import authentication, exceptions

from codecov_auth.authentication.types import (
RepositoryAsUser,
RepositoryAuthInterface,
)
from codecov_auth.authentication.types import RepositoryAsUser, RepositoryAuthInterface
from codecov_auth.models import RepositoryToken
from core.models import Repository

Expand Down Expand Up @@ -53,11 +50,12 @@ def authenticate(self, request):
LegacyTokenRepositoryAuth(repository, {"token": token}),
)


class RepositoryLegacyTokenAuthentication(authentication.TokenAuthentication):
def authenticate_credentials(self, token):
try:
token = UUID(token)
except (ValueError, TypeError) :
except (ValueError, TypeError):
raise exceptions.AuthenticationFailed("Invalid token.")
try:
repository = Repository.objects.get(upload_token=token)
Expand Down
1 change: 0 additions & 1 deletion codecov_auth/authentication/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def is_authenticated(self):


class RepositoryAuthInterface(object):

def get_scopes():
raise NotImplementedError()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async

from codecov_auth.models import Session
from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, ValidationError
from codecov_auth.models import Session


class CreateApiTokenInteractor(BaseInteractor):
Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/commands/owner/interactors/delete_session.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async

from codecov_auth.models import Session
from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated
from codecov_auth.models import Session


class DeleteSessionInteractor(BaseInteractor):
Expand Down
4 changes: 3 additions & 1 deletion codecov_auth/commands/owner/interactors/fetch_owner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov_auth.models import Owner


class FetchOwnerInteractor(BaseInteractor):
@sync_to_async
def execute(self, username):
return Owner.objects.filter(username=username, service=self.service).first()
return Owner.objects.filter(username=username, service=self.service).first()
6 changes: 3 additions & 3 deletions codecov_auth/commands/owner/interactors/onboard_user.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from asgiref.sync import sync_to_async
import html
import yaml

import yaml
from asgiref.sync import sync_to_async
from django import forms

from codecov_auth.models import OwnerProfile
from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
from codecov_auth.models import OwnerProfile


class OnboardForm(forms.Form):
Expand Down
15 changes: 8 additions & 7 deletions codecov_auth/commands/owner/interactors/set_yaml_on_owner.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from asgiref.sync import sync_to_async
import html

import yaml
from asgiref.sync import sync_to_async
from shared.validation.exceptions import InvalidYamlException
from shared.yaml.validation import validate_yaml

from codecov_auth.models import Owner
from codecov_auth.helpers import current_user_part_of_org
from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import (
NotFound,
Unauthenticated,
ValidationError,
Unauthorized,
NotFound,
ValidationError,
)
from shared.yaml.validation import validate_yaml
from shared.validation.exceptions import InvalidYamlException
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import Owner


class SetYamlOnOwnerInteractor(BaseInteractor):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
from django.test import TransactionTestCase
from django.contrib.auth.models import AnonymousUser
from django.test import TransactionTestCase

from codecov.commands.exceptions import Unauthenticated, ValidationError
from codecov_auth.models import Session
from codecov_auth.tests.factories import OwnerFactory

from ..create_api_token import CreateApiTokenInteractor
from codecov.commands.exceptions import Unauthenticated, ValidationError


class CreateApiTokenInteractorTest(TransactionTestCase):
Expand Down
Loading

0 comments on commit d2a7e51

Please sign in to comment.