#99 pytest page model
This commit is contained in:
parent
9be08a4047
commit
9a624994e9
134
aircox/tests/models/test_page.py
Normal file
134
aircox/tests/models/test_page.py
Normal file
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user