Best Python code snippet using pytest-django_python
tests.py
Source:tests.py
...39 def test_PassengerHomePage(self):40 c = Client()41 response = c.get(('PassengerHomePage'))42 self.assert_(response.status_code, 200)43 self.assertTemplateNotUsed(response, 'PassengerHomePage.html')44 def test_DriverNotification(self):45 c = Client()46 response = c.get(('DriverNotification'))47 self.assert_(response.status_code, 200)48 self.assertTemplateNotUsed(response, 'DriverNotification.html') 49 def test_AddNewDriver(self):50 c = Client()51 response = c.get(('AddNewDriver'))52 self.assert_(response.status_code, 200)53 self.assertTemplateNotUsed(response, 'AddNewDriver.html') 54 def test_AddNewDriver_sendMail(self):55 c = Client()56 response = c.get(('AddNewDriver'))57 self.assert_(response.status_code, 200)58 self.assertTemplateNotUsed(response, 'AddNewDriver/SendMail.html') 59 def test_AddNewDriver_DriverDetails(self):60 c = Client()61 response = c.get(('AddNewDriver'))62 self.assert_(response.status_code, 200)63 self.assertTemplateNotUsed(response, 'AddNewDriver/DriverDetails.html') 64 def test_AddNewDriver_deluser(self):65 c = Client()66 response = c.get(('AddNewDriver'))67 self.assert_(response.status_code, 200)68 self.assertTemplateNotUsed(response, 'AddNewDriver/deluser.html') 69 def test_AddNewDriver_Request(self):70 c = Client()71 response = c.get(('AddNewDriver'))72 self.assert_(response.status_code, 200)73 self.assertTemplateNotUsed(response, 'AddNewDriver/Request.html') 74 def test_PageHome(self):75 c = Client()76 response = c.get(('index'))77 self.assert_(response.status_code, 200)78 self.assertTemplateNotUsed(response, 'index/signup.html') 79 def test_PageHome_login(self):80 c = Client()81 response = c.get(('index'))82 self.assert_(response.status_code, 200)83 self.assertTemplateNotUsed(response, 'index/login.html') 84 def test_PageHome_DriverSignup(self):85 c = Client()86 response = c.get(('index'))87 self.assert_(response.status_code, 200)88 self.assertTemplateNotUsed(response, 'index/DriverSignup.html')89 def test_AdminHomePage(self):90 c = Client()91 response = c.get(('AdminHomePage'))92 self.assert_(response.status_code, 200)93 self.assertTemplateNotUsed(response, 'AdminHomePage.html') 94 def test_AdminHomePage_SendMail(self):95 c = Client()96 response = c.get(('AdminHomePage'))97 self.assert_(response.status_code, 200)98 self.assertTemplateNotUsed(response, 'AdminHomePage/SendMail.html') 99 def test_AdminHomePage_AddNewDriver(self):100 c = Client()101 response = c.get(('AdminHomePage'))102 self.assert_(response.status_code, 200)103 self.assertTemplateNotUsed(response, 'AdminHomePage/AddNewDriver.html') 104 def test_AdminHomePage_DriverDetails(self):105 c = Client()106 response = c.get(('AdminHomePage'))107 self.assert_(response.status_code, 200)108 self.assertTemplateNotUsed(response, 'AdminHomePage/DriverDetails.html') 109 def test_AdminHomePage_deluser(self):110 c = Client()111 response = c.get(('AdminHomePage'))112 self.assert_(response.status_code, 200)113 self.assertTemplateNotUsed(response, 'AdminHomePage/deluser.html')114 def test_AdminHomePage_Request(self):115 c = Client()116 response = c.get(('AdminHomePage'))117 self.assert_(response.status_code, 200)118 self.assertTemplateNotUsed(response, 'AdminHomePage/Request.html')119 def test_deluser(self):120 c = Client()121 response = c.get(('deluser'))122 self.assert_(response.status_code, 200)123 self.assertTemplateNotUsed(response, 'deluser.html') 124 def test_DriverDetails(self):125 c = Client()126 response = c.get(('DriverDetails'))127 self.assert_(response.status_code, 200)128 self.assertTemplateNotUsed(response, 'DriverDetails.html')129 def test_DriverFile(self):130 c = Client()131 response = c.get(('DriverFile'))132 self.assert_(response.status_code, 200)133 self.assertTemplateNotUsed(response, 'DriverFile.html')134 def test_DriverHomePage(self):135 c = Client()136 response = c.get(('DriverHomePage'))137 self.assert_(response.status_code, 200)138 self.assertTemplateNotUsed(response, 'DriverHomePage.html') 139 def test_DriverNotification(self):140 c = Client()141 response = c.get(('DriverNotification'))142 self.assert_(response.status_code, 200)143 self.assertTemplateNotUsed(response, 'DriverNotification.html')144 145 def test_DriverSignup(self):146 c = Client()147 response = c.get(('DriverSignup'))148 self.assert_(response.status_code, 200)149 self.assertTemplateNotUsed(response, 'DriverSignup.html') 150 def test_DriverSignup_DriverFile(self):151 c = Client()152 response = c.get(('DriverSignup'))153 self.assert_(response.status_code, 200)154 self.assertTemplateNotUsed(response, 'DriverSignup/DriverFile.html') 155 def test_login1(self):156 c = Client()157 response = c.get(('login'))158 self.assert_(response.status_code, 200)159 self.assertTemplateNotUsed(response, 'login.html')160 def test_login_AdminHomePade(self):161 c = Client()162 response = c.get(('login'))163 self.assert_(response.status_code, 200)164 self.assertTemplateNotUsed(response, 'login/AdminHomePade.html')165 def test_login_PassengerHomePage(self):166 c = Client()167 response = c.get(('login'))168 self.assert_(response.status_code, 200)169 self.assertTemplateNotUsed(response, 'login/PassengerHomePage.html')170 def test_login_DriverHomePage(self):171 c = Client()172 response = c.get(('login'))173 self.assert_(response.status_code, 200)174 self.assertTemplateNotUsed(response, 'login/DriverHomePage.html')175 def test_NotificationByDriver(self):176 c = Client()177 response = c.get(('NotificationByDriver'))178 self.assert_(response.status_code, 200)179 self.assertTemplateNotUsed(response, 'NotificationByDriver.html')180 def test_PassengerNotification(self):181 c = Client()182 response = c.get(('NotificationByDriver'))183 self.assert_(response.status_code, 200)184 self.assertTemplateNotUsed(response, 'NotificationByDriver/PassengerNotification.html') 185 def test_PassengerNotification_logout(self):186 c = Client()187 response = c.get(('NotificationByDriver'))188 self.assert_(response.status_code, 200)189 self.assertTemplateNotUsed(response, 'NotificationByDriver/login.html')190 def test_PassengerNotification_home_pagre(self):191 c = Client()192 response = c.get(('NotificationByDriver'))193 self.assert_(response.status_code, 200)194 self.assertTemplateNotUsed(response, 'NotificationByDriver/PassengerHomePage.html') 195 def test_SendMail(self):196 c = Client()197 response = c.get(('SendMail'))198 self.assert_(response.status_code, 200)199 self.assertTemplateNotUsed(response, 'SendMail.html')200 def test_Signup(self):201 c = Client()202 response = c.get(('signup'))203 self.assert_(response.status_code, 200)204 self.assertTemplateNotUsed(response, 'signup.html')205 '''206 def test_Requset(self):207 c = Client()208 response = c.get(('Requset'))209 self.assert_(response.status_code, 200)210 self.assertTemplateNotUsed(response, 'Requset.html')211 '''212 213 def test_PassengerNotification1(self):214 c = Client()215 response = c.get(('PassengerNotification'))216 self.assert_(response.status_code, 200)217 self.assertTemplateNotUsed(response, 'PassengerNotification.html') 218 def test_PassengerProfile(self):219 c = Client()220 response = c.get(('PassengerProfile'))221 self.assert_(response.status_code, 200)222 self.assertTemplateNotUsed(response, 'PassengerProfile.html')223 224####################################integration-test########################225@tag('integration_test')226class testPassengerHomePage_integration_test_class(TestCase): 227 def testRegisterStudentAndLogin_new(self):228 #User.objects.create(username='aa', password='aa'229 data = {'username': 'a12', 'password': 'a12'}230 data_login=User.objects.create () #+ User.objects.create = ({'name':'Areen'})231 response = self.client.post(('login'), data=data, follow=True)232 self.assert_(response.status_code, 200)233 response = self.client.post(('PassengerHomePage/'), data=data, follow=True)234 self.assertTemplateNotUsed(response, 'PassengerHomePage.html')235 236 def test_PassengerProfile(self):237 c = Client()238 response = c.get(('PassengerProfile'))239 self.assert_(response.status_code, 200)240 self.assertTemplateNotUsed(response, 'PassengerProfile.html')241 def test_LogIn_PassengerGetDic(self):242 response = self.client.get('Login')#url ש×× 1243 self.assertTrue(User.is_authenticated)244 response = self.client.get(('PassengerGetDic'))#url ×××¨× ×פע×××245 self.assertNotEqual(response.status_code, 300)246 response = self.client.get(('logoutUser'), follow=True)#log out247 self.assertNotEqual(response.status_code, 300)248 def test_LogIn_AdminHomePage(self):249 response = self.client.get('Login')#url ש×× 1250 self.assertTrue(User.is_authenticated)251 response = self.client.get(('AdminHomePage'))#url ×××¨× ×פע×××252 self.assertNotEqual(response.status_code, 300)253 response = self.client.get(('logoutUser'), follow=True)#log out254 self.assertNotEqual(response.status_code, 300)...
skip_test_detail.py
Source:skip_test_detail.py
...97 # User can decide98 self.assertTemplateUsed(response, u'inforequests/detail_decide.html')99 self.assertTemplateUsed(response, u'inforequests/detail_undecided.html')100 # User may not act101 self.assertTemplateNotUsed(response, u'inforequests/detail_add_smail.html')102 self.assertTemplateNotUsed(response, u'inforequests/detail_new_action.html')103 templates = defaultdict(list)104 for template in response.templates:105 templates[template.name].append(template)106 self.assertTemplateUsedCount(response, u'inforequests/detail_email.html', 3)107 def test_inforequest_with_undecided_email_related_models_are_prefetched_before_render(self):108 inforequest, _, _ = self._create_inforequest_scenario()109 self._create_inforequest_email(inforequest=inforequest)110 self._create_inforequest_email(inforequest=inforequest)111 self._create_inforequest_email(inforequest=inforequest)112 self._login_user()113 with self.assertQueriesDuringRender([]):114 response = self.client.get(reverse(u'inforequests:detail', args=(inforequest.pk,)))115 def test_inforequest_without_undecided_email(self):116 inforequest, _, _ = self._create_inforequest_scenario()117 self._login_user()118 response = self.client.get(reverse(u'inforequests:detail', args=(inforequest.pk,)))119 # There is nothing to decide120 self.assertTemplateNotUsed(response, u'inforequests/detail_decide.html')121 self.assertTemplateNotUsed(response, u'inforequests/detail_undecided.html')122 # User may act123 self.assertTemplateUsed(response, u'inforequests/detail_add_smail.html')124 self.assertTemplateUsed(response, u'inforequests/detail_new_action.html')125 def test_inforequest_without_undecided_email_related_models_are_prefetched_before_render(self):126 inforequest, _, _ = self._create_inforequest_scenario()127 self._login_user()128 with self.assertQueriesDuringRender([]):129 response = self.client.get(reverse(u'inforequests:detail', args=(inforequest.pk,)))130 def test_closed_inforequest_with_undecided_email(self):131 inforequest, _, _ = self._create_inforequest_scenario(dict(closed=True))132 self._create_inforequest_email(inforequest=inforequest)133 self._create_inforequest_email(inforequest=inforequest)134 self._create_inforequest_email(inforequest=inforequest)135 self._login_user()136 response = self.client.get(reverse(u'inforequests:detail', args=(inforequest.pk,)))137 # Inforequest is closed, user may do nothing138 self.assertTemplateNotUsed(response, u'inforequests/detail_decide.html')139 self.assertTemplateNotUsed(response, u'inforequests/detail_undecided.html')140 self.assertTemplateNotUsed(response, u'inforequests/detail_add_smail.html')141 self.assertTemplateNotUsed(response, u'inforequests/detail_new_action.html')142 def test_closed_inforequest_without_undecided_email(self):143 inforequest, _, _ = self._create_inforequest_scenario(dict(closed=True))144 self._login_user()145 response = self.client.get(reverse(u'inforequests:detail', args=(inforequest.pk,)))146 # Inforequest is closed, user may do nothing147 self.assertTemplateNotUsed(response, u'inforequests/detail_decide.html')148 self.assertTemplateNotUsed(response, u'inforequests/detail_undecided.html')149 self.assertTemplateNotUsed(response, u'inforequests/detail_add_smail.html')150 self.assertTemplateNotUsed(response, u'inforequests/detail_new_action.html')151 def test_closed_inforequest_related_models_are_prefetched_before_render(self):152 inforequest, _, _ = self._create_inforequest_scenario(dict(closed=True))153 self._create_inforequest_email(inforequest=inforequest)154 self._create_inforequest_email(inforequest=inforequest)155 self._create_inforequest_email(inforequest=inforequest)156 self._login_user()157 with self.assertQueriesDuringRender([]):...
test_views.py
Source:test_views.py
...20 def test_login_GET(self):21 response = self.c.get(self.login)22 self.assertEquals(response.status_code, 200)23 self.assertTemplateUsed(response, 'login/login.html')24 self.assertTemplateNotUsed(response, 'index.html')25 def test_login_logged_user_GET(self):26 response = self.c.post(self.login, self.credentials)27 self.assertEquals(response.status_code, 302)28 self.assertRedirects(response, reverse('homepage'))29 def test_logout_GET(self):30 response = self.c.get(self.logout, follow=True)31 messages = list(response.context['messages'])32 self.assertEqual(len(messages), 1)33 self.assertTemplateNotUsed(response, 'login/logout.html')34 self.assertRedirects(response, reverse('login'))35 def test_register_GET(self):36 response = self.c.get(self.register)37 self.assertEquals(response.status_code, 200)38 self.assertTemplateUsed(response, 'login/register.html')39 self.assertTemplateNotUsed(response, 'index.html')40 def test_game_GET(self):41 self.c.login(username='User', password='admin')42 response = self.c.get(self.game)43 self.c.logout()44 self.assertEquals(response.status_code, 200)45 self.assertTemplateUsed(response, 'tabs/game.html')46 self.assertTemplateUsed(response, 'index.html')47 self.assertTemplateNotUsed(response, 'login/register.html')48 def test_game_GET_fail(self):49 response = self.c.get(self.game)50 self.assertNotEqual(response.status_code, 200)51 def test_stats_GET(self):52 self.c.login(username='User', password='admin')53 response = self.c.get(self.stats)54 self.c.logout()55 self.assertEquals(response.status_code, 200)56 self.assertTemplateUsed(response, 'tabs/stats.html')57 self.assertTemplateUsed(response, 'index.html')58 def test_stats_GET_fail(self):59 response = self.c.get(self.stats)60 self.assertNotEqual(response.status_code, 200)61 def test_home_view_GET(self):62 self.c.login(username='User', password='admin')63 response = self.c.get(self.home)64 self.c.logout()65 self.assertEquals(response.status_code, 200)66 self.assertTemplateUsed(response, 'index.html')67 def test_home_view_GET_fail(self):68 response = self.c.get(self.home)69 self.assertNotEqual(response.status_code, 200)70 def test_results_GET(self):71 response = self.c.get(self.results)72 self.assertEquals(response.status_code, 200)73 self.assertTemplateNotUsed(response, 'base.html')74 self.assertTemplateNotUsed(response, 'index.html')75 self.assertTemplateNotUsed(response, 'tabs/stats.html')76class ViewsTest_POST(TestCase):77 def setUp(self):78 self.credentials = {79 'username': 'User',80 'password': 'admin'}81 self.user = User.objects.create_user(**self.credentials)82 self.c = Client()83 self.login = reverse('login')84 def test_login_POST(self):85 response = self.c.post(self.login, self.credentials)86 self.assertEquals(response.status_code, 302)87 self.assertRedirects(response, reverse('homepage'))88 def test_login_POST_fail(self):89 credentials = {90 'username': 'User',91 'email': 'admin'}92 response = self.c.post(self.login, credentials)93 messages = list(response.context['messages'])94 self.assertEqual(len(messages), 1)95 def test_register_POST(self):96 response = self.c.post(self.login, self.credentials)97 self.assertEquals(response.status_code, 302)98 self.assertRedirects(response, reverse('homepage'))99 def test_register_POST_fail(self):100 credentials = {101 'username': 'User',102 'email': 'admin'}103 response = self.c.post(self.login, credentials)104 messages = list(response.context['messages'])105 self.assertEqual(len(messages), 1)106class LoginTest(TestCase):107 def setUp(self):108 self.credentials = {109 'username': 'User',110 'password': 'admin123'}111 User.objects.create_user(**self.credentials)112 def test_login(self):113 response = self.client.post(reverse('login'),114 self.credentials,115 follow=True)116 self.assertTrue(response.context['user'].is_active)117class RegisterTest(TestCase):118 def setUp(self):119 self.credentials = {120 'username': 'User',121 'password1': 'VrWvr!32',122 'password2': 'VrWvr!32'}123 def test_register(self):124 response = self.client.post(reverse('register'),125 self.credentials,126 follow=True)127 self.assertRedirects(response, reverse('login'))128 def test_register_fail(self):129 credentials = {130 'username': 'User',131 'password1': 'VrWvr!32',132 'password2': 'VrWvq!33'}133 response = self.client.post(reverse('register'),134 credentials,135 follow=True)136 self.assertEquals(response.status_code, 200)137 self.assertTemplateUsed(response, 'login/register.html')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!