Beispiel #1
0
 def test_regions_within_sitemap(self):
     '''It should return the regions from the sitemap.'''
     paca, bdr, arles = create_geozones_fixtures()
     self.get_sitemap_tree()
     url = self.get_by_url('territories.territory', territory=paca)
     self.assertIsNotNone(url)
     self.assert_url(url, 0.5, 'weekly')
Beispiel #2
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')
Beispiel #3
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')
Beispiel #4
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)
Beispiel #5
0
 def test_regions_within_sitemap(self):
     '''It should return the regions from the sitemap.'''
     paca, bdr, arles = create_geozones_fixtures()
     self.get_sitemap_tree()
     url = self.get_by_url('territories.territory', territory=paca)
     self.assertIsNotNone(url)
     self.assert_url(url, 0.5, 'weekly')
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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
Beispiel #10
0
    def test_zone_datasets(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))
        self.assert200(response)
        self.assertEqual(len(response.json), 3)
Beispiel #11
0
    def test_zone_datasets(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))
        self.assert200(response)
        self.assertEqual(len(response.json), 3)
Beispiel #12
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
Beispiel #13
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) == 7
     expected = '<div data-udata-territory-id="{dataset.slug}"'
     for dataset in base_datasets:
         assert expected.format(dataset=dataset) in data
Beispiel #14
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
Beispiel #15
0
 def test_with_gouvfr_region_territory_datasets(self):
     paca, bdr, arles = create_geozones_fixtures()
     response = self.client.get(
         url_for('territories.territory', territory=paca))
     self.assert200(response)
     data = response.data.decode('utf-8')
     self.assertIn(paca.name, data)
     base_datasets = self.get_context_variable('base_datasets')
     self.assertEqual(len(base_datasets), 7)
     for dataset in base_datasets:
         self.assertIn(
             '<div data-udata-territory-id="{dataset.slug}"'.format(
                 dataset=dataset), data)
