Exemplo n.º 1
0
 def test_base_rendering(self):
     response = internal(faker.word(), 32)
     assert200(response)
     assert response.mimetype == 'image/png'
     assert response.is_streamed
     etag, weak = response.get_etag()
     assert etag is not None
Exemplo n.º 2
0
 def test_catalog_rdf_json_ld(self, fmt, client):
     url = url_for('site.rdf_catalog_format', format=fmt)
     response = client.get(url)
     assert200(response)
     assert response.content_type == 'application/ld+json'
     context_url = url_for('site.jsonld_context', _external=True)
     assert response.json['@context'] == context_url
Exemplo n.º 3
0
    def test_post_api_list(self, api):
        '''It should fetch a post list from the API'''
        posts = PostFactory.create_batch(3)

        response = api.get(url_for('api.posts'))
        assert200(response)
        assert len(response.json['data']) == len(posts)
Exemplo n.º 4
0
 def test_swagger_resource_type(self, api):
     response = api.get(url_for('api.specs'))
     assert200(response)
     swagger = json.loads(response.data)
     expected = swagger['paths']['/datasets/{dataset}/resources/']
     expected = expected['put']['responses']['200']['schema']['type']
     assert expected == 'array'
Exemplo n.º 5
0
 def test_render_dataconnexions_6_with_data(self, client):
     # Use tags until we are sure all reuse are correctly labeled
     for tag, label, description in DATACONNEXIONS_6_CATEGORIES:
         badge = Badge(kind=DATACONNEXIONS_6_CANDIDATE)
         VisibleReuseFactory(tags=['dataconnexions-6', tag], badges=[badge])
     response = client.get(url_for('gouvfr.dataconnexions6'))
     assert200(response)
Exemplo n.º 6
0
 def test_render_home_with_discourse(self, rmock, client):
     '''It should render the home page with the latest forum topic'''
     data = {
         'categories': [{
             'id': 1,
             'name': 'Category #1',
         }]
     }
     data_latest = {
         'users': [],
         'topic_list': {
             'topics': [
                 {
                     'last_posted_at': '2017-01-01',
                     'id': 1,
                     'title': 'Title',
                     'fancy_title': 'Fancy Title',
                     'slug': 'title',
                     'category_id': 1,
                     'posts_count': 1,
                     'reply_count': 1,
                     'like_count': 1,
                     'views': 1,
                     'created_at': '2017-01-01',
                     'posters': [],
                 }
             ],
         },
     }
     rmock.get('%s/site.json' % DISCOURSE_URL, json=data)
     rmock.get('%s/l/latest.json' % DISCOURSE_URL, json=data_latest)
     response = client.get(url_for('site.home'))
     assert200(response)
     assert 'Title' in response.data.decode('utf8')
Exemplo n.º 7
0
    def test_authorization_multiple_grant_token(self, client, oauth):

        for i in range(3):
            client.login()
            response = client.post(url_for(
                'oauth.authorize',
                response_type='code',
                client_id=oauth.client_id,
            ), {
                'scope': 'default',
                'accept': '',
            })

            uri, params = response.location.split('?')
            code = parse_qs(params)['code'][0]

            client.logout()
            response = client.post(url_for('oauth.token'), {
                'grant_type': 'authorization_code',
                'code': code,
            }, headers=basic_header(oauth))

            assert200(response)
            assert response.content_type == 'application/json'
            assert 'access_token' in response.json
