def test_oembeds_api_for_territory(self): '''It should fetch a territory in the oembed format.''' country = faker.country_code() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level), validity={ 'start': '1942-01-01', 'end': '9999-12-31' }) TestDataset = territory_dataset_factory() TERRITORY_DATASETS[level][TestDataset.id] = TestDataset reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id) url = url_for('api.oembeds', references=reference) response = self.get(url) 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(zone.name, data['html']) self.assertIn('placeholders/default.png', data['html'])
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.'
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.'
def test_oembeds_api_for_territory_level_not_registered(self): '''Should raise 400 on unregistered territory level''' country = faker.country_code().lower() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level)) TestDataset = territory_dataset_factory() del TERRITORY_DATASETS[level] reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id) url = url_for('api.oembeds', references=reference) response = self.get(url) self.assert400(response) self.assertEqual(response.json['message'], 'Unknown kind of territory.')
def test_oembeds_api_for_territory_dataset_not_registered(self): '''Should raise 400 on unregistered territory dataset''' country = faker.country_code() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level), validity={ 'start': '1942-01-01', 'end': '9999-12-31' }) TestDataset = territory_dataset_factory() TERRITORY_DATASETS[level] = {} reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id) url = url_for('api.oembeds', references=reference) response = self.get(url) self.assert400(response) self.assertEqual(response.json['message'], 'Unknown territory dataset id.')
def test_oembeds_api_for_territory(self, api): '''It should fetch a territory in the oembed format.''' country = faker.country_code().lower() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level)) TestDataset = territory_dataset_factory() TERRITORY_DATASETS[level][TestDataset.id] = TestDataset reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id) url = url_for('api.oembeds', references=reference) response = api.get(url) assert200(response) data = response.json[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' assert zone.name in data['html'] assert 'placeholders/default.png' in data['html']
def test_oembeds_api_for_territory(self, api): '''It should fetch a territory in the oembed format.''' country = faker.country_code().lower() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level)) TestDataset = territory_dataset_factory() TERRITORY_DATASETS[level][TestDataset.id] = TestDataset reference = 'territory-{0}:{1}'.format(zone.id, TestDataset.id) url = url_for('api.oembeds', references=reference) response = api.get(url) assert200(response) data = response.json[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' assert zone.name in data['html'] assert 'placeholders/default.png' in data['html']
def test_oembeds_api_for_territory_resolve_geoid(self): '''It should fetch a territory from a geoid in the oembed format.''' country = faker.country_code().lower() level = 'commune' zone = GeoZoneFactory(level='{0}:{1}'.format(country, level)) TestDataset = territory_dataset_factory() TERRITORY_DATASETS[level][TestDataset.id] = TestDataset geoid = '{0.level}:{0.code}@latest'.format(zone) reference = 'territory-{0}:{1}'.format(geoid, TestDataset.id) url = url_for('api.oembeds', references=reference) response = self.get(url) 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(zone.name, data['html']) self.assertIn('placeholders/default.png', data['html'])