def test_reuse_metric(self, app):
        site = SiteFactory.create(id=app.config['SITE_ID'])
        VisibleReuseFactory.create_batch(4)

        site.count_reuses()

        assert site.get_metrics()['reuses'] == 4
Exemple #2
0
    def test_minimal(self):
        site = SiteFactory()
        home_url = url_for('site.home_redirect', _external=True)
        uri = url_for('site.rdf_catalog', _external=True)
        datasets = VisibleDatasetFactory.create_batch(3)
        catalog = build_catalog(site, datasets)
        graph = catalog.graph

        self.assertIsInstance(catalog, Resource)
        catalogs = graph.subjects(RDF.type, DCAT.Catalog)
        self.assertEqual(len(list(catalogs)), 1)

        self.assertEqual(catalog.value(RDF.type).identifier, DCAT.Catalog)

        self.assertIsInstance(catalog.identifier, URIRef)
        self.assertEqual(str(catalog.identifier), uri)
        self.assertEqual(catalog.value(DCT.title), Literal(site.title))
        self.assertEqual(catalog.value(DCT.language),
                         Literal(self.app.config['DEFAULT_LANGUAGE']))

        self.assertEqual(len(list(catalog.objects(DCAT.dataset))),
                         len(datasets))

        self.assertEqual(
            catalog.value(FOAF.homepage).identifier, URIRef(home_url))

        org = catalog.value(DCT.publisher)
        self.assertEqual(org.value(RDF.type).identifier, FOAF.Organization)
        self.assertEqual(org.value(FOAF.name),
                         Literal(current_app.config['SITE_AUTHOR']))

        graph = catalog.graph
        self.assertEqual(len(list(graph.subjects(RDF.type, DCAT.Dataset))),
                         len(datasets))
    def test_orga_metric(self, app):
        site = SiteFactory.create(id=app.config['SITE_ID'])
        OrganizationFactory.create_batch(3)

        site.count_org()

        assert site.get_metrics()['organizations'] == 3
Exemple #4
0
    def test_minimal(self, app):
        site = SiteFactory()
        home_url = url_for('site.home_redirect', _external=True)
        uri = url_for('site.rdf_catalog', _external=True)
        datasets = VisibleDatasetFactory.create_batch(3)
        catalog = build_catalog(site, datasets)
        graph = catalog.graph

        assert isinstance(catalog, Resource)
        catalogs = graph.subjects(RDF.type, DCAT.Catalog)
        assert len(list(catalogs)) == 1

        assert catalog.value(RDF.type).identifier == DCAT.Catalog

        assert isinstance(catalog.identifier, URIRef)
        assert str(catalog.identifier) == uri
        assert catalog.value(DCT.title) == Literal(site.title)
        lang = app.config['DEFAULT_LANGUAGE']
        assert catalog.value(DCT.language) == Literal(lang)

        assert len(list(catalog.objects(DCAT.dataset))) == len(datasets)

        assert catalog.value(FOAF.homepage).identifier == URIRef(home_url)

        org = catalog.value(DCT.publisher)
        assert org.value(RDF.type).identifier == FOAF.Organization
        assert org.value(FOAF.name) == Literal(app.config['SITE_AUTHOR'])

        graph = catalog.graph
        graph_datasets = graph.subjects(RDF.type, DCAT.Dataset)
        assert len(list(graph_datasets)) == len(datasets)
Exemple #5
0
    def test_pagination(self):
        site = SiteFactory()
        page_size = 3
        total = 4
        uri = url_for('api.site_rdf_catalog', _external=True)
        uri_first = url_for('api.site_rdf_catalog_format', format='json',
                            page=1, page_size=page_size, _external=True)
        uri_last = url_for('api.site_rdf_catalog_format', format='json',
                           page=2, page_size=page_size, _external=True)
        VisibleDatasetFactory.create_batch(total)

        # First page
        datasets = Dataset.objects.paginate(1, page_size)
        catalog = build_catalog(site, datasets, format='json')
        graph = catalog.graph

        assert isinstance(catalog, Resource)
        assert catalog.identifier == URIRef(uri)
        types = [o.identifier for o in catalog.objects(RDF.type)]
        assert DCAT.Catalog in types
        assert HYDRA.Collection in types

        assert catalog.value(HYDRA.totalItems) == Literal(total)

        assert len(list(catalog.objects(DCAT.dataset))) == page_size

        paginations = list(graph.subjects(RDF.type,
                                          HYDRA.PartialCollectionView))
        assert len(paginations) == 1
        pagination = graph.resource(paginations[0])
        assert pagination.identifier == URIRef(uri_first)
        assert pagination.value(HYDRA.first).identifier == URIRef(uri_first)
        assert pagination.value(HYDRA.next).identifier == URIRef(uri_last)
        assert pagination.value(HYDRA.last).identifier == URIRef(uri_last)
        assert HYDRA.previous not in pagination

        # Second page
        datasets = Dataset.objects.paginate(2, page_size)
        catalog = build_catalog(site, datasets, format='json')
        graph = catalog.graph

        assert isinstance(catalog, Resource)
        assert catalog.identifier == URIRef(uri)
        types = [o.identifier for o in catalog.objects(RDF.type)]
        assert DCAT.Catalog in types
        assert HYDRA.Collection in types

        assert catalog.value(HYDRA.totalItems) == Literal(total)

        assert len(list(catalog.objects(DCAT.dataset))) == 1

        paginations = list(graph.subjects(RDF.type,
                                          HYDRA.PartialCollectionView))
        assert len(paginations) == 1
        pagination = graph.resource(paginations[0])
        assert pagination.identifier == URIRef(uri_last)
        assert pagination.value(HYDRA.first).identifier == URIRef(uri_first)
        assert pagination.value(HYDRA.previous).identifier == URIRef(uri_first)
        assert pagination.value(HYDRA.last).identifier == URIRef(uri_last)
        assert HYDRA.next not in pagination
    def test_dataset_metric(self, app):
        site = SiteFactory.create(id=app.config['SITE_ID'])
        DatasetFactory.create_batch(2)
        VisibleDatasetFactory.create_batch(3)

        site.count_datasets()

        assert site.get_metrics()['datasets'] == 3
    def test_resources_metric(self, app):
        site = SiteFactory.create(id=app.config['SITE_ID'])

        DatasetFactory.create_batch(3, nb_resources=3)

        site.count_datasets()
        site.count_resources()

        assert site.get_metrics()['resources'] == 9
