manuels-scolaires/manuels/tests/test_teacher_base_view.py

48 lines
1.9 KiB
Python
Raw Normal View History

2021-07-10 15:28:29 +02:00
from django.test import TestCase
2021-07-10 15:56:07 +02:00
from model_bakery import baker
2021-07-10 15:28:29 +02:00
2021-07-10 15:56:07 +02:00
from manuels.tests.selenium import TeacherSeleniumTestCase, TeacherTestMixin
2021-07-10 15:28:29 +02:00
2021-07-10 15:56:07 +02:00
class TeacherBaseViewTestCase(TeacherTestMixin, TestCase):
2021-07-10 15:28:29 +02:00
def test_view_is_rendered(self):
2021-07-10 15:56:07 +02:00
url = self.teacher.get_absolute_url()
res = self.client.get(url)
assert res.status_code == 200
2021-07-10 15:28:29 +02:00
2021-07-10 15:56:07 +02:00
def view_is_passed_teacher(self):
baker.make_recipe("manuels.tests.book", _quantity=5, teacher=self.teacher)
baker.make_recipe("manuels.tests.book", _quantity=5)
baker.make_recipe("manuels.tests.supply", _quantity=5, teacher=self.teacher)
baker.make_recipe("manuels.tests.supply", _quantity=5)
url = self.teacher.get_absolute_url()
res = self.client.get(url)
assert res.status_code == 200
assert res.context["teacher"] == self.teacher
2021-07-10 15:28:29 +02:00
class TeacherBaseViewSeleniumTestCase(TeacherSeleniumTestCase):
def test_books_are_displayed(self):
2021-07-10 15:56:07 +02:00
teacher_books = baker.make_recipe(
"manuels.tests.book", _quantity=5, teacher=self.teacher
)
other_books = baker.make_recipe("manuels.tests.book", _quantity=5)
url = self.teacher.get_absolute_url()
self.get(url)
for book in teacher_books:
assert book.title in self.selenium.page_source
for book in other_books:
assert book.title not in self.selenium.page_source
2021-07-10 15:28:29 +02:00
def test_supplies_are_displayed(self):
2021-07-10 15:56:07 +02:00
teacher_supplies = baker.make_recipe(
"manuels.tests.supply", _quantity=5, teacher=self.teacher
)
other_supplies = baker.make_recipe("manuels.tests.supply", _quantity=5)
url = self.teacher.get_absolute_url()
self.get(url)
for supply in teacher_supplies:
assert supply.supplies in self.selenium.page_source
for supply in other_supplies:
assert supply.supplies not in self.selenium.page_source