Ejemplo n.º 1
0
 def test_community_resource_api_create_remote_needs_dataset(self):
     '''
     It should prevent remote community resource creation without dataset
     from the API
     '''
     self.login()
     response = self.post(url_for('api.community_resources'),
                          CommunityResourceFactory.as_dict())
     self.assertStatus(response, 400)
     data = json.loads(response.data)
     self.assertIn('errors', data)
     self.assertIn('dataset', data['errors'])
     self.assertEqual(CommunityResource.objects.count(), 0)
Ejemplo n.º 2
0
 def test_community_resource_api_create_remote_needs_real_dataset(self):
     '''
     It should prevent remote community resource creation without a valid
     dataset identifier
     '''
     self.login()
     attrs = CommunityResourceFactory.as_dict()
     attrs['dataset'] = 'xxx'
     response = self.post(url_for('api.community_resources'), attrs)
     self.assertStatus(response, 400)
     data = json.loads(response.data)
     self.assertIn('errors', data)
     self.assertIn('dataset', data['errors'])
     self.assertEqual(CommunityResource.objects.count(), 0)
Ejemplo n.º 3
0
 def test_community_resource_api_create_remote(self):
     '''It should create a remote community resource from the API'''
     user = self.login()
     dataset = VisibleDatasetFactory()
     attrs = CommunityResourceFactory.as_dict()
     attrs['dataset'] = str(dataset.id)
     response = self.post(url_for('api.community_resources'), attrs)
     self.assert201(response)
     data = json.loads(response.data)
     self.assertEqual(data['title'], attrs['title'])
     self.assertEqual(data['url'], attrs['url'])
     self.assertEqual(CommunityResource.objects.count(), 1)
     community_resource = CommunityResource.objects.first()
     self.assertEqual(community_resource.dataset, dataset)
     self.assertEqual(community_resource.owner, user)
     self.assertIsNone(community_resource.organization)