Implement some more tests

This commit is contained in:
Gabriel Augendre 2021-07-10 15:56:07 +02:00
parent 6f1d87463c
commit dd24632a70
4 changed files with 62 additions and 36 deletions

View file

@ -0,0 +1,23 @@
import random
from model_bakery import seq
from model_bakery.recipe import Recipe
def random_bool():
return random.choice([True, False])
book = Recipe(
"Book",
title=seq("book title "),
field=seq("field "),
authors=seq("author "),
previously_acquired=random_bool,
consumable=random_bool,
)
supply = Recipe(
"SuppliesRequirement",
field=seq("field "),
)

View file

@ -42,11 +42,7 @@ class SeleniumTestCase(LiveServerTestCase):
return f"{self.live_server_url}{url}"
class TeacherSeleniumTestCase(SeleniumTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
class TeacherTestMixin:
def setUp(self) -> None:
super().setUp()
self.teacher = Teacher.objects.create(
@ -56,6 +52,6 @@ class TeacherSeleniumTestCase(SeleniumTestCase):
email="teacher@example.com",
)
def go_to_teacher_url(self):
url = self.teacher.get_absolute_url()
self.get(url)
class TeacherSeleniumTestCase(TeacherTestMixin, SeleniumTestCase):
pass

View file

@ -6,8 +6,6 @@ from manuels.tests.selenium import SeleniumTestCase
class InscriptionTestCase(SeleniumTestCase):
headless = False
def setUp(self) -> None:
super().setUp()
url = reverse("home_page")

View file

@ -1,38 +1,47 @@
from django.test import TestCase
from model_bakery import baker
from manuels.tests.selenium import TeacherSeleniumTestCase
from manuels.tests.selenium import TeacherSeleniumTestCase, TeacherTestMixin
class TeacherBaseViewTestCase(TestCase):
class TeacherBaseViewTestCase(TeacherTestMixin, TestCase):
def test_view_is_rendered(self):
# Go to url
# check response is 200
assert False
url = self.teacher.get_absolute_url()
res = self.client.get(url)
assert res.status_code == 200
def test_view_contains_books(self):
# Create books linked to teacher
# go to url
# check response is 200
# check books are in context
assert False
def test_view_contains_supplies(self):
# create supplies requirements linked to teacher
# go to url
# check response is 200
# check supplies are in context
assert False
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
class TeacherBaseViewSeleniumTestCase(TeacherSeleniumTestCase):
def test_books_are_displayed(self):
# Create books linked to teacher
# go to url
# check book title is displayed
assert False
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
def test_supplies_are_displayed(self):
# Create books linked to teacher
# go to url
# check supplies name is displayed
assert False
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