Beispiel #16
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'] == []
Beispiel #17
0
    def test_zone_datasets_with_dynamic_and_setting(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 they are added by gouvfr extension.
        self.assertEqual(len(response.json), 3)
Beispiel #18
0
    def test_zone_datasets_with_dynamic_and_setting(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 they are added by gouvfr extension.
        self.assertEqual(len(response.json), 3)
Beispiel #19
0
 def test_with_gouvfr_region_territory_datasets(self):
     paca, bdr, arles = create_geozones_fixtures()
     response = self.client.get(
         url_for('territories.territory', territory=paca))
     self.assert200(response)
     data = response.data.decode('utf-8')
     self.assertIn(paca.name, data)
     base_datasets = self.get_context_variable('base_datasets')
     self.assertEqual(len(base_datasets), 7)
     for dataset in base_datasets:
         self.assertIn(
             '<div data-udata-territory-id="{dataset.slug}"'.format(
                 dataset=dataset),
             data)
Beispiel #20
0
    def test_zone_children(self):
        paca, bdr, arles = create_geozones_fixtures()

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

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

        response = self.get(url_for('api.zone_children', id=arles.id))
        self.assert200(response)
        self.assertEqual(response.json['features'], [])
Beispiel #21
0
    def test_zone_children(self):
        paca, bdr, arles = create_geozones_fixtures()

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

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

        response = self.get(url_for('api.zone_children', id=arles.id))
        self.assert200(response)
        self.assertEqual(response.json['features'], [])
Beispiel #22
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'] == []
Beispiel #23
0
 def test_oembed_town_territory_api_get(self):
     '''It should fetch a town territory in the oembed format.'''
     paca, bdr, arles = create_geozones_fixtures()
     licence_ouverte = LicenseFactory(id='fr-lo', title='Licence Ouverte')
     odbl_license = LicenseFactory(id='odc-odbl', title='ODbL')
     LicenseFactory(id='notspecified', title='Not Specified')
     town_datasets = TERRITORY_DATASETS['commune']
     for territory_dataset_class in town_datasets.values():
         organization = OrganizationFactory(
             id=territory_dataset_class.organization_id)
         territory = territory_dataset_class(arles)
         reference = 'territory-{id}'.format(id=territory.slug)
         response = self.get(url_for('api.oembeds', references=reference))
         self.assert200(response)
         data = json.loads(response.data)[0]
         self.assertIn('html', data)
         self.assertIn('width', data)
         self.assertIn('maxwidth', data)
         self.assertIn('height', data)
         self.assertIn('maxheight', data)
         self.assertTrue(data['type'], 'rich')
         self.assertTrue(data['version'], '1.0')
         self.assertIn(territory.title, data['html'])
         self.assertIn(cgi.escape(territory.url), data['html'])
         self.assertIn(
             'alt="{name}"'.format(name=organization.name), data['html'])
         self.assertIn(
             md(territory.description, source_tooltip=True), data['html'])
         self.assertIn('Download from localhost', data['html'])
         self.assertIn('Add to your own website', data['html'])
         if territory_dataset_class not in (town_datasets['comptes_com'],):
             if territory_dataset_class == town_datasets['ban_odbl_com']:
                 license = odbl_license
             else:
                 license = licence_ouverte
             self.assertIn(
                 'License: {title}'.format(title=license.title),
                 data['html'])
             self.assertIn(
                 '© {license_id}'.format(license_id=license.id),
                 data['html'])
             self.assertIn(
                 '<a data-tooltip="Source" href="http://localhost/datasets',
                 data['html'])
Beispiel #24
0
 def test_oembed_town_territory_api_get(self):
     '''It should fetch a town territory in the oembed format.'''
     paca, bdr, arles = create_geozones_fixtures()
     licence_ouverte = LicenseFactory(id='fr-lo', title='Licence Ouverte')
     odbl_license = LicenseFactory(id='odc-odbl', title='ODbL')
     LicenseFactory(id='notspecified', title='Not Specified')
     town_datasets = TERRITORY_DATASETS['commune']
     for territory_dataset_class in town_datasets.values():
         organization = OrganizationFactory(
             id=territory_dataset_class.organization_id)
         territory = territory_dataset_class(arles)
         reference = 'territory-{id}'.format(id=territory.slug)
         response = self.get(url_for('api.oembeds', references=reference))
         self.assert200(response)
         data = json.loads(response.data)[0]
         self.assertIn('html', data)
         self.assertIn('width', data)
         self.assertIn('maxwidth', data)
         self.assertIn('height', data)
         self.assertIn('maxheight', data)
         self.assertTrue(data['type'], 'rich')
         self.assertTrue(data['version'], '1.0')
         self.assertIn(territory.title, data['html'])
         self.assertIn(cgi.escape(territory.url), data['html'])
         self.assertIn('alt="{name}"'.format(name=organization.name),
                       data['html'])
         self.assertIn(md(territory.description, source_tooltip=True),
                       data['html'])
         self.assertIn('Download from localhost', data['html'])
         self.assertIn('Add to your own website', data['html'])
         if territory_dataset_class not in (town_datasets['comptes_com'], ):
             if territory_dataset_class == town_datasets['ban_odbl_com']:
                 license = odbl_license
             else:
                 license = licence_ouverte
             self.assertIn('License: {title}'.format(title=license.title),
                           data['html'])
             self.assertIn('© {license_id}'.format(license_id=license.id),
                           data['html'])
             self.assertIn(
                 '<a data-tooltip="Source" href="http://localhost/datasets',
                 data['html'])
 def setUp(self):
     self.paca, self.bdr, self.arles = create_geozones_fixtures()
Beispiel #26
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, [])
Beispiel #27
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, [])
Beispiel #28
0
 def setUp(self):
     super(TerritoriesAPITest, self).setUp()
     self.paca, self.bdr, self.arles = create_geozones_fixtures()
Beispiel #29
0
 def setUp(self):
     self.paca, self.bdr, self.arles = create_geozones_fixtures()