Ejemplo n.º 1
0
 def test_regions_within_sitemap(self, sitemap):
     '''It should return the regions from the sitemap.'''
     paca, bdr, arles = create_geozones_fixtures()
     sitemap.fetch()
     url = sitemap.get_by_url('territories.territory', territory=paca)
     assert url is not None
     sitemap.assert_url(url, 0.5, 'weekly')
Ejemplo n.º 2
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 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)
Ejemplo n.º 3
0
    def test_zone_children(self):
        paca, bdr, arles = create_geozones_fixtures()

        response = self.get(url_for('api.zone_children', id=paca.id))
        self.assertStatus(response, 501)
        response = self.get(url_for('api.zone_children', id=bdr.id))
        self.assertStatus(response, 501)
        response = self.get(url_for('api.zone_children', id=arles.id))
        self.assertStatus(response, 501)
Ejemplo n.º 4
0
    def test_zone_datasets(self):
        paca, bdr, arles = create_geozones_fixtures()
        organization = OrganizationFactory()
        for _ in range(3):
            VisibleDatasetFactory(
                organization=organization,
                spatial=SpatialCoverageFactory(zones=[paca.id]))

        response = self.get(url_for('api.zone_datasets', id=paca.id))
        self.assert200(response)
        self.assertEqual(len(response.json), 3)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    def test_zone_datasets_with_dynamic_and_setting(self):
        paca, bdr, arles = create_geozones_fixtures()
        organization = OrganizationFactory()
        for _ in range(3):
            VisibleDatasetFactory(
                organization=organization,
                spatial=SpatialCoverageFactory(zones=[paca.id]))

        response = self.get(url_for('api.zone_datasets', id=paca.id),
                            qs={'dynamic': 1})
        self.assert200(response)
        # No dynamic datasets given that they are added by udata-front extension.
        self.assertEqual(len(response.json), 3)
Ejemplo n.º 7
0
 def test_with_gouvfr_region_territory_datasets(self, client, templates):
     paca, bdr, arles = create_geozones_fixtures()
     url = url_for('territories.territory', territory=paca)
     with templates.capture():
         response = client.get(url)
     assert200(response)
     data = response.data.decode('utf-8')
     assert paca.name in data
     base_datasets = templates.get_context_variable('base_datasets')
     assert len(base_datasets) == 6
     expected = '<div data-udata-territory-id="{dataset.slug}"'
     for dataset in base_datasets:
         assert expected.format(dataset=dataset) in data
Ejemplo n.º 8
0
    def test_zone_datasets_with_dynamic(self):
        paca, bdr, arles = create_geozones_fixtures()
        with self.autoindex():
            organization = OrganizationFactory()
            for _ in range(3):
                VisibleDatasetFactory(
                    organization=organization,
                    spatial=SpatialCoverageFactory(zones=[paca.id]))

        response = self.get(url_for('api.zone_datasets', id=paca.id),
                            qs={'dynamic': 1})
        self.assert200(response)
        # No dynamic datasets given that the setting is deactivated by default.
        self.assertEqual(len(response.json), 3)
Ejemplo n.º 9
0
    def test_zone_children(self, client):
        paca, bdr, arles = create_geozones_fixtures()

        response = client.get(url_for('api.zone_children', id=paca.id))
        assert200(response)
        assert response.json['features'][0]['id'] == bdr.id

        response = client.get(url_for('api.zone_children', id=bdr.id))
        assert200(response)
        assert response.json['features'][0]['id'] == arles.id

        response = client.get(url_for('api.zone_children', id=arles.id))
        assert200(response)
        assert response.json['features'] == []
Ejemplo n.º 10
0
 def test_zone_datasets_empty(self):
     paca, bdr, arles = create_geozones_fixtures()
     response = self.get(url_for('api.zone_datasets', id=paca.id))
     self.assert200(response)
     self.assertEqual(response.json, [])
Ejemplo n.º 11
0
 def setUp(self):
     self.paca, self.bdr, self.arles = create_geozones_fixtures()