How to use assert_http_406_not_acceptable method in Django Test Plus

Best Python code snippet using django-test-plus_python

test_population_indicators.py

Source:test_population_indicators.py Github

copy

Full Screen

...66 unknown_level = max(AreaLevel.objects.all().values_list('id', flat=True)) + 167 response = self.post('arealevels-intersect-areas',68 pk=unknown_level,69 data={'drop_constraints': False,})70 self.assert_http_406_not_acceptable(response)71 def test_disaggregate_population(self):72 """Test if the population is correctly Disaggregated to RasterCells"""73 population: Population = self.population74 # disaggregate the population75 response = self.post('populations-disaggregate', pk=-1,76 data={'drop_constraints': False, })77 self.assert_http_406_not_acceptable(response)78 # disaggregate the population79 response = self.post('populations-disaggregate', pk=population.pk,80 data={'drop_constraints': False, })81 self.assert_http_202_accepted(response)82 print(response.data.get('message'))83 # do again to check updates84 response = self.post('populations-disaggregate', pk=population.pk,85 data={'drop_constraints': False, })86 self.assert_http_202_accepted(response)87 # get disaggregated population88 response = self.get_check_200(url='populations-get-details',89 pk=population.pk)90 df = pd.DataFrame.from_records(response.data['rastercellpopulationagegender_set'])91 # compare to population entry...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...62 current_agegroups = response.data63 response = self.post(self.url_key + '-check',64 data=current_agegroups,65 extra={'format': 'json'})66 self.assert_http_406_not_acceptable(response)67 # logout to see if check is not allowed68 self.client.logout()69 response = self.post(self.url_key + '-replace')70 self.assert_http_401_unauthorized(response)71 # login without can_edit_basedata is not allowed72 self.client.force_login(self.profile.user)73 response = self.post(self.url_key + '-replace')74 self.assert_http_403_forbidden(response)75 # with can_edit_basedata it should work76 self.profile.can_edit_basedata = True77 self.profile.save()78 # get the default agegroups79 response = self.get_check_200(self.url_key + '-list',80 data={'defaults': True, })81 default_agegroups = response.data82 # post them to the replace route83 response = self.post(self.url_key + '-replace',84 data=default_agegroups,85 extra={'format': 'json'})86 self.assert_http_200_ok(response)87 assert(len(response.data) == len(RegStatAgeGroups.agegroups))88 response = self.get_check_200(self.url_key + '-list')89 current_agegroups = response.data90 # now the check should work91 response = self.post(self.url_key + '-check',92 data=current_agegroups,93 extra={'format': 'json'})94 self.assert_http_202_accepted(response)95 # change some agegroup definition96 pk1 = current_agegroups[-1]['id']97 pk2 = current_agegroups[-2]['id']98 self.profile.admin_access = True99 self.profile.save()100 response = self.patch(self.url_key + '-detail', pk=pk1,101 data={'fromAge': 83, }, extra={'format': 'json'})102 self.assert_http_200_ok(response)103 response = self.patch(self.url_key + '-detail', pk=pk2,104 data={'toAge': 82, }, extra={'format': 'json'})105 self.assert_http_200_ok(response)106 # get the whole agegroups107 response = self.get_check_200(self.url_key + '-list')108 current_agegroups = response.data109 # check if they are still valid110 response = self.post(self.url_key + '-check',111 data=current_agegroups,112 extra={'format': 'json'})113 # they should fail now114 self.assert_http_406_not_acceptable(response)115class TestRegStatAgeGroup(TestCase):116 def test_repr_of_agegroups(self):117 """Test the representation of agegroups"""118 ag1 = RegStatAgeGroup(from_age=4, to_age=8)119 str(ag1)120 repr(ag1)121 def test_compare_agegroups(self):122 """Test to compare agegroups"""123 ag1 = RegStatAgeGroup(from_age=4, to_age=8)124 ag2 = RegStatAgeGroup(from_age=9, to_age=12)125 ag3 = RegStatAgeGroup(from_age=9, to_age=12)126 assert ag2 == ag3127 assert ag1 != ag2128 assert ag1 != ag3...

Full Screen

Full Screen

test_upload_shape_geopackage.py

Source:test_upload_shape_geopackage.py Github

copy

Full Screen

...69 url = reverse('arealevels-upload-shapefile',70 kwargs={'pk': self.arealevel.pk})71 res = self.client.post(url, data,72 extra=dict(format='multipart/form-data'))73 self.assert_http_406_not_acceptable(res, msg=res.content)...

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