From 2abad89208ad49b28d7700d4ee11618518335f5e Mon Sep 17 00:00:00 2001 From: yann Date: Tue, 9 Sep 2025 16:20:15 +0200 Subject: [PATCH] test models, urls, views - 100% --- pytest.ini | 2 + tests/.coverage | Bin 0 -> 53248 bytes tests/__init__.py | 0 tests/conftest.py | 83 +++++++++++++++++++++++ tests/unit/__init__.py | 0 tests/unit/lettings/__init__.py | 0 tests/unit/lettings/test_models.py | 15 ++++ tests/unit/lettings/test_urls.py | 21 ++++++ tests/unit/lettings/test_views.py | 19 ++++++ tests/unit/oc_lettings_site/__init__.py | 0 tests/unit/oc_lettings_site/test_urls.py | 18 +++++ tests/unit/oc_lettings_site/test_view.py | 10 +++ tests/unit/profiles/__init__.py | 0 tests/unit/profiles/test_models.py | 17 +++++ tests/unit/profiles/test_urls.py | 20 ++++++ tests/unit/profiles/test_views.py | 13 ++++ 16 files changed, 218 insertions(+) create mode 100644 pytest.ini create mode 100644 tests/.coverage create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/lettings/__init__.py create mode 100644 tests/unit/lettings/test_models.py create mode 100644 tests/unit/lettings/test_urls.py create mode 100644 tests/unit/lettings/test_views.py create mode 100644 tests/unit/oc_lettings_site/__init__.py create mode 100644 tests/unit/oc_lettings_site/test_urls.py create mode 100644 tests/unit/oc_lettings_site/test_view.py create mode 100644 tests/unit/profiles/__init__.py create mode 100644 tests/unit/profiles/test_models.py create mode 100644 tests/unit/profiles/test_urls.py create mode 100644 tests/unit/profiles/test_views.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..076dfd2 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE = oc_lettings_site.settings diff --git a/tests/.coverage b/tests/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..e39aa5ccb124db7dec413ae26d323e539e929d37 GIT binary patch literal 53248 zcmeI)U2oe|7zc1Wc9W(};=(kAs+xLkA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_<0uXqy z1=h2=(ks`uJxA7?^^0Ds>qs{Y>Q^po)OURErVJZrY2&gC`MY<5*XyAS=rDbgPqbY( zP206Y)1?2?U!QuSqUbFAfBC_1Q5!lHRXui8Udv1aGwEw{WE8BqYs)EWp@2e zKxJOdP??qgALo$bd6kNsI(CsmCGh9}*-}k0zAx2`j`2$A$I`)z-N{jV2tWV=5P$## zAOHafKmY;|P?Sr0udE*Xb~C-r9=>VMK3P$R-TzNr(|gt9NA=kIfBk8encV+t8+xzu z6yhAZd(WKLdsF#iH^@*4`2IhPYY0F90uX=z1Rwwb2tWV=5P-mQEug8IQsmG7RpVcU zey~6Q0uX=z1Rwwb2tWV=5P$##An+UtXj(DPpa1K|&x-Mn@u%?{tzdxw1Rwwb2tWV= z5P$##AOHafKw!cIa=NbO=k)iDX^mE1);|CATsA{%rHneI>iK+0<{V8favpoWo|;Ng|Hz2 z0SG_<0uX=z1Rwwb2tWV=5IB+mfBujA|07W$5d" in response.content.decode() \ No newline at end of file diff --git a/tests/unit/profiles/__init__.py b/tests/unit/profiles/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/profiles/test_models.py b/tests/unit/profiles/test_models.py new file mode 100644 index 0000000..a8a1cb3 --- /dev/null +++ b/tests/unit/profiles/test_models.py @@ -0,0 +1,17 @@ +import pytest +from django.contrib.auth.models import User +from profiles.models import Profile + + +@pytest.mark.django_db +def test_str_profile(): + user = User.objects.create( + username = 'TestUser', + password = 'password', + ) + profile = Profile.objects.create( + user=user, + favorite_city="Paris", + + ) + assert str(profile) == "TestUser" diff --git a/tests/unit/profiles/test_urls.py b/tests/unit/profiles/test_urls.py new file mode 100644 index 0000000..5468059 --- /dev/null +++ b/tests/unit/profiles/test_urls.py @@ -0,0 +1,20 @@ +import pytest +from django.urls import reverse +from django.test import Client + + +@pytest.mark.django_db +def test_should_get_200_on_profile_index(): + """ test the server's response """ + c = Client() + url = reverse('profiles_index') + response = c.get(url) + assert response.status_code == 200 + +@pytest.mark.django_db +def test_should_get_200_on_profile_detail(sample_profile): + c = Client() + url = reverse('profile', kwargs={'username': "TestUser"}) + response = c.get(url) + assert response.status_code == 200 + diff --git a/tests/unit/profiles/test_views.py b/tests/unit/profiles/test_views.py new file mode 100644 index 0000000..fadadb5 --- /dev/null +++ b/tests/unit/profiles/test_views.py @@ -0,0 +1,13 @@ +import pytest +from django.test import Client +from django.urls import reverse +from bs4 import BeautifulSoup + +@pytest.mark.django_db +def test_view_should_display_right_len_list(sample_profile): + c = Client() + url = reverse('profiles_index') + response = c.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + li_tags = soup.find_all('li') + assert len(li_tags) == 3 \ No newline at end of file