def test_new_map_config(self, thumbnail_mock): """Test that new map config can be properly assigned """ self.client.login(username='******', password='******') # Test successful new map creation m = Map() admin_user = get_user_model().objects.get(username='******') dataset_name = Dataset.objects.all().first().alternate m.create_from_dataset_list(admin_user, [dataset_name], "title", "abstract") map_id = m.id url = reverse('new_map_json') # Test GET method with COPY response = self.client.get(url, {'copy': map_id}) self.assertEqual(response.status_code, 200) map_obj = Map.objects.get(id=map_id) config_map = map_obj.viewer_json(None) content = response.content if isinstance(content, bytes): content = content.decode('UTF-8') response_config_dict = json.loads(content) self.assertEqual(config_map['map']['layers'], response_config_dict['map']['layers']) # Test GET method no COPY and no layer in params response = self.client.get(url) self.assertEqual(response.status_code, 200) config_default = default_map_config(None)[0] content = response.content if isinstance(content, bytes): content = content.decode('UTF-8') response_config_dict = json.loads(content) self.assertEqual(config_default['about']['abstract'], response_config_dict['about']['abstract']) self.assertEqual(config_default['about']['title'], response_config_dict['about']['title']) # Test GET method no COPY but with layer in params response = self.client.get(url, {'layer': dataset_name}) self.assertEqual(response.status_code, 200) content = response.content if isinstance(content, bytes): content = content.decode('UTF-8') response_dict = json.loads(content) self.assertEqual(response_dict['fromLayer'], True) # Test POST method without authentication self.client.logout() response = self.client.post(url, {'layer': dataset_name}) self.assertEqual(response.status_code, 401) # Test POST method with authentication and a layer in params self.client.login(username='******', password='******') try: response = self.client.post(url, {'layer': dataset_name}) # Should not accept the request self.assertEqual(response.status_code, 400) # Test POST method with map data in json format response = self.client.post(url, data=self.viewer_config, content_type="text/json") self.assertEqual(response.status_code, 200) content = response.content if isinstance(content, bytes): content = content.decode('UTF-8') map_id = int(json.loads(content)['id']) # Check new map saved map_obj = Map.objects.get(id=map_id) # Check # BBox format: [xmin, xmax, ymin, ymax bbox_str = [ '-90.193207913954200', '-79.206792062465500', '9.059219904470890', '16.540780092025600', 'EPSG:4326' ] self.assertEqual(bbox_str, [str(c) for c in map_obj.bbox]) bbox_long_str = '-90.193207913954200,9.059219904470890,' \ '-79.206792062465500,16.540780092025600' self.assertEqual(bbox_long_str, map_obj.bbox_string) # Test methods other than GET or POST and no layer in params response = self.client.put(url) self.assertEqual(response.status_code, 405) except Exception: pass