Exemple #8
0
    def test_get_home_reuses(self):
        site = SiteFactory.create(
            id=self.app.config['SITE_ID'],
            settings__home_reuses=VisibleReuseFactory.create_batch(3))
        current_site.reload()

        self.login(AdminFactory())
        response = self.get(url_for('api.home_reuses'))
        self.assert200(response)

        self.assertEqual(len(response.json), len(site.settings.home_reuses))
    def test_badges_metric(self, app):
        site = SiteFactory.create(id=app.config['SITE_ID'])

        ps_badge = Badge(kind=PUBLIC_SERVICE)
        public_services = [
            OrganizationFactory(badges=[ps_badge]) for _ in range(2)
        ]
        for _ in range(3):
            OrganizationFactory()

        site.count_org_for_badge(PUBLIC_SERVICE)

        assert site.get_metrics()[PUBLIC_SERVICE] == len(public_services)
Exemple #10
0
    def test_no_duplicate(self):
        site = SiteFactory()
        org = OrganizationFactory()
        user = UserFactory()
        datasets = VisibleDatasetFactory.create_batch(2, owner=user)
        datasets += VisibleDatasetFactory.create_batch(2, organization=org)
        catalog = build_catalog(site, datasets)
        graph = catalog.graph

        orgs = list(graph.subjects(RDF.type, FOAF.Organization))
        self.assertEqual(len(orgs), 1 + 1)  # There is the site publisher
        users = list(graph.subjects(RDF.type, FOAF.Person))
        self.assertEqual(len(users), 1)
        org_names = list(graph.objects(orgs[0], FOAF.name))
        self.assertEqual(len(org_names), 1)
        user_names = list(graph.objects(users[0], FOAF.name))
        self.assertEqual(len(user_names), 1)
Exemple #11
0
    def test_pagination(self):
        site = SiteFactory()
        page_size = 3
        total = 4
        uri = url_for('site.rdf_catalog', _external=True)
        uri_first = url_for('site.rdf_catalog_format',
                            format='json',
                            page=1,
                            page_size=page_size,
                            _external=True)
        uri_last = url_for('site.rdf_catalog_format',
                           format='json',
                           page=2,
                           page_size=page_size,
                           _external=True)
        VisibleDatasetFactory.create_batch(total)

        # First page
        datasets = Dataset.objects.paginate(1, page_size)
        catalog = build_catalog(site, datasets, format='json')
        graph = catalog.graph

        self.assertIsInstance(catalog, Resource)
        self.assertEqual(catalog.identifier, URIRef(uri))
        types = [o.identifier for o in catalog.objects(RDF.type)]
        self.assertIn(DCAT.Catalog, types)
        self.assertIn(HYDRA.Collection, types)

        self.assertEqual(catalog.value(HYDRA.totalItems), Literal(total))

        self.assertEqual(len(list(catalog.objects(DCAT.dataset))), page_size)

        paginations = list(
            graph.subjects(RDF.type, HYDRA.PartialCollectionView))
        self.assertEqual(len(paginations), 1)
        pagination = graph.resource(paginations[0])
        self.assertEqual(pagination.identifier, URIRef(uri_first))
        self.assertEqual(
            pagination.value(HYDRA.first).identifier, URIRef(uri_first))
        self.assertEqual(
            pagination.value(HYDRA.next).identifier, URIRef(uri_last))
        self.assertEqual(
            pagination.value(HYDRA.last).identifier, URIRef(uri_last))
        self.assertNotIn(HYDRA.previous, pagination)

        # Second page
        datasets = Dataset.objects.paginate(2, page_size)
        catalog = build_catalog(site, datasets, format='json')
        graph = catalog.graph

        self.assertIsInstance(catalog, Resource)
        self.assertEqual(catalog.identifier, URIRef(uri))
        types = [o.identifier for o in catalog.objects(RDF.type)]
        self.assertIn(DCAT.Catalog, types)
        self.assertIn(HYDRA.Collection, types)

        self.assertEqual(catalog.value(HYDRA.totalItems), Literal(total))

        self.assertEqual(len(list(catalog.objects(DCAT.dataset))), 1)

        paginations = list(
            graph.subjects(RDF.type, HYDRA.PartialCollectionView))
        self.assertEqual(len(paginations), 1)
        pagination = graph.resource(paginations[0])
        self.assertEqual(pagination.identifier, URIRef(uri_last))
        self.assertEqual(
            pagination.value(HYDRA.first).identifier, URIRef(uri_first))
        self.assertEqual(
            pagination.value(HYDRA.previous).identifier, URIRef(uri_first))
        self.assertEqual(
            pagination.value(HYDRA.last).identifier, URIRef(uri_last))
        self.assertNotIn(HYDRA.next, pagination)