Skip to content
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ max-complexity = 18
select = B,C,E,F,W,T4,B9,Q0,N8,VNE
exclude =
**migrations
.venv
venv
tests
74 changes: 71 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Test


on:
pull_request:
branches:
Expand All @@ -9,8 +8,34 @@ on:
jobs:
test:
runs-on: ubuntu-latest
environment: ".env"
timeout-minutes: 15

services:
postgres:
image: postgres:15
env:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_HOST_AUTH_METHOD: "trust"
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -31,5 +56,48 @@ jobs:
- name: Run flake8
run: flake8

# - name: Run unit tests
# run: python manage.py test
- name: Make migrations
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_PORT: 5432
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
python manage.py makemigrations users
python manage.py makemigrations library
python manage.py makemigrations payment

- name: Run migrations
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_PORT: 5432
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
python manage.py migrate users
python manage.py migrate library
python manage.py migrate payment
python manage.py migrate


- name: Run unit tests
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_PORT: 5432
SECRET_KEY: ${{ secrets.SECRET_KEY }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
REDIS_HOST: "127.0.0.1"
REDIS_PORT: "6379"
STRIPE_PUBLIC_KEY: ${{ secrets.STRIPE_PUBLIC_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}

run: python manage.py test
9 changes: 0 additions & 9 deletions config/asgi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
"""
ASGI config for config project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application
Expand Down
9 changes: 0 additions & 9 deletions config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
"""
WSGI config for config project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
Expand Down
4 changes: 2 additions & 2 deletions fixtures/initial_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"model": "users.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$1200000$osjeKfZEdWyzpUB6E4MOfD$/44JNiC4B3QkpY9lHmKtGIWDWd5Dt89fIxH/UK11fHI=",
"password": "pbkdf2_sha256$1200000$vBjfJ5vodjFb8FJturiV0J$rmsxK3EtJUsru6Duw2Ap0uXALUN5pt8x1DzxuhBzKuI=",
"is_superuser": true,
"email": "[email protected]",
"is_staff": true,
Expand All @@ -17,7 +17,7 @@
"model": "users.user",
"pk": 2,
"fields": {
"password": "pbkdf2_sha256$1200000$P09N9FkNeCOqZAEWJhDwXX$mUuiQiKBSn1vjnr+wWGdoTH2gP0zzQjHtDQhEPc2Eb8=",
"password": "pbkdf2_sha256$1200000$vBjfJ5vodjFb8FJturiV0J$rmsxK3EtJUsru6Duw2Ap0uXALUN5pt8x1DzxuhBzKuI=",
"is_superuser": false,
"email": "[email protected]",
"is_staff": false,
Expand Down
2 changes: 0 additions & 2 deletions library/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.contrib import admin

# Register your models here.
1 change: 0 additions & 1 deletion library/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.db import transaction
from django.utils import timezone
from rest_framework import serializers
from library.models import Borrowing, Book
Expand Down
3 changes: 2 additions & 1 deletion library/tests/test_borrowing_api_auth_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
def borrowing_detail_url(borrowing_id: int) -> str:
return reverse("library:borrowing-detail", args=[borrowing_id])


def get_results(data):
return data["results"] if isinstance(data, dict) and "results" in data else data
return data["results"] if isinstance(data, dict) and "results" in data else data # noqa


class BorrowingAuthPermissionsTests(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions library/tests/test_borrowing_api_create_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _payload(self, book_id: int):
return {
"book": book_id,
"expected_return_date": (
timezone.localdate() + timedelta(days=7)).isoformat(),
timezone.localdate() + timedelta(days=7)).isoformat(),
}

def _mock_stripe_session(self, mock_create_session):
Expand All @@ -70,7 +70,7 @@ def test_create_borrowing_requires_auth(self):
# ---- Create borrowing ----

@patch("library.serializers.create_payment_session")
def test_create_borrowing_decreases_inventory_and_attaches_user(self, mock_create_session):
def test_create_borrowing_decreases_inventory_and_attaches_user(self, mock_create_session): # noqa
self._mock_stripe_session(mock_create_session)

self.client.force_authenticate(user=self.user)
Expand Down
3 changes: 0 additions & 3 deletions notifications/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
3 changes: 0 additions & 3 deletions notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.db import models

# Create your models here.
4 changes: 2 additions & 2 deletions notifications/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_notify_task_called_on_borrowing_create(self):
"expected_return_date": "2030-01-20"
}

with patch("notifications.tasks.notify_new_borrowing.delay") as mocked_task:
with patch("notifications.tasks.notify_new_borrowing.delay") as mocked_task: # noqa
response = client.post(
reverse("library:borrowing-list-create"),
reverse("library:borrowing-list"),
payload
)

Expand Down
3 changes: 0 additions & 3 deletions notifications/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.shortcuts import render

# Create your views here.
2 changes: 1 addition & 1 deletion payment/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_payment_session(borrowing, is_fee: bool = False):
"quantity": 1,
}
],
success_url="http://127.0.0.1:8000/api/success/?session_id={CHECKOUT_SESSION_ID}",
success_url="http://127.0.0.1:8000/api/success/?session_id={CHECKOUT_SESSION_ID}", # noqa
cancel_url="http://127.0.0.1:8000/api/cancel/",
)

Expand Down
2 changes: 1 addition & 1 deletion payment/tests/test_payment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ def test_correct_fee_price(self):
session = create_payment_session(self.exp_borrowing)
price = session.total_price / 100
days = (
self.exp_borrowing.actual_return_date - self.exp_borrowing.expected_return_date).days
self.exp_borrowing.actual_return_date - self.exp_borrowing.expected_return_date).days # noqa
calculate_total = days * self.book.daily_fee
self.assertEqual(price, calculate_total)
2 changes: 1 addition & 1 deletion payment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
PaymentViewSet,
StripeWebhookView,
payment_success,
payment_cancel
payment_cancel,
)

app_name = "payment"
Expand Down
4 changes: 1 addition & 3 deletions payment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def get_queryset(self):
def payment_success(request):
session_id = request.GET.get("session_id")

return HttpResponse(
f"✅ Payment successful! Session ID: {session_id}"
)
return HttpResponse(f"✅ Payment successful! Session ID: {session_id}")


def payment_cancel(request):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exclude = '''
/(
migrations
| venv
| .venv
| tests
)/
'''
5 changes: 4 additions & 1 deletion users/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def test_create_user_with_email_successful(self):
"""Test creating user with email"""
email = "[email protected]"
password = "password123"
user = get_user_model().objects.create_user(email=email, password=password)
user = get_user_model().objects.create_user(
email=email,
password=password
)

self.assertEqual(user.email, email)
self.assertTrue(user.check_password(password))
Expand Down
1 change: 0 additions & 1 deletion users/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_user_serializer_validation(self):
self.assertFalse(serializer.is_valid())
self.assertIn("password", serializer.errors)


def test_user_serializer_update(self):
"""Test user serializer update"""
user = get_user_model().objects.create_user("[email protected]", "pass123")
Expand Down
5 changes: 4 additions & 1 deletion users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
class ViewTests(APITestCase):
def setUp(self):
self.url = reverse("users:manage")
self.user = get_user_model().objects.create_user("[email protected]", "pass12345")
self.user = get_user_model().objects.create_user(
"[email protected]",
"pass12345"
)

def test_retrieve_user_unauthorized(self):
"""Test anonim retrieve user data (401)"""
Expand Down