Exemplo n.º 8
0
    def test_oembed_region_territory_api_get(self, api):
        '''It should fetch a region territory in the oembed format.'''
        paca, bdr, arles = create_geozones_fixtures()
        licence_ouverte = LicenseFactory(id='fr-lo', title='Licence Ouverte')
        LicenseFactory(id='notspecified', title='Not Specified')
        for territory_dataset_class in TERRITORY_DATASETS['region'].values():
            organization = OrganizationFactory(
                id=territory_dataset_class.organization_id)
            territory = territory_dataset_class(paca)
            reference = 'territory-{id}'.format(id=territory.slug)
            response = api.get(url_for('api.oembeds', references=reference))
            assert200(response)
            data = json.loads(response.data)[0]
            assert 'html' in data
            assert 'width' in data
            assert 'maxwidth' in data
            assert 'height' in data
            assert 'maxheight' in data
            assert data['type'] == 'rich'
            assert data['version'] == '1.0'

            html = data['html']
            assert territory.title in html
            assert cgi.escape(territory.url) in html
            assert 'alt="{name}"'.format(name=organization.name) in html
            assert md(territory.description, source_tooltip=True) in html
            assert 'Download from local.test' in html
            assert 'Add to your own website' in html
            if territory_dataset_class not in (
                    TERRITORY_DATASETS['region']['zonages_reg'], ):
                assert 'License: {0}'.format(licence_ouverte.title) in html
                assert '© {0}'.format(licence_ouverte.id) in html
                assert (
                    '<a data-tooltip="Source" href="http://local.test/datasets'
                    in html)
Exemplo n.º 9
0
    def test_no_auth(self, api):
        '''Should not return a content type if there is no content on delete'''
        response = api.get(url_for('api.fake'))

        assert200(response)
        assert response.content_type == 'application/json'
        assert response.json == {'success': True}
Exemplo n.º 10
0
    def test_authorization_grant_token_body_credentials(self, client, oauth):
        client.login()

        response = client.post(url_for(
            'oauth.authorize',
            response_type='code',
            client_id=oauth.client_id,
        ), {
            'scope': 'default',
            'accept': '',
        })

        uri, params = response.location.split('?')
        code = parse_qs(params)['code'][0]

        client.logout()
        response = client.post(url_for('oauth.token'), {
            'grant_type': 'authorization_code',
            'code': code,
            'client_id': oauth.client_id,
            'client_secret': oauth.secret,
        })

        assert200(response)
        assert response.content_type == 'application/json'
        assert 'access_token' in response.json
Exemplo n.º 11
0
    def test_render_reuse_page(self, client):
        '''It should render the reuse page'''
        org = OrganizationFactory()
        dataset = DatasetFactory(organization=org)
        reuse = ReuseFactory(organization=org, datasets=[dataset])

        response = client.get(url_for('reuses.show', reuse=reuse))
        assert200(response)
Exemplo n.º 12
0
 def test_render_metrics(self, client):
     '''It should render the dashboard page'''
     for i in range(3):
         org = OrganizationFactory()
         DatasetFactory(organization=org)
         ReuseFactory(organization=org)
     response = client.get(url_for('site.dashboard'))
     assert200(response)
Exemplo n.º 13
0
    def test_render_dataset_page(self, client):
        '''It should render the dataset page'''
        org = OrganizationFactory()
        dataset = DatasetFactory(organization=org)
        ReuseFactory(organization=org, datasets=[dataset])

        response = client.get(url_for('datasets.show', dataset=dataset))
        assert200(response)
Exemplo n.º 14
0
    def test_expose_jsonld_context(self, client):
        url = url_for('site.jsonld_context')
        assert url == '/context.jsonld'

        response = client.get(url)
        assert200(response)
        assert response.content_type == 'application/ld+json'
        assert response.json == CONTEXT
Exemplo n.º 15
0
    def test_client_credentials_grant_token(self, client, oauth):
        response = client.post(url_for('oauth.token'), {
            'grant_type': 'client_credentials',
        }, headers=basic_header(oauth))

        assert200(response)
        assert response.content_type == 'application/json'
        assert 'access_token' in response.json
Exemplo n.º 16
0
    def test_oembed_with_port_in_https_url(self, api):
        '''It should works on HTTPS URLs with explicit port.'''
        dataset = DatasetFactory()
        url = dataset.external_url.replace('http://local.test/',
                                           'https://local.test:443/')
        api_url = url_for('api.oembed', url=url)

        assert200(api.get(api_url, base_url='https://local.test:443/'))
