Best Python code snippet using django-test-plus_python
tests.py
Source:tests.py
...27class IndexViewTest(TestCase):28 """get test about response index"""29 def setUp(self):30 self.url = reverse('index')31 def test_response_200(self):32 response = self.client.get(self.url)33 self.assertEqual(response.status_code, 200)34 def test_template_used(self):35 response = self.client.get(self.url)36 self.assertTemplateUsed(response, 'index.html')37class TFLViewTest(TestCase):38 """get test about response API"""39 def setUp(self):40 self.url = reverse('api')41 def test_response_200(self):42 response = self.client.get(self.url)43 self.assertEqual(response.status_code, 200)44class TFLViewTest(TestCase):45 """get test about response Results"""46 def setUp(self):47 self.url = reverse('results')48 def test_response_200(self):49 response = self.client.get(self.url)50 self.assertEqual(response.status_code, 200)51class Get_API_return(TestCase):52 """Get test about API return"""53 def setUp(self):54 self.r = get_bus('https://api.tfl.gov.uk/StopPoint/490009333W/arrivals')55 self.r_error = get_bus('https://api.tfl.gov.uk/StopPoint/490009333W/arrivals/222')56 def test_return_list(self):57 self.assertEqual(type(self.r), list)58 def test_return_error(self):...
test_views.py
Source:test_views.py
2class TestAboutView(TestCase):3 def setUp(self):4 self.client = Client()5 6 def test_response_200(self):7 response = self.client.get('/pages/about/')8 self.assertEqual(response.status_code, 200)9 10class TestFaqView(TestCase):11 def setup(self):12 self.client = Client()13 14 def test_response_200(self):15 response = self.client.get('/pages/faq/')16 self.assertEqual(response.status_code, 200)17 18class TestContactView(TestCase):19 def setup(self):20 self.client = Client()21 22 def test_response_200(self):23 response = self.client.get('/pages/contact/')24 self.assertEqual(response.status_code, 200)25 26# Comment it out as I can't get it to show something different than 404 27#class TestContactSendView(TestCase):28# def setup(self):29# self.client = Client()30 31# def test_response_200(self):32# response = self.client.get('/pages/contact_send/')33# self.assertEqual(response.status_code, 404 ) 34 ...
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!!