예제 #1
0
 def test_oembeds_api_for_territory_zone_not_found(self, api):
     '''Should raise 400 on unknown zone ID'''
     url = url_for('api.oembeds',
                   references='territory-fr:commune:13004@1970-01-01:xyz')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown territory identifier.'
예제 #2
0
    def test_chunked_upload_bad_chunk(self, client):
        client.login()
        url = url_for('storage.upload', name='tmp')
        uuid = str(uuid4())
        parts = 4

        response = client.post(
            url,
            {
                'file': (StringIO(b'a'), 'blob'),
                'uuid': uuid,
                'filename': 'test.txt',
                'partindex': 0,
                'partbyteoffset': 0,
                'totalfilesize': parts,
                'totalparts': parts,
                'chunksize': 10,  # Does not match
            })

        assert400(response)
        assert not response.json['success']
        assert 'filename' not in response.json
        assert 'url' not in response.json
        assert 'size' not in response.json
        assert 'sha1' not in response.json
        assert 'url' not in response.json

        assert list(storages.chunks.list_files()) == []
예제 #3
0
 def test_oembeds_api_for_territory_zone_not_found(self, api):
     '''Should raise 400 on unknown zone ID'''
     url = url_for('api.oembeds',
                   references='territory-fr:commune:13004@1970-01-01:xyz')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown territory identifier.'
예제 #4
0
    def test_oembeds_dataset_api_get_without_good_item(self, api):
        '''It should fail at fetching an oembed with a wrong item.'''
        user = UserFactory()

        url = url_for('api.oembeds', references='user-{id}'.format(id=user.id))
        response = api.get(url)
        assert400(response)
        assert response.json['message'] == 'Invalid object type.'
예제 #5
0
    def test_oembeds_dataset_api_get_without_good_item(self, api):
        '''It should fail at fetching an oembed with a wrong item.'''
        user = UserFactory()

        url = url_for('api.oembeds', references='user-{id}'.format(id=user.id))
        response = api.get(url)
        assert400(response)
        assert response.json['message'] == 'Invalid object type.'
예제 #6
0
    def test_upload_resource_bad_request(self, client):
        client.login()
        response = client.post(url_for('storage.upload', name='tmp'),
                               {'bad': (StringIO(b'aaa'), 'test.txt')})

        assert400(response)
        assert not response.json['success']
        assert 'error' in response.json
예제 #7
0
    def test_value_error(self, api):
        @ns.route('/exception', endpoint='exception')
        class ExceptionAPI(API):
            def get(self):
                raise ValueError('Not working')

        response = api.get(url_for('api.exception'))

        assert400(response)
        assert response.json['message'] == 'Not working'
예제 #8
0
    def test_value_error(self, api):
        @ns.route('/exception', endpoint='exception')
        class ExceptionAPI(API):
            def get(self):
                raise ValueError('Not working')

        response = api.get(url_for('api.exception'))

        assert400(response)
        assert response.json['message'] == 'Not working'
예제 #9
0
    def test_validation_errors(self, api):
        '''Should raise a HTTP 400 and returns errors on validation error'''
        response = api.put(url_for('api.fake'), {'email': 'wrong'})

        assert400(response)
        assert response.content_type == 'application/json'

        for field in 'required', 'email', 'choices':
            assert field in response.json['errors']
            assert isinstance(response.json['errors'][field], list)
예제 #10
0
    def test_validation_errors(self, api):
        '''Should raise a HTTP 400 and returns errors on validation error'''
        response = api.put(url_for('api.fake'), {'email': 'wrong'})

        assert400(response)
        assert response.content_type == 'application/json'

        for field in 'required', 'email', 'choices':
            assert field in response.json['errors']
            assert isinstance(response.json['errors'][field], list)
예제 #11
0
 def test_oembeds_api_for_territory_dataset_not_registered(self, api):
     '''Should raise 400 on unregistered territory dataset'''
     country = faker.country_code().lower()
     level = 'commune'
     zone = GeoZoneFactory(level='{0}:{1}'.format(country, level))
     TestDataset = territory_dataset_factory()
     TERRITORY_DATASETS[level] = {}
     reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id)
     url = url_for('api.oembeds', references=reference)
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown territory dataset id.'
예제 #12
0
    def test_reuse_api_create_as_permissions(self, api):
        """It should create a reuse as organization from the API

        only if user is member.
        """
        api.login()
        data = ReuseFactory.as_dict()
        org = OrganizationFactory()
        data['organization'] = str(org.id)
        response = api.post(url_for('api.reuses'), data)
        assert400(response)
        assert Reuse.objects.count() == 0
예제 #13
0
 def test_oembeds_api_for_territory_dataset_not_registered(self, api):
     '''Should raise 400 on unregistered territory dataset'''
     country = faker.country_code().lower()
     level = 'commune'
     zone = GeoZoneFactory(level='{0}:{1}'.format(country, level))
     TestDataset = territory_dataset_factory()
     TERRITORY_DATASETS[level] = {}
     reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id)
     url = url_for('api.oembeds', references=reference)
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown territory dataset id.'
예제 #14
0
    def test_revoke_token_with_bad_hint(self, client, oauth):
        user = UserFactory()
        token = OAuth2Token.objects.create(
            client=oauth,
            user=user,
            access_token='access-token',
            refresh_token='refresh-token',
        )
        response = client.post(url_for('oauth.revoke_token'), {
            'token': token.access_token,
            'token_type_hint': 'refresh_token',
        }, headers=basic_header(oauth))

        assert400(response)
        assert OAuth2Token.objects(pk=token.pk).first() == token
