Example #1
0
    def test_suggest_datasets_acronym_api(self):
        '''It should suggest datasets from their acronyms'''
        with self.autoindex():
            for i in range(4):
                DatasetFactory(
                    # Ensure title does not contains 'tes'
                    title=faker.unique_string(),
                    acronym='test-{0}'.format(i) if i % 2 else None,
                    visible=True)

        response = self.get(url_for('api.suggest_datasets'),
                            qs={
                                'q': 'tes',
                                'size': '5'
                            })
        self.assert200(response)

        self.assertLessEqual(len(response.json), 5)
        self.assertGreater(len(response.json), 1)

        for suggestion in response.json:
            self.assertIn('id', suggestion)
            self.assertIn('title', suggestion)
            self.assertIn('slug', suggestion)
            self.assertIn('score', suggestion)
            self.assertIn('image_url', suggestion)
            self.assertNotIn('tes', suggestion['title'])
            self.assertTrue(suggestion['acronym'].startswith('test'))
Example #2
0
class ReuseFactory(ModelFactory):
    class Meta:
        model = Reuse

    title = factory.Faker('sentence')
    description = factory.Faker('text')
    url = factory.LazyAttribute(
        lambda o: '/'.join([faker.url(), faker.unique_string()]))
    type = FuzzyChoice(REUSE_TYPES.keys())
def package_factory(ckan, **kwargs):
    data = {
        'name': faker.unique_string(),
        'title': faker.sentence(),
        'notes': faker.paragraph(),
        'resources': [{
            'url': faker.unique_url()
        }],
    }
    data.update(kwargs)
    response = ckan.action('package_create', data)
    return response['result']
Example #4
0
class ReuseFactory(ModelFactory):
    class Meta:
        model = Reuse

    title = factory.Faker('sentence')
    description = factory.Faker('text')
    url = factory.LazyAttribute(
        lambda o: '/'.join([faker.url(), faker.unique_string()]))
    type = FuzzyChoice(REUSE_TYPES.keys())
    topic = FuzzyChoice(REUSE_TOPICS.keys())

    class Params:
        visible = factory.Trait(
            datasets=factory.LazyAttribute(lambda o: [DatasetFactory()]))
Example #5
0
    def test_resolve_zones_from_json_failure(self):
        Fake, FakeForm = self.factory()
        GeoZoneFactory.create_batch(3)
        form = FakeForm.from_json({
            'spatial': {
                'zones': [
                    '{0}:{0}@{0}'.format(faker.unique_string())
                    for _ in range(2)
                ],
                'granularity': faker.spatial_granularity()
            }
        })

        form.validate()

        self.assertIn('spatial', form.errors)
        self.assertEqual(len(form.errors['spatial']), 1)

        self.assertIn('zones', form.errors['spatial'])
        self.assertEqual(len(form.errors['spatial']['zones']), 1)
Example #6
0
    def test_resolve_zones_from_json_failure(self):
        Fake, FakeForm = self.factory()
        GeoZoneFactory.create_batch(3)
        form = FakeForm.from_json({
            'spatial': {
                'zones': [
                    '{0}:{0}@{0}'.format(faker.unique_string())
                    for _ in range(2)
                ],
                'granularity':
                faker.spatial_granularity()
            }
        })

        form.validate()

        self.assertIn('spatial', form.errors)
        self.assertEqual(len(form.errors['spatial']), 1)

        self.assertIn('zones', form.errors['spatial'])
        self.assertEqual(len(form.errors['spatial']['zones']), 1)
Example #7
0
 def unique_url(self):
     return '{0}?_={1}'.format(faker.uri(), faker.unique_string())