Skip to content

Commit

Permalink
ZDL-94: Integrate isort package
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanAquino committed Dec 22, 2021
1 parent 7577503 commit e224fed
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 74 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/django-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black flake8 pytest mypy
pip install black flake8 pytest mypy isort
- name: Lint with flake8
run: |
flake8 . --statistics
Expand All @@ -27,6 +27,9 @@ jobs:
mypy .
- name: Check formatting
run: black . --exclude=venv --check
- name: Check isort imports
run: |
isort . --check-only
unit-test:
runs-on: ubuntu-latest
services:
Expand All @@ -50,6 +53,6 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run migrations
run: python manage.py migrate
- name: Test with pytest
- name: Test with pytest with coverage
run: |
pytest . --cov
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
1 change: 1 addition & 0 deletions authentication/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin

from authentication.models import User

admin.site.register(User)
5 changes: 3 additions & 2 deletions authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.db import models
from django.contrib.auth.models import (
AbstractBaseUser,
Group,
BaseUserManager,
Group,
PermissionsMixin,
)
from django.db import models
from rest_framework_simplejwt.tokens import RefreshToken

from authentication.validators import UserTokens


Expand Down
5 changes: 3 additions & 2 deletions authentication/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from rest_framework import serializers
from authentication.models import User
from django.contrib import auth
from rest_framework import serializers
from rest_framework.exceptions import AuthenticationFailed

from authentication.models import User
from authentication.validators import UserLogin


Expand Down
2 changes: 1 addition & 1 deletion authentication/tests/factories/group_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.auth.models import Group
import factory
from django.contrib.auth.models import Group


class CustomersGroupFactory(factory.django.DjangoModelFactory):
Expand Down
5 changes: 3 additions & 2 deletions authentication/tests/factories/user_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from authentication.models import User
import factory
from factory import PostGenerationMethodCall
from factory.django import DjangoModelFactory
import factory

from authentication.models import User


class UserFactory(DjangoModelFactory):
Expand Down
6 changes: 3 additions & 3 deletions authentication/tests/test_auth_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
from django.contrib.auth.models import Group
from django.test import Client
from django.test.client import MULTIPART_CONTENT

from authentication.tests.factories.user_factory import UserFactory
from authentication.models import User
from django.contrib.auth.models import Group
import pytest
from authentication.tests.factories.user_factory import UserFactory


@pytest.mark.django_db
Expand Down
5 changes: 3 additions & 2 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.urls import path

from .views import (
UserRegisterView,
UserLoginView,
SupplierRegisterView,
UserLoginView,
UserProfileView,
UserRegisterView,
)

