Exemple #1
0
    def test_dataset_api_update_with_no_extras(self):
        '''It should update a dataset from the API with no extras

        In that case the extras parameters are kept.
        '''
        data = DatasetFactory.attributes()
        data['extras'] = {
            'integer': 42,
            'float': 42.0,
            'string': 'value',
        }
        with self.api_user():
            response = self.post(url_for('api.datasets'), data)

        dataset = Dataset.objects.first()
        data = dataset.to_dict()
        del data['extras']
        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(dataset.extras['integer'], 42)
        self.assertEqual(dataset.extras['float'], 42.0)
        self.assertEqual(dataset.extras['string'], 'value')
Exemple #2
0
 def test_dataset_api_fail_to_create_too_long_tags(self):
     '''Should fail creating a dataset with a tag long'''
     data = DatasetFactory.attributes()
     data['tags'] = [unique_string(MAX_TAG_LENGTH + 1)]
     with self.api_user():
         response = self.post(url_for('api.datasets'), data)
     self.assertStatus(response, 400)
Exemple #3
0
 def test_dataset_api_fail_to_create_too_short_tags(self):
     '''It should fail to create a dataset from the API because
     the tag is too short'''
     data = DatasetFactory.attributes()
     data['tags'] = [unique_string(MIN_TAG_LENGTH - 1)]
     with self.api_user():
         response = self.post(url_for('api.datasets'), data)
     self.assertStatus(response, 400)
Exemple #4
0
    def test_dataset_api_create_with_legacy_frequency(self):
        '''It should create a dataset from the API with a legacy frequency'''
        self.login()

        for oldFreq, newFreq in LEGACY_FREQUENCIES.items():
            data = DatasetFactory.attributes()
            data['frequency'] = oldFreq
            response = self.post(url_for('api.datasets'), data)
            self.assert201(response)
            self.assertEqual(response.json['frequency'], newFreq)
Exemple #5
0
 def test_dataset_api_create_and_slugify_tags(self):
     '''It should create a dataset from the API and slugify the tags'''
     data = DatasetFactory.attributes()
     data['tags'] = [' Aaa bBB $$ $$-µ  ']
     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(dataset.tags, ['aaa-bbb-u'])
Exemple #6
0
 def test_dataset_api_create_tags(self):
     '''It should create a dataset from the API with tags'''
     data = DatasetFactory.attributes()
     data['tags'] = [unique_string(16) 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(dataset.tags, sorted(data['tags']))
Exemple #7
0
    def test_dataset_api_create(self):
        '''It should create a dataset from the API'''
        data = DatasetFactory.attributes()
        self.login()
        response = self.post(url_for('api.datasets'), data)
        self.assert201(response)
        self.assertEqual(Dataset.objects.count(), 1)

        dataset = Dataset.objects.first()
        self.assertEqual(dataset.owner, self.user)
        self.assertIsNone(dataset.organization)
Exemple #8
0
    def test_dataset_api_create_with_geom(self):
        '''It should create a dataset with resources from the API'''
        data = DatasetFactory.attributes()
        data['spatial'] = {'geom': SAMPLE_GEOM}

        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(dataset.spatial.geom, SAMPLE_GEOM)
Exemple #9
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)
Exemple #10
0
    def test_dataset_api_create_as_org_permissions(self):
        """It should create a dataset as organization from the API

        only if the current user is member.
        """
        self.login()
        data = DatasetFactory.attributes()
        org = OrganizationFactory()
        data['organization'] = str(org.id)
        response = self.post(url_for('api.datasets'), data)
        self.assert400(response)
        self.assertEqual(Dataset.objects.count(), 0)
Exemple #11
0
    def test_dataset_api_create_as_org(self):
        '''It should create a dataset as organization from the API'''
        self.login()
        data = DatasetFactory.attributes()
        member = Member(user=self.user, role='editor')
        org = OrganizationFactory(members=[member])
        data['organization'] = str(org.id)

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

        dataset = Dataset.objects.first()
        self.assertEqual(dataset.organization, org)
        self.assertIsNone(dataset.owner)
Exemple #12
0
    def test_dataset_api_create_with_extras(self):
        '''It should create a dataset with extras from the API'''
        data = DatasetFactory.attributes()
        data['extras'] = {
            'integer': 42,
            'float': 42.0,
            'string': 'value',
        }
        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(dataset.extras['integer'], 42)
        self.assertEqual(dataset.extras['float'], 42.0)
        self.assertEqual(dataset.extras['string'], 'value')