def test_dataset_api_update_existing_resource_with_extras(self): '''It should update a dataset's existing resource with extras''' user = self.login() dataset = VisibleDatasetFactory(owner=user) data = dataset.to_dict() data['resources'][0]['extras'] = {'extra:id': 'id'} response = self.put(url_for('api.dataset', dataset=dataset), data) self.assert200(response) dataset.reload() resource = dataset.resources[0] self.assertEqual(resource.extras, {'extra:id': 'id'})
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.as_dict()) 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)
def test_dataset_api_update_new_resource_with_extras(self): '''It should update a dataset with a new resource with extras''' user = self.login() dataset = VisibleDatasetFactory(owner=user) data = dataset.to_dict() resource_data = ResourceFactory.as_dict() resource_data['extras'] = {'extra:id': 'id'} data['resources'].append(resource_data) response = self.put(url_for('api.dataset', dataset=dataset), data) self.assert200(response) dataset.reload() resource = (r for r in dataset.resources if r.title == resource_data['title']).next() self.assertEqual(resource.extras, {'extra:id': 'id'})