Exemplo n.º 1
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
Exemplo n.º 2
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

        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
Exemplo n.º 3
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))
Exemplo n.º 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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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))
        assert len(orgs) == 1 + 1  # There is the site publisher
        users = list(graph.subjects(RDF.type, FOAF.Person))
        assert len(users) == 1
        org_names = list(graph.objects(orgs[0], FOAF.name))
        assert len(org_names) == 1
        user_names = list(graph.objects(users[0], FOAF.name))
        assert len(user_names) == 1
Exemplo n.º 8
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)