urlpatterns = [
Expand Down
8 changes: 4 additions & 4 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from rest_condition import Or
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from .permissions import CustomerAccessPermission, SupplierAccessPermission
from .serializers import (
UserSerializer,
UserLoginSerializers,
SupplierSerializer,
UserLoginSerializers,
UserProfileSerializer,
UserSerializer,
)
from rest_framework.response import Response
from rest_framework import status


class UserRegisterView(GenericAPIView):
Expand Down
5 changes: 3 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from authentication.tests.factories.user_factory import UserFactory
from django.contrib.auth.models import Group
from django.test.client import Client
from pytest_django.lazy_django import skip_if_no_django
from django.contrib.auth.models import Group

from authentication.tests.factories.user_factory import UserFactory


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion orders/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Order, OrderItem, ShippingAddress

from .models import Order, OrderItem, ShippingAddress

admin.site.register(Order)
admin.site.register(OrderItem)
Expand Down
2 changes: 1 addition & 1 deletion orders/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 3.0.8 on 2021-01-08 02:01

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion orders/migrations/0002_auto_20210917_2012.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 3.0.8 on 2021-09-17 12:12

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
7 changes: 4 additions & 3 deletions orders/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.utils import timezone
from django.db import models
from authentication.models import User
from products.models import Product
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.utils import timezone

from authentication.models import User
from products.models import Product


class Order(models.Model):
Expand Down
1 change: 1 addition & 0 deletions orders/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers

from orders.models import Order, OrderItem, ShippingAddress
from products.serializers import ProductSerializer

Expand Down
8 changes: 5 additions & 3 deletions orders/tests/factories/order_factory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from orders.models import Order
import datetime

import factory
from factory.django import DjangoModelFactory

from authentication.tests.factories.user_factory import UserFactory
import factory
import datetime
from orders.models import Order


class OrderFactory(DjangoModelFactory):
Expand Down
10 changes: 6 additions & 4 deletions orders/tests/factories/order_item_factory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime

import factory
from factory.django import DjangoModelFactory

from orders.models import OrderItem
from products.tests.factories.product_factory import ProductFactory
from orders.tests.factories.order_factory import OrderFactory
from factory.django import DjangoModelFactory
import factory
import datetime
from products.tests.factories.product_factory import ProductFactory


class OrderItemFactory(DjangoModelFactory):
Expand Down
6 changes: 3 additions & 3 deletions orders/tests/test_orders_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime

from orders.tests.factories.order_item_factory import OrderItemFactory
from orders.tests.factories.order_factory import OrderFactory
from orders.models import OrderItem, Order
import pytest

from orders.models import Order, OrderItem
from orders.tests.factories.order_factory import OrderFactory
from orders.tests.factories.order_item_factory import OrderItemFactory
from products.tests.factories.product_factory import ProductFactory


Expand Down
4 changes: 2 additions & 2 deletions orders/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from orders.views import OrderViewSet
from django.urls import path, include
from django.urls import include, path
from rest_framework.routers import DefaultRouter

from orders.views import OrderViewSet

router = DefaultRouter()
router.register("", OrderViewSet)
Expand Down
3 changes: 2 additions & 1 deletion orders/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel
from typing import Dict, List

from pydantic import BaseModel


class OrdersList(BaseModel):
total_items: int
Expand Down
25 changes: 12 additions & 13 deletions orders/views.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import datetime

from rest_condition import Or
from rest_framework import mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from authentication.permissions import (
CustomerAccessPermission,
SupplierAccessPermission,
)
from orders.exceptions import UnprocessableEntity
from orders.models import Order, OrderItem, ShippingAddress
from rest_framework.response import Response
from orders.serializers import (
OrderItemSerializer,
OrderSerializer,
UpdateCartSerializer,
ShippingAddressSerializer,
UpdateCartSerializer,
)
from rest_framework.permissions import IsAuthenticated
from authentication.permissions import (
CustomerAccessPermission,
SupplierAccessPermission,
)
from rest_framework import mixins, viewsets
from rest_framework.decorators import action
from rest_condition import Or

from orders.validators import OrdersList
from products.models import Product
from rest_framework import status
import datetime


class OrderViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
Expand Down
1 change: 1 addition & 0 deletions products/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin

from products.models import Product

admin.site.register(Product)
2 changes: 1 addition & 1 deletion products/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 3.0.8 on 2021-01-08 02:01

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion products/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.conf import settings
from django.db import models


class Product(models.Model):
Expand Down
1 change: 1 addition & 0 deletions products/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers

from products.models import Product


Expand Down
5 changes: 3 additions & 2 deletions products/tests/factories/product_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from products.models import Product
from factory.django import DjangoModelFactory
import factory
from factory.django import DjangoModelFactory

from products.models import Product


class ProductFactory(DjangoModelFactory):
Expand Down
5 changes: 3 additions & 2 deletions products/tests/test_products_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from products.tests.factories.product_factory import ProductFactory
from products.models import Product
from django.test.client import MULTIPART_CONTENT

from products.models import Product
from products.tests.factories.product_factory import ProductFactory


@pytest.mark.django_db
def test_list_all_products_with_empty_db(logged_in_client):
Expand Down
4 changes: 2 additions & 2 deletions products/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from products.views import ProductViewSet
from django.urls import include, path
from rest_framework import routers
from django.urls import path, include

from products.views import ProductViewSet

router = routers.DefaultRouter()
router.register("", ProductViewSet)
Expand Down
14 changes: 8 additions & 6 deletions products/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from products.models import Product
from rest_framework import filters
from rest_framework.pagination import PageNumberPagination
from rest_framework.parsers import MultiPartParser
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from .serializers import ProductSerializer
from authentication.permissions import SupplierAccessPermission
from rest_framework.viewsets import ModelViewSet
from rest_framework.parsers import MultiPartParser
from rest_framework.pagination import PageNumberPagination
from rest_framework import filters

from authentication.permissions import SupplierAccessPermission
from products.models import Product

from .serializers import ProductSerializer


class ProductViewSet(ModelViewSet):
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
appdirs==1.4.4
asgiref==3.2.10
atomicwrites==1.4.0
attrs==19.3.0
black==20.8b1
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
colorama==0.4.4
coreapi==2.3.3
coreschema==0.0.4
coverage==5.3.1
Expand All @@ -21,6 +23,7 @@ idna==2.10
importlib-metadata==1.7.0
inflection==0.5.1
iniconfig==1.0.1
isort==5.10.1
itypes==1.2.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Expand Down
Loading

0 comments on commit e224fed

Please sign in to comment.