예제 #15
0
    def test_revoke_token_with_bad_hint(self, client, oauth):
        user = UserFactory()
        token = OAuth2Token.objects.create(
            client=oauth,
            user=user,
            access_token='access-token',
            refresh_token='refresh-token',
        )
        response = client.post(url_for('oauth.revoke_token'), {
            'token': token.access_token,
            'token_type_hint': 'refresh_token',
        }, headers=basic_header(oauth))

        assert400(response)
        assert OAuth2Token.objects(pk=token.pk).first() == token
예제 #16
0
    def test_create_source_with_unknown_feature(self, api):
        '''Can only use known features in config'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'features': {
                    'unknown': True
                },
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert400(response)
예제 #17
0
    def test_create_source_with_not_boolean_feature(self, api):
        '''It should handled negative values'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'features': {
                    'test': 'not a boolean',
                }
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert400(response)
예제 #18
0
    def test_create_source_with_bad_filter_format(self, api):
        '''Filters should have the right format'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'filters': [
                    {
                        'key': 'unknown',
                        'notvalue': 'any'
                    },
                ]
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert400(response)
예제 #19
0
    def test_create_source_with_unknown_filter(self, api):
        '''Can only use known filters in config'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'filters': [
                    {
                        'key': 'unknown',
                        'value': 'any'
                    },
                ]
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert400(response)
예제 #20
0
    def test_create_source_with_bad_filter_type(self, api):
        '''Can only use the xpected filter type'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'filters': [
                    {
                        'key': 'test',
                        'value': 'not-an-integer'
                    },
                ]
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert400(response)
예제 #21
0
 def test_oembed_without_url(self, api):
     '''It should fail at fetching an oembed without a dataset.'''
     response = api.get(url_for('api.oembed'))
     assert400(response)
     assert 'url' in response.json['errors']
예제 #22
0
 def test_oembeds_dataset_api_get_without_references(self, api):
     '''It should fail at fetching an oembed without a dataset.'''
     response = api.get(url_for('api.oembeds'))
     assert400(response)
     assert 'references' in response.json['errors']
예제 #23
0
 def test_oembed_with_an_invalid_url(self, api):
     '''It should fail at fetching an oembed with an invalid URL.'''
     response = api.get(url_for('api.oembed', url='123456789'))
     assert400(response)
     assert 'url' in response.json['errors']
예제 #24
0
 def test_oembeds_dataset_api_get_without_valid_id(self, api):
     '''It should fail at fetching an oembed without a valid id.'''
     url = url_for('api.oembeds', references='dataset-123456789')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown dataset ID.'
예제 #25
0
 def test_oembeds_api_for_territory_bad_id(self, api):
     '''Should raise 400 on bad territory ID'''
     url = url_for('api.oembeds', references='territory-xyz')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Invalid territory ID.'
예제 #26
0
 def test_oembeds_dataset_api_get_without_good_id(self, api):
     '''It should fail at fetching an oembed without a good id.'''
     response = api.get(url_for('api.oembeds', references='123456789'))
     assert400(response)
     assert response.json['message'] == 'Invalid ID.'
예제 #27
0
 def test_oembeds_dataset_api_get_without_good_id(self, api):
     '''It should fail at fetching an oembed without a good id.'''
     response = api.get(url_for('api.oembeds', references='123456789'))
     assert400(response)
     assert response.json['message'] == 'Invalid ID.'
예제 #28
0
 def test_oembeds_dataset_api_get_without_references(self, api):
     '''It should fail at fetching an oembed without a dataset.'''
     response = api.get(url_for('api.oembeds'))
     assert400(response)
     assert 'references' in response.json['errors']
예제 #29
0
 def test_oembed_with_an_invalid_url(self, api):
     '''It should fail at fetching an oembed with an invalid URL.'''
     response = api.get(url_for('api.oembed', url='123456789'))
     assert400(response)
     assert 'url' in response.json['errors']
예제 #30
0
 def test_oembeds_dataset_api_get_without_valid_id(self, api):
     '''It should fail at fetching an oembed without a valid id.'''
     url = url_for('api.oembeds', references='dataset-123456789')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Unknown dataset ID.'
예제 #31
0
 def test_oembeds_api_for_territory_bad_id(self, api):
     '''Should raise 400 on bad territory ID'''
     url = url_for('api.oembeds', references='territory-xyz')
     response = api.get(url)
     assert400(response)
     assert response.json['message'] == 'Invalid territory ID.'
예제 #32
0
 def test_oembed_without_url(self, api):
     '''It should fail at fetching an oembed without a dataset.'''
     response = api.get(url_for('api.oembed'))
     assert400(response)
     assert 'url' in response.json['errors']