Skip to content

Commit

Permalink
'tests-fixed'
Browse files Browse the repository at this point in the history
  • Loading branch information
VoitecP committed Apr 8, 2024
1 parent c4a3682 commit 62994a0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Dshop/Dshop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_PAGINATION_CLASS": 'rest_framework.pagination.PageNumberPagination',
"PAGE_SIZE": 25,
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"]

"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
}

# drf_spectacular
Expand Down
1 change: 1 addition & 0 deletions Dshop/Dshop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

path('api/users/', include('apps.users.api_urls')),
path('api/', include('apps.products_catalogue.api_urls')),


path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
path(
Expand Down
2 changes: 1 addition & 1 deletion Dshop/apps/products_catalogue/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register('products/', ProductViewSet, basename='products-api')
router.register('products', ProductViewSet, basename='products-api')

urlpatterns = [
path('', include(router.urls)),
Expand Down
96 changes: 48 additions & 48 deletions Dshop/apps/products_catalogue/tests/test_api_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,56 +112,56 @@ def test_product_list_pagination_ten_products_page_too_far(tv_product):
assert response.status_code == 404


# @pytest.mark.parametrize("page_suffix", ["", "?page=1"])
# @pytest.mark.django_db
# def test_product_list_pagination_ten_products_page_1(page_suffix, ten_tv_products):
# response = APIClient().get(reverse("products-api-list") + page_suffix)
# results = response.data['results']
# assert len(results) == 5
# assert results[0]['id'] == ten_tv_products[0].id
# assert results[4]['id'] == ten_tv_products[4].id
# assert response.data['count'] == 10
# assert response.data['next'] == "http://testserver/api/products/?page=2"
# assert response.data['previous'] is None
@pytest.mark.parametrize("page_suffix", ["", "?page=1"])
@pytest.mark.django_db
def test_product_list_pagination_ten_products_page_1(page_suffix, ten_tv_products):
response = APIClient().get(reverse("products-api-list") + page_suffix)
results = response.data['results']
assert len(results) == 5
assert results[0]['id'] == ten_tv_products[0].id
assert results[4]['id'] == ten_tv_products[4].id
assert response.data['count'] == 10
assert response.data['next'] == "http://testserver/api/products/?page=2"
assert response.data['previous'] is None


# @pytest.mark.django_db
# def test_product_list_pagination_ten_products_page_2(ten_tv_products):
# response = APIClient().get(f"{reverse('products-api-list')}?page=2")
# results = response.data['results']
# assert response.status_code == 200
# assert len(results) == 5
# assert results[0]['id'] == ten_tv_products[5].id
# assert results[4]['id'] == ten_tv_products[9].id
# assert response.data['count'] == 10
# assert response.data['next'] is None
# assert response.data['previous'] == "http://testserver/api/products/"


# @pytest.mark.django_db
# def test_product_list_pagination_forty_three_products_page_4(forty_three_tv_products):
# response = APIClient().get(f"{reverse('products-api-list')}?page=4")
# results = response.data['results']
# assert response.status_code == 200
# assert len(results) == 5
# assert results[0]['id'] == forty_three_tv_products[15].id
# assert results[4]['id'] == forty_three_tv_products[19].id
# assert response.data['count'] == 43
# assert response.data['next'] == "http://testserver/api/products/?page=5"
# assert response.data['previous'] == "http://testserver/api/products/?page=3"


# @pytest.mark.django_db
# def test_product_list_pagination_forty_three_products_page_9(forty_three_tv_products):
# response = APIClient().get(f"{reverse('products-api-list')}?page=9")
# results = response.data['results']
# assert response.status_code == 200
# assert len(results) == 3
# assert results[0]['id'] == forty_three_tv_products[40].id
# assert results[2]['id'] == forty_three_tv_products[42].id
# assert response.data['count'] == 43
# assert response.data['next'] is None
# assert response.data['previous'] == "http://testserver/api/products/?page=8"
@pytest.mark.django_db
def test_product_list_pagination_ten_products_page_2(ten_tv_products):
response = APIClient().get(f"{reverse('products-api-list')}?page=2")
results = response.data['results']
assert response.status_code == 200
assert len(results) == 5
assert results[0]['id'] == ten_tv_products[5].id
assert results[4]['id'] == ten_tv_products[9].id
assert response.data['count'] == 10
assert response.data['next'] is None
assert response.data['previous'] == "http://testserver/api/products/"


@pytest.mark.django_db
def test_product_list_pagination_forty_three_products_page_4(forty_three_tv_products):
response = APIClient().get(f"{reverse('products-api-list')}?page=4")
results = response.data['results']
assert response.status_code == 200
assert len(results) == 5
assert results[0]['id'] == forty_three_tv_products[15].id
assert results[4]['id'] == forty_three_tv_products[19].id
assert response.data['count'] == 43
assert response.data['next'] == "http://testserver/api/products/?page=5"
assert response.data['previous'] == "http://testserver/api/products/?page=3"


@pytest.mark.django_db
def test_product_list_pagination_forty_three_products_page_9(forty_three_tv_products):
response = APIClient().get(f"{reverse('products-api-list')}?page=9")
results = response.data['results']
assert response.status_code == 200
assert len(results) == 3
assert results[0]['id'] == forty_three_tv_products[40].id
assert results[2]['id'] == forty_three_tv_products[42].id
assert response.data['count'] == 43
assert response.data['next'] is None
assert response.data['previous'] == "http://testserver/api/products/?page=8"


@pytest.mark.django_db
Expand Down

0 comments on commit 62994a0

Please sign in to comment.