How to use assert_http_200_ok method in Django Test Plus

Best Python code snippet using django-test-plus_python

test_views.py

Source:test_views.py Github

copy

Full Screen

...12 self.profile = ProfileFactory()13 self.profile_category = ProfileCategoryFactory(profile=self.profile)14 def test_category_points_list(self):15 self.get('category-points', profile_id=self.profile.pk, profile_category_id=self.profile_category.pk, extra={'format': 'json'})16 self.assert_http_200_ok()17 def test_category_points_geography_list(self):18 geography = GeographyFactory()19 GeographyBoundaryFactory(geography=geography)20 hierarchy = GeographyHierarchyFactory(root_geography=geography)21 profile = ProfileFactory(geography_hierarchy=hierarchy)22 profile_category = ProfileCategoryFactory(profile=profile)23 self.get('category-points-geography', profile_id=profile.pk, profile_category_id=profile_category.pk, geography_code=geography.code, extra={'format': 'json'})24 self.assert_http_200_ok()25 def test_category_points_geography_not_found(self):26 geography = GeographyFactory()27 self.get('category-points-geography', profile_id=self.profile.pk, profile_category_id=self.profile_category.pk, geography_code=geography.code, extra={'format': 'json'})28 self.assert_http_404_not_found()29class TestThemeView(APITestCase):30 def setUp(self):31 self.profile = ProfileFactory()32 def test_points_themes_list(self):33 self.get("points-themes", profile_id=self.profile.pk)34 self.assert_http_200_ok()35class TestLocationView(APITestCase):36 def setUp(self):37 self.profile = ProfileFactory()38 self.theme = ThemeFactory(profile=self.profile)39 self.category = CategoryFactory(profile=self.profile)40 self.location = LocationFactory(category=self.category)41 self.profile_category = ProfileCategoryFactory(42 profile=self.profile, category=self.category, theme=self.theme43 )44 def test_nonexisting_profile(self):45 """46 Test if redirected to 404 when profile id is not valid47 """48 self.get(49 "category-points", profile_id=1234,50 profile_category_id=self.profile_category.id51 )52 self.assert_http_404_not_found()53 def test_nonexisting_profile_category(self):54 """55 Test if redirected to 404 when profile category id is not valid56 """57 self.get(58 "category-points", profile_id=self.profile.id,59 profile_category_id=123460 )61 self.assert_http_404_not_found()62 def test_invalid_profile_id_param(self):63 """64 Test to check if profile id and pc id are linked.65 We should only fetch profile categories that are linked to66 requested profile else throw 40467 pass profile id which is not linked to pc id68 """69 profile = ProfileFactory()70 response = self.get(71 "category-points", profile_id=profile.id,72 profile_category_id=self.profile_category.id73 )74 self.assert_http_404_not_found()75 def test_category_points_returns_all_locations(self):76 """77 categoty-points returns all locations for linked profile category78 """79 response = self.get(80 "category-points", profile_id=self.profile.id,81 profile_category_id=self.profile_category.id82 )83 data = response.data84 self.assert_http_200_ok()85 assert len(data["features"]) == 186 assert data["features"][0]["id"] == self.location.id87 assert data["type"] == "FeatureCollection"88 def test_category_points_no_locations(self):89 """90 category-points returns no locations when there are no locations 91 linked to category of profile category92 """93 profile = ProfileFactory()94 category = CategoryFactory(profile=profile)95 profile_category = ProfileCategoryFactory(96 profile=profile, category=category97 )98 response = self.get(99 "category-points", profile_id=profile.id,100 profile_category_id=profile_category.id101 )102 data = response.data103 self.assert_http_200_ok()104 assert data["type"] == "FeatureCollection"105 assert len(data["features"]) == 0106 def test_with_geography_code_valid_locations(self):107 """108 category-points-geography returns locations inside the boundary for a geography109 default Boundary:110 MultiPolygon([Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)) )])111 default Location: Point(1.0, 1.0)112 """113 geography = GeographyFactory(114 version=self.profile.geography_hierarchy.root_geography.version115 )116 GeographyBoundaryFactory(geography=geography)117 response = self.get(118 "category-points-geography", profile_id=self.profile.id,119 profile_category_id=self.profile_category.id,120 geography_code=geography.code121 )122 data = response.data123 self.assert_http_200_ok()124 assert data["features"][0]["id"] == self.location.id125 assert len(data["features"]) == 1126 assert data["type"] == "FeatureCollection"127 def test_with_different_geography_code_no_locations(self):128 """129 category-points-geography returns no locations when130 the geography code is not linked to the profile131 """132 geography = GeographyFactory()133 response = self.get(134 "category-points-geography", profile_id=self.profile.id,135 profile_category_id=self.profile_category.id,136 geography_code=geography.code137 )138 self.assert_http_404_not_found()139 def test_category_points_geography_new_boundary(self):140 """141 new geography with different boundary should not return location142 """143 geography = GeographyFactory(144 code="ABC",145 version=self.profile.geography_hierarchy.root_geography.version146 )147 GeographyBoundaryFactory(geography=geography, geom=MultiPolygon([148 Polygon( ((5.0, 5.0), (5.0, 50.0), (50.0, 50.0), (50.0, 5.0), (5.0, 5.0)) )149 ]))150 response = self.get(151 "category-points-geography", profile_id=self.profile.id,152 profile_category_id=self.profile_category.id,153 geography_code=geography.code154 )155 data = response.data156 self.assert_http_200_ok()157 assert len(data["features"]) == 0158 assert data["type"] == "FeatureCollection"159 def test_category_points_geography_location_outside_boundary(self):160 """161 Set Location point outside GeographyBoundary162 """163 category = CategoryFactory(profile=self.profile)164 profile_category = ProfileCategoryFactory(165 profile=self.profile, category=category, theme=self.theme166 )167 geography = GeographyFactory(168 version=self.profile.geography_hierarchy.root_geography.version169 )170 GeographyBoundaryFactory(geography=geography)171 location = LocationFactory(category=category, coordinates=Point(70.0, 70.0))172 response = self.get(173 "category-points-geography", profile_id=self.profile.id,174 profile_category_id=profile_category.id,175 geography_code=geography.code176 )177 data = response.data178 self.assert_http_200_ok()179 assert data["type"] == "FeatureCollection"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Django Test Plus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful