Esempio n. 1
0
 def test_create(self):
     data = ResourceFactory.attributes()
     with self.api_user():
         response = self.post(
             url_for('api.resources', dataset=self.dataset), data)
     self.assert201(response)
     self.dataset.reload()
     self.assertEqual(len(self.dataset.resources), 1)
Esempio n. 2
0
    def test_dataset_api_create_with_resources(self):
        '''It should create a dataset with resources from the API'''
        data = DatasetFactory.attributes()
        data['resources'] = [ResourceFactory.attributes() for _ in range(3)]

        with self.api_user():
            response = self.post(url_for('api.datasets'), data)
        self.assert201(response)
        self.assertEqual(Dataset.objects.count(), 1)

        dataset = Dataset.objects.first()
        self.assertEqual(len(dataset.resources), 3)
Esempio n. 3
0
    def test_dataset_api_update_with_resources(self):
        '''It should update a dataset from the API with resources parameters'''
        user = self.login()
        dataset = VisibleDatasetFactory(owner=user)
        initial_length = len(dataset.resources)
        data = dataset.to_dict()
        data['resources'].append(ResourceFactory.attributes())
        response = self.put(url_for('api.dataset', dataset=dataset), data)
        self.assert200(response)
        self.assertEqual(Dataset.objects.count(), 1)

        dataset = Dataset.objects.first()
        self.assertEqual(len(dataset.resources), initial_length + 1)