Exemplo n.º 17
0
 def test_dataset_rdf_json_ld(self, client):
     dataset = DatasetFactory()
     for fmt in 'json', 'jsonld':
         url = url_for('datasets.rdf_format', dataset=dataset, format=fmt)
         response = client.get(url)
         assert200(response)
         assert response.content_type == 'application/ld+json'
         context_url = url_for('site.jsonld_context', _external=True)
         assert response.json['@context'] == context_url
Exemplo n.º 18
0
    def test_header_auth(self, api):
        '''Should handle header API Key authentication'''
        with api.user() as user:  # API Key auth
            response = api.post(url_for('api.fake'),
                                headers={'X-API-KEY': user.apikey})

        assert200(response)
        assert response.content_type == 'application/json'
        assert response.json == {'success': True}
Exemplo n.º 19
0
    def test_session_auth(self, api):
        '''Should handle session authentication'''
        api.client.login()  # Session auth

        response = api.post(url_for('api.fake'))

        assert200(response)
        assert response.content_type == 'application/json'
        assert response.json == {'success': True}
Exemplo n.º 20
0
    def test_render_organization_page(self, client):
        '''It should render the organization page'''
        org = OrganizationFactory()
        datasets = [DatasetFactory(organization=org) for _ in range(3)]
        for dataset in datasets:
            ReuseFactory(organization=org, datasets=[dataset])

        response = client.get(url_for('organizations.show', org=org))
        assert200(response)
Exemplo n.º 21
0
    def test_render_list(self, client, templates):
        '''It should render the post list page'''
        posts = PostFactory.create_batch(3)

        response = client.get(url_for('posts.list'))

        assert200(response)
        rendered_posts = templates.get_context_variable('posts')
        assert len(rendered_posts) == len(posts)
Exemplo n.º 22
0
    def test_no_validation_error(self, api):
        '''Should pass if no validation error'''
        response = api.put(url_for('api.fake'), {
            'required': 'value',
            'email': '*****@*****.**',
            'choices': 'first',
        })

        assert200(response)
        assert response.json == {'success': True}
Exemplo n.º 23
0
    def test_render_search(self, client, autoindex):
        '''It should render the search page'''
        with autoindex():
            for i in range(3):
                org = OrganizationFactory()
                DatasetFactory(organization=org)
                ReuseFactory(organization=org)

        response = client.get(url_for('search.index'))
        assert200(response)
Exemplo n.º 24
0
    def test_renaming(self, client):
        tester = self.model.objects.create(slug='old')
        old_url = url_for('model_tester', model=tester)
        assert200(client.get(old_url))

        tester.slug = 'new'
        tester.save()
        new_url = url_for('model_tester', model=tester)
        assert200(client.get(new_url))
        assert404(client.get(old_url))
Exemplo n.º 25
0
 def test_post_api_update(self, api):
     '''It should update a post from the API'''
     post = PostFactory()
     data = post.to_dict()
     data['content'] = 'new content'
     api.login(AdminFactory())
     response = api.put(url_for('api.post', post=post), data)
     assert200(response)
     assert Post.objects.count() == 1
     assert Post.objects.first().content == 'new content'
Exemplo n.º 26
0
    def test_render_home(self, autoindex, client):
        '''It should render the home page'''
        with autoindex:
            for i in range(3):
                org = OrganizationFactory()
                DatasetFactory(organization=org)
                ReuseFactory(organization=org)

        response = client.get(url_for('site.home'))
        assert200(response)
Exemplo n.º 27
0
    def test_post_api_unpublish(self, api):
        '''It should update a post from the API'''
        post = PostFactory()
        api.login(AdminFactory())
        response = api.delete(url_for('api.publish_post', post=post))
        assert200(response)
        assert Post.objects.count() == 1

        post.reload()
        assert post.published is None
