コード例 #1
0
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
    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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
    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
ファイル: test_auth_api.py プロジェクト: opendatateam/udata
    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
ファイル: test_auth_api.py プロジェクト: opendatateam/udata
    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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_auth_api.py プロジェクト: opendatateam/udata
    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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: mayjolux/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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
ファイル: test_oembed_api.py プロジェクト: odtvince/udata
 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']