Esempio n. 1
0
 def test_render_display(self):
     '''It should render the organization page'''
     organization = OrganizationFactory(
         description='* Title 1\n* Title 2', )
     url = url_for('organizations.show', org=organization)
     response = self.get(url)
     self.assert200(response)
     json_ld = self.get_json_ld(response)
     self.assertEquals(json_ld['@context'], 'http://schema.org')
     self.assertEquals(json_ld['@type'], 'Organization')
     self.assertEquals(json_ld['alternateName'], organization.slug)
     self.assertEquals(json_ld['url'], 'http://localhost{}'.format(url))
     self.assertEquals(json_ld['name'], organization.name)
     self.assertEquals(json_ld['description'], 'Title 1 Title 2')
Esempio n. 2
0
    def test_create_badge_certified_mail(self):
        member = Member(user=self.user, role='admin')
        org = OrganizationFactory(members=[member])

        data = self.factory.attributes()
        data['kind'] = CERTIFIED

        with self.capture_mails() as mails:
            self.post(url_for('api.organization_badges', org=org), data)

        # Should have sent one mail to each member of organization
        members_emails = [m.user.email for m in org.members]
        self.assertEqual(len(mails), len(members_emails))
        self.assertListEqual([m.recipients[0] for m in mails], members_emails)
Esempio n. 3
0
    def test_reuse_api_create_as_org(self):
        '''It should create a reuse as organization from the API'''
        self.login()
        data = ReuseFactory.as_dict()
        member = Member(user=self.user, role='editor')
        org = OrganizationFactory(members=[member])
        data['organization'] = str(org.id)
        response = self.post(url_for('api.reuses'), data)
        self.assert201(response)
        self.assertEqual(Reuse.objects.count(), 1)

        reuse = Reuse.objects.first()
        self.assertIsNone(reuse.owner)
        self.assertEqual(reuse.organization, org)
Esempio n. 4
0
    def test_hydra_partial_collection_view_pagination(self):
        url = mock_pagination('catalog.jsonld',
                              'partial-collection-{page}.jsonld')
        org = OrganizationFactory()
        source = HarvestSourceFactory(backend='dcat',
                                      url=url,
                                      organization=org)

        actions.run(source.slug)

        source.reload()

        job = source.get_last_job()
        self.assertEqual(len(job.items), 4)
Esempio n. 5
0
    def test_with_org(self):
        org = OrganizationFactory()
        dataset = DatasetFactory(organization=org)
        d = dataset_to_rdf(dataset)
        g = d.graph

        assert isinstance(d, RdfResource)
        datasets = g.subjects(RDF.type, DCAT.Dataset)
        organizations = g.subjects(RDF.type, FOAF.Organization)
        assert len(list(datasets)) == 1
        assert len(list(organizations)) == 1

        publisher = d.value(DCT.publisher)
        assert publisher.value(RDF.type).identifier == FOAF.Organization
Esempio n. 6
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)
Esempio n. 7
0
    def test_hydra_legacy_paged_collection_pagination(self, rmock):
        url = mock_pagination(rmock, 'catalog.jsonld',
                              'paged-collection-{page}.jsonld')
        org = OrganizationFactory()
        source = HarvestSourceFactory(backend='dcat',
                                      url=url,
                                      organization=org)

        actions.run(source.slug)

        source.reload()

        job = source.get_last_job()
        assert len(job.items) == 4
Esempio n. 8
0
def test_simple():
    org = OrganizationFactory()
    source = HarvestSourceFactory(backend='{{ cookiecutter.identifier }}',
                                  url=faker.url(),
                                  organization=org)

    # TODO: mock remote endpoints responses

    actions.run(source.slug)

    source.reload()

    job = source.get_last_job()
    assert len(job.items) > 0
Esempio n. 9
0
    def test_no_user_logged_in_permission(self):
        Ownable, OwnableForm = self.factory()
        member = Member(user=UserFactory(), role='editor')
        org = OrganizationFactory(members=[member])

        form = OwnableForm(MultiDict({
            'organization': str(org.id)
        }))

        self.assertEqual(form.organization.data, org)

        self.assertFalse(form.validate())
        self.assertIn('organization', form.errors)
        self.assertEqual(len(form.errors['organization']), 1)
Esempio n. 10
0
    def test_only_admin_can_create_member(self, api):
        user = api.login()
        added_user = UserFactory()
        organization = OrganizationFactory(members=[
            Member(user=user, role='editor'),
        ])

        api_url = url_for('api.member', org=organization, user=added_user)
        response = api.post(api_url, {'role': 'editor'})

        assert403(response)

        organization.reload()
        assert not organization.is_member(added_user)
Esempio n. 11
0
    def test_only_admin_can_accept_membership(self, api):
        user = api.login()
        applicant = UserFactory()
        membership_request = MembershipRequest(user=applicant, comment='test')
        member = Member(user=user, role='editor')
        organization = OrganizationFactory(
            members=[member], requests=[membership_request])

        api_url = url_for(
            'api.accept_membership',
            org=organization,
            id=membership_request.id)
        response = api.post(api_url)
        assert403(response)