Exemplo n.º 28
0
    def test_oembed_for_dataset_with_organization(self, api):
        '''It should fetch a dataset in the oembed format with org.'''
        organization = OrganizationFactory()
        dataset = DatasetFactory(organization=organization)

        url = url_for('api.oembed', url=dataset.external_url)
        response = api.get(url)
        assert200(response)

        card = theme.render('dataset/card.html', dataset=dataset)
        assert card in response.json['html']
Exemplo n.º 29
0
    def test_oembeds_dataset_api_get_with_organization(self, api):
        '''It should fetch a dataset in the oembed format with org.'''
        organization = OrganizationFactory()
        dataset = DatasetFactory(organization=organization)

        url = url_for('api.oembeds',
                      references='dataset-{id}'.format(id=dataset.id))
        response = api.get(url)
        assert200(response)
        data = response.json[0]
        assert organization.name in data['html']
        assert organization.external_url in data['html']
Exemplo n.º 30
0
    def test_datasets_without_dynamic_region(self, autoindex, client):
        paca, bdr, arles = create_geozones_fixtures()
        with autoindex:
            organization = OrganizationFactory()
            for _ in range(3):
                VisibleDatasetFactory(
                    organization=organization,
                    spatial=SpatialCoverageFactory(zones=[paca.id]))

        response = client.get(url_for('api.zone_datasets', id=paca.id))
        assert200(response)
        assert len(response.json) == 3
Exemplo n.º 31
0
 def test_match_normalized_utf8_slug(self, client):
     slug = 'slüg'
     Tester.objects.create(slug=slug)
     assert200(client.get('/model/sl%C3%BCg'))
Exemplo n.º 32
0
 def test_render_with_data(self, client):
     for i in range(3):
         badge = Badge(kind=OPENFIELD16)
         VisibleDatasetFactory(badges=[badge])
     response = client.get(url_for('gouvfr.openfield16'))
     assert200(response)
Exemplo n.º 33
0
 def test_terms(self, client):
     response = client.get(url_for('site.terms'))
     assert200(response)
Exemplo n.º 34
0
 def test_render_dataconnexions_5_with_data(self, client):
     for tag, label, description in DATACONNEXIONS_5_CATEGORIES:
         badge = Badge(kind=DATACONNEXIONS_5_CANDIDATE)
         VisibleReuseFactory(tags=[tag], badges=[badge])
     response = client.get(url_for('gouvfr.dataconnexions5'))
     assert200(response)
Exemplo n.º 35
0
 def test_render_home_no_data(self, client):
     '''It should render the home page without data'''
     response = client.get(url_for('site.home'))
     assert200(response)
Exemplo n.º 36
0
 def test_organization_api_get(self, api):
     '''It should fetch an organization from the API'''
     organization = OrganizationFactory()
     response = api.get(url_for('api.organization', org=organization))
     assert200(response)
Exemplo n.º 37
0
 def test_resolve_zone_with_validity(self, client):
     zone = GeoZoneFactory()
     url = '/territory/{level}/{code}@{validity.start}/{slug}'
     response = client.get(url.format(**zone._data))
     assert200(response)
Exemplo n.º 38
0
 def test_catalog_rdf_trig(self, client):
     url = url_for('site.rdf_catalog_format', format='trig')
     response = client.get(url)
     assert200(response)
     assert response.content_type == 'application/trig'
Exemplo n.º 39
0
 def test_organization_role_api_get(self, api):
     '''It should fetch an organization's roles list from the API'''
     response = api.get(url_for('api.org_roles'))
     assert200(response)
Exemplo n.º 40
0
 def test_catalog_rdf_rdfxml(self, fmt, client):
     url = url_for('site.rdf_catalog_format', format=fmt)
     response = client.get(url)
     assert200(response)
     assert response.content_type == 'application/rdf+xml'
Exemplo n.º 41
0
 def test_catalog_rdf_n3(self, client):
     url = url_for('site.rdf_catalog_format', format='n3')
     response = client.get(url)
     assert200(response)
     assert response.content_type == 'text/n3'
