Best Python code snippet using tempest_python
tests.py
Source:tests.py
...39class HomePageViewTest(TestCase):40 def test_response_200(self):41 response = self.client.get('/')42 self.assertEqual(response.status_code, 200)43 def test_response_404(self):44 response = self.client.get('/poasdkpoasdkpoakdpoakd')45 self.assertEqual(response.status_code, 404)46 def test_all_urls(self):47 response = self.client.get(reverse('home_page'))48 self.assertEqual(response.status_code, 200)49 def test_template(self):50 response = self.client.get(reverse('home_page'))51 self.assertEqual(response.status_code, 200)52 self.assertTemplateUsed(response, 'index.html')53 def test_site_content(self):54 response = self.client.get(reverse('home_page'))55 self.assertContains(response, 'Blog')56class PostPageViewTest(TestCase):57 def setUp(self) -> None:58 self.user = get_user_model().objects.create_user(59 username=USER_NAME, email=USER_EMAIL, password='****************')60 self.post = Post.objects.create(body=POST_CONTENT,61 author=self.user,62 title=POST_TITLE)63 def test_response_200(self):64 response = self.client.get(f'/post/{self.post.id}')65 self.assertEqual(response.status_code, 200)66 def test_response_404(self):67 """68 ensure that no response when querying for non exsisting object69 """70 no_response = self.client.get(f'/post/10000')71 self.assertEqual(no_response.status_code, 404)72 def test_template(self):73 response = self.client.get(f'/post/{self.post.id}')74 self.assertEqual(response.status_code, 200)75 self.assertTemplateUsed(response, 'post.html')76 def test_content(self):77 response = self.client.get(f'/post/{self.post.id}')...
test_api.py
Source:test_api.py
1import requests2def test_response_200():3 response = requests.get("http://api.zippopotam.us/us/90210")4 assert response.status_code == 200, "status code is not ok"5def test_response_404():6 response = requests.get("http://api.zippopotam.us/us/902104645756756756")7 assert response.status_code == 404, "status code is not ok"8def test_content_type():9 response = requests.get("http://api.zippopotam.us/us/90210")10 assert response.headers["Content-Type"] == "application/json"11def test_body():12 response = requests.get("http://api.zippopotam.us/us/90210")13 response_body = response.json()14 assert response_body["country"] == "United States"15 assert response_body["post code"] == "90210"...
test_jsonplaceholder.py
Source:test_jsonplaceholder.py
...3from jsonschema import validate4def test_response_200(base_url):5 r = requests.get(base_url)6 assert r.status_code == 2007def test_response_404(base_url):8 r = requests.get(base_url + '/123')9 assert r.status_code == 40410def test_validation_id1(base_url, schema_id1):11 r = requests.get(base_url + '/1')12 validate({'id': 1}, schema=schema_id1)13def test_response_201(base_url):14 r = requests.post(base_url)15 assert r.status_code == 20116def test_validation_id101(base_url, schema_id101):17 r = requests.post(base_url)...
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!!