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

View file

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

View file

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