Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.test import TestCase, Client
- import datetime as dt
- # Create your tests here.
- # Задание
- # Напишите тесты для проверки страницы сайта с тарифными планами.
- # Проверьте, что:
- # YES- главная страница доступна неавторизованному пользователю, а раздел администратора — нет
- # YES- переменная plans есть в контексте шаблона
- # YES- имя шаблона, который вызывается при рендеринге главной страницы — index.html
- # YES- тип переменной plans — это список, состоящий из 3-х элементов, а их тип — словарь
- # YES- на результирующей странице показываются названия тарифных планов и подставляется правильная тема (subject) в ссылку на кнопке "Связаться"
- # - в контекстных переменных шаблона присутствует текущий год и он же правильно появляется на странице
- #@classmethod
- class PlansPageTest(TestCase):
- def setUp(self):
- self.client = Client()
- self.response = self.client.get("/")
- def testPageCodes(self):
- # формируем GET-запрос к странице сайта
- self.assertEqual(self.response.status_code, 200)
- response = self.client.get("/admin/")
- self.assertEqual(response.status_code, 302)
- def testIndexContext(self):
- self.assertTrue(self.response.context["plans"])
- def testIndexTemplate(self):
- self.assertTemplateUsed(self.response, 'index.html')
- def testIndexPlans(self):
- self.assertIsInstance(self.response.context["plans"], list)
- testlist = self.response.context["plans"]
- self.assertIn('plans', self.response.context)
- self.assertEqual(len(testlist), 3)
- for item in testlist:
- self.assertIsInstance(item, dict)
- def testIndexContent(self):
- plans = self.response.context["plans"]
- for plan in plans:
- testsbj = f"mailto:order@company.site?subject={plan['name']}"
- self.assertContains(self.response, testsbj)
- def testContextProcessor(self):
- today = dt.datetime.today().year
- self.assertContains(self.response, today)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement