Advertisement
matacoder

Untitled

Sep 5th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. from django.test import TestCase, Client
  2. import datetime as dt
  3.  
  4. # Create your tests here.
  5.  
  6. # Задание
  7.  
  8. # Напишите тесты для проверки страницы сайта с тарифными планами.
  9.  
  10. # Проверьте, что:
  11. # YES- главная страница доступна неавторизованному пользователю, а раздел администратора — нет
  12. # YES- переменная plans есть в контексте шаблона
  13. # YES- имя шаблона, который вызывается при рендеринге главной страницы — index.html
  14. # YES- тип переменной plans — это список, состоящий из 3-х элементов, а их тип — словарь
  15. # YES- на результирующей странице показываются названия тарифных планов и подставляется правильная тема (subject) в ссылку на кнопке "Связаться"
  16. # - в контекстных переменных шаблона присутствует текущий год и он же правильно появляется на странице
  17.  
  18. #@classmethod
  19. class PlansPageTest(TestCase):
  20.     def setUp(self):
  21.         self.client = Client()
  22.         self.response = self.client.get("/")
  23.  
  24.     def testPageCodes(self):
  25.         # формируем GET-запрос к странице сайта        
  26.         self.assertEqual(self.response.status_code, 200)
  27.         response = self.client.get("/admin/")
  28.         self.assertEqual(response.status_code, 302)
  29.  
  30.     def testIndexContext(self):
  31.         self.assertTrue(self.response.context["plans"])
  32.  
  33.     def testIndexTemplate(self):
  34.         self.assertTemplateUsed(self.response, 'index.html')
  35.  
  36.     def testIndexPlans(self):
  37.         self.assertIsInstance(self.response.context["plans"], list)
  38.         testlist = self.response.context["plans"]
  39.         self.assertIn('plans', self.response.context)
  40.         self.assertEqual(len(testlist), 3)
  41.         for item in testlist:
  42.             self.assertIsInstance(item, dict)
  43.  
  44.     def testIndexContent(self):
  45.         plans = self.response.context["plans"]
  46.         for plan in plans:
  47.             testsbj = f"mailto:order@company.site?subject={plan['name']}"
  48.             self.assertContains(self.response, testsbj)
  49.  
  50.     def testContextProcessor(self):
  51.         today = dt.datetime.today().year
  52.         self.assertContains(self.response, today)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement