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)
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)
def test_oembed_county_territory_api_get(self): '''It should fetch a county territory in the oembed format.''' midi_pyrenees = GeoZoneFactory(id='fr/region/73', level='fr/region', name='Midi-Pyrénées', code='73') aveyron = GeoZoneFactory(id='fr/county/12', level='fr/county', name='Aveyron', code='12', parents=[midi_pyrenees.id]) licence_ouverte = LicenseFactory(id='fr-lo', title='Licence Ouverte') LicenseFactory(id='notspecified', title='Not Specified') for territory_dataset_class in TERRITORY_DATASETS['county'].values(): organization = OrganizationFactory( id=territory_dataset_class.organization_id) territory = territory_dataset_class(aveyron) 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 ( TERRITORY_DATASETS['county']['comptes_c'], TERRITORY_DATASETS['county']['zonages_c']): self.assertIn( 'License: {title}'.format(title=licence_ouverte.title), data['html']) self.assertIn( '© {license_id}'.format(license_id=licence_ouverte.id), data['html']) self.assertIn( '<a data-tooltip="Source" href="http://localhost/datasets', data['html'])
def test_oembed_town_territory_api_get(self): '''It should fetch a town territory in the oembed format.''' arles = GeoZoneFactory( id='fr/town/13004', level='fr/town', name='Arles', code='13004', population=52439) 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['town'] 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_t'],): if territory_dataset_class == town_datasets['ban_odbl_t']: 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 test_oembed_town_territory_api_get(self): '''It should fetch a town territory in the oembed format.''' arles = GeoZoneFactory(id='fr/town/13004', level='fr/town', name='Arles', code='13004', population=52439) 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['town'] 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_t'], ): if territory_dataset_class == town_datasets['ban_odbl_t']: 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 test_oembed_county_territory_api_get(self): '''It should fetch a county territory in the oembed format.''' midi_pyrenees = GeoZoneFactory( id='fr/region/73', level='fr/region', name='Midi-Pyrénées', code='73') aveyron = GeoZoneFactory( id='fr/county/12', level='fr/county', name='Aveyron', code='12', parents=[midi_pyrenees.id]) licence_ouverte = LicenseFactory(id='fr-lo', title='Licence Ouverte') LicenseFactory(id='notspecified', title='Not Specified') for territory_dataset_class in TERRITORY_DATASETS['county'].values(): organization = OrganizationFactory( id=territory_dataset_class.organization_id) territory = territory_dataset_class(aveyron) 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 ( TERRITORY_DATASETS['county']['comptes_c'], TERRITORY_DATASETS['county']['zonages_c']): self.assertIn( 'License: {title}'.format(title=licence_ouverte.title), data['html']) self.assertIn( '© {license_id}'.format(license_id=licence_ouverte.id), data['html']) self.assertIn( '<a data-tooltip="Source" href="http://localhost/datasets', data['html'])
def test_oembed_region_territory_api_get(self): '''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 = 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 ( TERRITORY_DATASETS['region']['comptes_reg'], TERRITORY_DATASETS['region']['zonages_reg']): self.assertIn( 'License: {title}'.format(title=licence_ouverte.title), data['html']) self.assertIn( '© {license_id}'.format(license_id=licence_ouverte.id), data['html']) self.assertIn( '<a data-tooltip="Source" href="http://localhost/datasets', data['html'])
def test_oembed_town_territory_api_get(self, api): '''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 = 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 localhost' in html assert 'Add to your own website' in 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 assert 'License: {title}'.format(title=license.title) in html assert '© {license_id}'.format(license_id=license.id) in html assert ( '<a data-tooltip="Source" href="http://localhost/datasets' in html)
def test_oembed_region_territory_api_get(self): '''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 = 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 ( TERRITORY_DATASETS['region']['comptes_reg'], TERRITORY_DATASETS['region']['zonages_reg']): self.assertIn( 'License: {title}'.format(title=licence_ouverte.title), data['html']) self.assertIn( '© {license_id}'.format(license_id=licence_ouverte.id), data['html']) self.assertIn( '<a data-tooltip="Source" href="http://localhost/datasets', data['html'])
def test_excerpt_is_not_removed(self, app): with app.test_request_context('/'): assert_md_equal(md(EXCERPT_TOKEN), EXCERPT_TOKEN)
def test_excerpt_is_not_removed(self): with self.app.test_request_context('/'): self.assertEqual(md(EXCERPT_TOKEN).strip(), EXCERPT_TOKEN)