Exemplo n.º 42
0
    def test_list_sources(self, api):
        sources = HarvestSourceFactory.create_batch(3)

        response = api.get(url_for('api.harvest_sources'))
        assert200(response)
        assert len(response.json['data']) == len(sources)
Exemplo n.º 43
0
 def test_resolve_default_prefix_zone_without_validity(self, client):
     zone = GeoZoneFactory(level='fr:level', validity=None)
     url = '/territory/level/{code}@latest/{slug}'
     response = client.get(url.format(**zone._data))
     assert200(response)
Exemplo n.º 44
0
 def test_render_c3_without_data(self, client):
     response = client.get(url_for('gouvfr.climate_change_challenge'))
     assert200(response)
Exemplo n.º 45
0
 def test_resolve_uuid(self, client):
     uuid = uuid4()
     url = '/uuid/{0}'.format(str(uuid))
     assert200(client.get(url))
Exemplo n.º 46
0
 def test_dataset_rdf_formats(self, client, fmt, mime):
     dataset = DatasetFactory()
     url = url_for('datasets.rdf_format', dataset=dataset, format=fmt)
     response = client.get(url)
     assert200(response)
     assert response.content_type == mime
Exemplo n.º 47
0
 def test_render_dataconnexions_6_without_data(self, client):
     response = client.get(url_for('gouvfr.dataconnexions6'))
     assert200(response)
Exemplo n.º 48
0
 def test_render_metrics_no_data(self, client):
     '''It should render the dashboard page without data'''
     response = client.get(url_for('site.dashboard'))
     assert200(response)
Exemplo n.º 49
0
 def test_licences(self, client):
     response = client.get(url_for('gouvfr.licences'))
     assert200(response)
Exemplo n.º 50
0
 def test_render_search_no_data(self, autoindex, client):
     '''It should render the search page without data'''
     response = client.get(url_for('search.index'))
     assert200(response)
Exemplo n.º 51
0
 def test_credits(self, client):
     response = client.get(url_for('gouvfr.credits'))
     assert200(response)
Exemplo n.º 52
0
 def test_render_with_data(self, client):
     for i in range(3):
         badge = Badge(kind=SPD)
         VisibleDatasetFactory(badges=[badge])
     response = client.get(url_for('gouvfr.spd'))
     assert200(response)
Exemplo n.º 53
0
 def test_redevances(self, client):
     response = client.get(url_for('gouvfr.redevances'))
     assert200(response)
Exemplo n.º 54
0
 def test_resolve_model_from_slug(self, client):
     self.model.objects.create(slug='slug')
     assert200(client.get('/model/slug'))
Exemplo n.º 55
0
 def test_render_home_if_discourse_error(self, rmock, client):
     '''It should render the home page when forum is not available'''
     url = '%s/site.json' % DISCOURSE_URL
     rmock.get(url, exc=requests.ConnectionError('Error'))
     response = client.get(url_for('site.home'))
     assert200(response)
Exemplo n.º 56
0
    def test_get_source(self, api):
        source = HarvestSourceFactory()

        url = url_for('api.harvest_source', ident=str(source.id))
        response = api.get(url)
        assert200(response)
Exemplo n.º 57
0
 def test_post_api_get(self, api):
     '''It should fetch a post from the API'''
     post = PostFactory()
     response = api.get(url_for('api.post', post=post))
     assert200(response)
Exemplo n.º 58
0
 def test_resolve_model_from_id(self, client):
     tester = self.model.objects.create(slug='slug')
     url = '/model/{0}'.format(str(tester.id))
     assert200(client.get(url))
Exemplo n.º 59
0
 def test_source_from_config(self, api):
     api.login()
     data = {'name': faker.word(), 'url': faker.url(), 'backend': 'factory'}
     response = api.post(url_for('api.preview_harvest_source_config'), data)
     assert200(response)
Exemplo n.º 60
0
 def test_render_without_data(self, client):
     response = client.get(url_for('gouvfr.spd'))
     assert200(response)