Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.
Open
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
4 changes: 4 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = config.settings.tests
testpaths = test integration
python_files = tests.py test_*.py *_tests.py
2 changes: 1 addition & 1 deletion apps/courses/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.core.validators import FileExtensionValidator

from utils import AbstractBaseModel
from utils.abs_model import AbstractBaseModel


class Category(AbstractBaseModel):
Expand Down
1 change: 1 addition & 0 deletions apps/courses/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .test_models import *
7 changes: 5 additions & 2 deletions apps/courses/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CourseListCreateView(generics.ListCreateAPIView):
"""
queryset = Course.objects.all()
serializer_class = CourseSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
permission_classes = [permissions.AllowAny]
# permission_classes = [permissions.IsAuthenticatedOrReadOnly]

def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
Expand Down Expand Up @@ -94,4 +95,6 @@ def delete(self, request, *args, **kwargs):


course_list_create_view = CourseListCreateView.as_view()
course_detail_view = CourseDetailView.as_view()
course_detail_view = CourseDetailView.as_view()

print(Response)
5 changes: 4 additions & 1 deletion config/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .dev import *
from .dev import *
from .base import *
from .prod import *
from .test import *
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"drf_yasg",

"apps.courses",
"apps.authentication",
]

MIDDLEWARE = [
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def main():


if __name__ == "__main__":
main()
main()
15 changes: 11 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
asgiref==3.10.0
django>=5.2.7
asgiref==3.9.2
Django==5.2.6
django-debug-toolbar==6.0.0
djangorestframework==3.16.1
drf-yasg==1.21.11
Faker==37.12.0
inflection==0.5.1
iniconfig==2.3.0
packaging==25.0
psycopg2==2.9.11
python-dotenv==1.2.1
pluggy==1.6.0
psycopg2-binary==2.9.10
Pygments==2.19.2
pytest==8.4.2
pytest-django==4.11.1
python-dotenv==1.1.1
pytz==2025.2
PyYAML==6.0.3
sqlparse==0.5.3
typing_extensions==4.15.0
tzdata==2025.2
uritemplate==4.2.0
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/courses/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .test_course_api import *
57 changes: 57 additions & 0 deletions tests/courses/test_course_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest
from faker import Faker
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient
from apps.courses.models import Course

fake = Faker()

@pytest.fixture
def api_client():
"""APIClient fixture for making API requests"""
return APIClient()


@pytest.mark.django_db
class TestCourseAPI:
"""Test suite for Course API endpoints"""

def test_create_course(self, api_client):
"""Test creating a new course via API"""
url = reverse('course-list-create')


# user = CustomUser.objects.create_user(username='testuser', password='testpass')
# api_client.force_authenticate(user=user)

course = Course(
title=" ".join(fake.words(nb=3)),
description=fake.text(),
duration=fake.random_int(min=1, max=7000),
is_active=fake.boolean(),
is_premium=fake.boolean()
)

print(type(fake.sentence))
data = {
"title": course.title,
"description": course.description,
"duration": course.duration,
"is_active": course.is_active,
"is_premium": course.is_premium
}
# response = post(url, data, format='json')
response = api_client.post(url, data, format='json')
print(response.status_code)
print(response.data)

result = response.data['result']


assert response.status_code == status.HTTP_201_CREATED
assert result['title'] == course.title
assert result['duration'] == course.duration
assert result['is_active'] == course.is_active
assert Course.objects.filter(title=data['title']).exists()

4 changes: 1 addition & 3 deletions utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .abs_model import AbstractBaseModel

__all__ = ["AbstractBaseModel"]
from .abs_model import *
2 changes: 1 addition & 1 deletion utils/abs_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# utils/abs_model.py
from django.db import models


class AbstractBaseModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)


class Meta:
abstract = True