Esempio n. 12
0
    def test_create_source_with_org_not_member(self, api):
        '''It should create and attach a new source to an organization'''
        user = api.login()
        member = Member(user=user, role='editor')
        org = OrganizationFactory(members=[member])
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'organization': str(org.id)
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert403(response)
Esempio n. 13
0
    def test_create_badge_certified_mail(self, api):
        member = Member(user=self.user, role='admin')
        org = OrganizationFactory(members=[member])

        data = self.factory.as_dict()
        data['kind'] = CERTIFIED

        with capture_mails() as mails:
            api.post(url_for('api.organization_badges', org=org), data)

        # Should have sent one mail to each member of organization
        members_emails = [m.user.email for m in org.members]
        assert len(mails) == len(members_emails)
        assert [m.recipients[0] for m in mails] == members_emails
Esempio n. 14
0
    def test_render_home(self):
        '''It should render the home page'''
        for i in range(3):
            org = OrganizationFactory()
            DatasetFactory(organization=org)
            ReuseFactory(organization=org)

        current_site.settings.home_datasets = [
            DatasetFactory() for _ in range(3)
        ]
        current_site.settings.home_reuses = [ReuseFactory() for _ in range(3)]

        response = self.get(url_for('site.home'))
        self.assert200(response)
Esempio n. 15
0
    def test_owner_changed_from_org_to_user_with_owned_postsave_signal(self):
        # Test with an additionnal post save signal that will retriger save signals
        user = UserFactory()
        org = OrganizationFactory()

        owned = OwnedPostSave.objects.create(organization=org)

        with post_save.connected_to(OwnedPostSave.post_save,
                                    sender=OwnedPostSave):
            owned.owner = user
            owned.save()

        assert owned.owner == user
        assert owned.organization is None
Esempio n. 16
0
    def test_reuse_api_create_as_org(self, api):
        '''It should create a reuse as organization from the API'''
        user = api.login()
        data = ReuseFactory.as_dict()
        member = Member(user=user, role='editor')
        org = OrganizationFactory(members=[member])
        data['organization'] = str(org.id)
        response = api.post(url_for('api.reuses'), data)
        assert201(response)
        assert Reuse.objects.count() == 1

        reuse = Reuse.objects.first()
        assert reuse.owner is None
        assert reuse.organization == org
Esempio n. 17
0
    def test_delete_member(self):
        user = self.login()
        deleted_user = UserFactory()
        organization = OrganizationFactory(members=[
            Member(user=user, role='admin'),
            Member(user=deleted_user, role='editor')
        ])

        api_url = url_for('api.member', org=organization, user=deleted_user)
        response = self.delete(api_url)
        self.assert204(response)

        organization.reload()
        self.assertFalse(organization.is_member(deleted_user))
Esempio n. 18
0
    def test_only_admin_can_delete_member(self, api):
        user = api.login()
        deleted_user = UserFactory()
        organization = OrganizationFactory(members=[
            Member(user=user, role='editor'),
            Member(user=deleted_user, role='editor')
        ])

        api_url = url_for('api.member', org=organization, user=deleted_user)
        response = api.delete(api_url)
        assert403(response)

        organization.reload()
        assert organization.is_member(deleted_user)
Esempio n. 19
0
    def test_dataset_api_list_filtered_by_org(self):
        '''It should fetch a dataset list for a given org'''
        self.login()
        with self.autoindex():
            member = Member(user=self.user, role='editor')
            org = OrganizationFactory(members=[member])
            VisibleDatasetFactory()
            dataset_org = VisibleDatasetFactory(organization=org)

        response = self.get(url_for('api.datasets'),
                            qs={'organization': str(org.id)})
        self.assert200(response)
        self.assertEqual(len(response.json['data']), 1)
        self.assertEqual(response.json['data'][0]['id'], str(dataset_org.id))
Esempio n. 20
0
    def test_follow_org(self):
        '''It should follow an organization on POST'''
        user = self.login()
        to_follow = OrganizationFactory()

        response = self.post(
            url_for('api.organization_followers', id=to_follow.id))
        self.assert201(response)

        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(Follow.objects.followers(to_follow).count(), 1)
        follow = Follow.objects.followers(to_follow).first()
        self.assertIsInstance(follow.following, Organization)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)
Esempio n. 21
0
    def test_xml_catalog(self, rmock):
        LicenseFactory(id='lov2', title='Licence Ouverte Version 2.0')

        url = mock_dcat(rmock, 'catalog.xml', path='catalog.xml')
        org = OrganizationFactory()
        source = HarvestSourceFactory(backend='dcat',
                                      url=url,
                                      organization=org)

        actions.run(source.slug)

        # test dct:license support
        extras = {'extras__dct:identifier': '3'}
        dataset = Dataset.objects.get(**extras)
        assert dataset.license.id == 'lov2'
