From 9a624994e92e3cf3e7e0f506ca9df26c59f36178 Mon Sep 17 00:00:00 2001 From: lauvwbk Date: Mon, 8 May 2023 18:01:29 +0200 Subject: [PATCH] #99 pytest page model --- aircox/tests/models/test_page.py | 134 +++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 aircox/tests/models/test_page.py diff --git a/aircox/tests/models/test_page.py b/aircox/tests/models/test_page.py new file mode 100644 index 0000000..bff1f5d --- /dev/null +++ b/aircox/tests/models/test_page.py @@ -0,0 +1,134 @@ +import pytest + +from model_bakery import baker + +from aircox.models import Page + + + +@pytest.mark.django_db +class TestCategory: + + def test__str__(self): + page = baker.make(Page) + title = page.__str__() + assert title == page.title + +class TestBasePageQuerySet(): + + @pytest.mark.django_db + def test_draft(self): + baker.make(Page, _quantity=5) + draft_pages = Page.objects.draft() + for page in draft_pages: + assert page.status == Page.STATUS_DRAFT + + @pytest.mark.django_db + def test_published(self): + baker.make(Page, _quantity=5) + published_pages = Page.objects.published() + for page in published_pages: + assert page.status == Page.STATUS_PUBLISHED + + @pytest.mark.django_db + def test_trash(self): + baker.make(Page, _quantity=5) + trashed_pages = Page.objects.published() + for page in trashed_pages: + assert page.status == Page.STATUS_TRASH + + @pytest.mark.django_db + def test_parent_core(self): + # by defining parent in page make the page become childpage. Both childs and parents are link without any specific method. + parent = baker.make(Page) + child1 = baker.make(Page, parent=parent) + child2 = baker.make(Page, parent=parent) + child3 = baker.make(Page, parent=parent) + nochild = baker.make(Page, parent=None) + + assert parent.child_set.count() == 3 + assert child1 in parent.child_set.all() + assert child2 in parent.child_set.all() + assert child3 in parent.child_set.all() + assert nochild not in parent.child_set.all() + + @pytest.mark.django_db + def test_parent_with_parent_object(self): + #retrieve child pages having this parent as parameter of the method + parent = baker.make(Page) + child1 = baker.make(Page, parent=parent) + child2 = baker.make(Page, parent=parent) + child3 = baker.make(Page, parent=parent) + nochild = baker.make(Page, parent=None) + + childs = Page.objects.parent(parent) + + assert child1 in childs + assert child2 in childs + assert child3 in childs + assert nochild not in childs + + @pytest.mark.django_db + def test_parent_with_id(self): + #retrive child pages having this parent id as parameter of the method + parent = baker.make(Page) + child1 = baker.make(Page, parent=parent) + child2 = baker.make(Page, parent=parent) + child3 = baker.make(Page, parent=parent) + nochild = baker.make(Page, parent=None) + + childs = Page.objects.parent(parent.id) + + assert child1 in childs + assert child2 in childs + assert child3 in childs + assert nochild not in childs + + @pytest.mark.django_db + def test_search_with_searchcontent(self): + baker.make(Page, _quantity=4) + page1 = baker.make(Page, title='test') + page2 = baker.make(Page, content='test') + q = 'test' + + results = Page.objects.search(q=q) + + assert page1 in results + assert page2 in results + + @pytest.mark.django_db + def test_search_without_searchcontent(self): + baker.make(Page, _quantity=4) + page1 = baker.make(Page, title='test') + page2 = baker.make(Page, content='test') + q = 'test' + + results = Page.objects.search(q=q, search_content=False) + + assert page1 in results + assert page2 not in results + +#class TestBasePage: + # @pytest.mark.django_db + # def test__str__(self): + + #en cours par laurent TODO + + + + + + + + + + + + + + + + + + +