Esempio n. 22
0
    def test_my_org_datasets(self):
        user = self.login()
        member = Member(user=user, role='editor')
        organization = OrganizationFactory(members=[member])
        community_resources = [
            VisibleDatasetFactory(owner=user) for _ in range(2)
        ]
        org_datasets = [
            VisibleDatasetFactory(organization=organization) for _ in range(2)
        ]

        response = self.get(url_for('api.my_org_datasets'))
        self.assert200(response)
        self.assertEqual(len(response.json),
                         len(community_resources) + len(org_datasets))
Esempio n. 23
0
def generate_fixtures(datasets, reuses):
    '''Build sample fixture data (users, datasets and reuses).'''
    user = UserFactory()
    log.info('Generated user "{user.email}".'.format(user=user))

    organization = OrganizationFactory(members=[Member(user=user)])
    log.info('Generated organization "{org.name}".'.format(org=organization))

    for _ in range(datasets):
        dataset = VisibleDatasetFactory(organization=organization)
        DiscussionFactory(subject=dataset, user=user)
        ReuseFactory.create_batch(reuses, datasets=[dataset], owner=user)

    msg = 'Generated {datasets} dataset(s) with {reuses} reuse(s) each.'
    log.info(msg.format(**locals()))
Esempio n. 24
0
    def test_dataset_api_create_as_org(self):
        '''It should create a dataset as organization from the API'''
        self.login()
        data = DatasetFactory.attributes()
        member = Member(user=self.user, role='editor')
        org = OrganizationFactory(members=[member])
        data['organization'] = str(org.id)

        response = self.post(url_for('api.datasets'), data)
        self.assert201(response)
        self.assertEqual(Dataset.objects.count(), 1)

        dataset = Dataset.objects.first()
        self.assertEqual(dataset.organization, org)
        self.assertIsNone(dataset.owner)
Esempio n. 25
0
    def test_failure_on_initialize(self):
        url = DCAT_URL_PATTERN.format(path='', domain=TEST_DOMAIN)
        httpretty.register_uri(httpretty.GET, url, body='should fail')
        org = OrganizationFactory()
        source = HarvestSourceFactory(backend='dcat',
                                      url=url,
                                      organization=org)

        actions.run(source.slug)

        source.reload()

        job = source.get_last_job()

        self.assertEqual(job.status, 'failed')
Esempio n. 26
0
    def test_with_org(self):
        org = OrganizationFactory()
        dataset = DatasetFactory(organization=org)
        d = dataset_to_rdf(dataset)
        g = d.graph

        self.assertIsInstance(d, RdfResource)
        datasets = g.subjects(RDF.type, DCAT.Dataset)
        organizations = g.subjects(RDF.type, FOAF.Organization)
        self.assertEqual(len(list(datasets)), 1)
        self.assertEqual(len(list(organizations)), 1)

        publisher = d.value(DCT.publisher)
        self.assertEqual(publisher.value(RDF.type).identifier,
                         FOAF.Organization)
    def test_follow_org(self, api):
        '''It should follow an organization on POST'''
        user = api.login()
        to_follow = OrganizationFactory()

        url = url_for('api.organization_followers', id=to_follow.id)
        response = api.post(url)
        assert201(response)

        assert Follow.objects.following(to_follow).count() is 0
        assert Follow.objects.followers(to_follow).count() is 1
        follow = Follow.objects.followers(to_follow).first()
        assert isinstance(follow.following, Organization)
        assert Follow.objects.following(user).count() is 1
        assert Follow.objects.followers(user).count() is 0
Esempio n. 28
0
    def test_failure_on_initialize(self, rmock):
        url = DCAT_URL_PATTERN.format(path='', domain=TEST_DOMAIN)
        rmock.get(url, text='should fail')
        org = OrganizationFactory()
        source = HarvestSourceFactory(backend='dcat',
                                      url=url,
                                      organization=org)

        actions.run(source.slug)

        source.reload()

        job = source.get_last_job()

        assert job.status == 'failed'
Esempio n. 29
0
 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'])
Esempio n. 30
0
 def test_render_display(self):
     '''It should render the organization page'''
     organization = OrganizationFactory(
         description='* Title 1\n* Title 2', )
     url = url_for('organizations.show', org=organization)
     response = self.get(url)
     self.assert200(response)
     self.assertNotIn(b'<meta name="robots" content="noindex, nofollow">',
                      response.data)
     json_ld = self.get_json_ld(response)
     self.assertEqual(json_ld['@context'], 'http://schema.org')
     self.assertEqual(json_ld['@type'], 'Organization')
     self.assertEqual(json_ld['alternateName'], organization.slug)
     self.assertEqual(json_ld['url'], 'http://local.test{}'.format(url))
     self.assertEqual(json_ld['name'], organization.name)
     self.assertEqual(json_ld['description'], 'Title 1 Title 2')