コード例 #1
0
    def test_annotation_page_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            page = AnnotationWriter.annotation_page_for(patron)

            # The patron doesn't have any annotations, so the page is empty.
            eq_(AnnotationWriter.JSONLD_CONTEXT, page['@context'])
            assert 'annotations' in page['id']
            eq_('AnnotationPage', page['type'])
            eq_(0, len(page['items']))

            # If we add an annotation, the page will have an item.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db, Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )

            page = AnnotationWriter.annotation_page_for(patron)

            eq_(1, len(page['items']))

            # But if the annotation is deleted, the page will be empty again.
            annotation.active = False

            page = AnnotationWriter.annotation_page_for(patron)

            eq_(0, len(page['items']))
コード例 #2
0
    def test_annotation_page_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            page = AnnotationWriter.annotation_page_for(patron)

            # The patron doesn't have any annotations, so the page is empty.
            eq_(AnnotationWriter.JSONLD_CONTEXT, page['@context'])
            assert 'annotations' in page['id']
            eq_('AnnotationPage', page['type'])
            eq_(0, len(page['items']))

            # If we add an annotation, the page will have an item.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db, Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )

            page = AnnotationWriter.annotation_page_for(patron)

            eq_(1, len(page['items']))

            # But if the annotation is deleted, the page will be empty again.
            annotation.active = False

            page = AnnotationWriter.annotation_page_for(patron)

            eq_(0, len(page['items']))
コード例 #3
0
    def test_annotation_page_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            page = AnnotationWriter.annotation_page_for(patron)

            # The patron doesn't have any annotations, so the page is empty.
            assert AnnotationWriter.JSONLD_CONTEXT == page["@context"]
            assert "annotations" in page["id"]
            assert "AnnotationPage" == page["type"]
            assert 0 == len(page["items"])

            # If we add an annotation, the page will have an item.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db,
                Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )

            page = AnnotationWriter.annotation_page_for(patron)

            assert 1 == len(page["items"])

            # But if the annotation is deleted, the page will be empty again.
            annotation.active = False

            page = AnnotationWriter.annotation_page_for(patron)

            assert 0 == len(page["items"])
コード例 #4
0
    def test_detail_body(self):
        patron = self._patron()
        identifier = self._identifier()
        body = {
            "@type": "http://www.w3.org/ns/oa#TextualBody",
            "http://www.w3.org/ns/oa#bodyValue": "A good description of the topic that bears further investigation",
            "http://www.w3.org/ns/oa#hasPurpose": {
                "@id": "http://www.w3.org/ns/oa#describing"
            }
        }

        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
            content=json.dumps(body),
        )

        with self.app.test_request_context("/"):
            detail = AnnotationWriter.detail(annotation)

            assert "annotations/%i" % annotation.id in detail["id"]
            eq_("Annotation", detail['type'])
            eq_(Annotation.IDLING, detail['motivation'])
            compacted_body = {
                "type": "TextualBody",
                "bodyValue": "A good description of the topic that bears further investigation",
                "purpose": "describing"
            }
            eq_(compacted_body, detail["body"])
コード例 #5
0
    def test_detail_target(self):
        patron = self._patron()
        identifier = self._identifier()
        target = {
            "http://www.w3.org/ns/oa#hasSource": {
                "@id": identifier.urn
            },
            "http://www.w3.org/ns/oa#hasSelector": {
                "@type": "http://www.w3.org/ns/oa#FragmentSelector",
                "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)"
            }
        }

        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
            target=json.dumps(target),
        )

        with self.app.test_request_context("/"):
            detail = AnnotationWriter.detail(annotation)

            assert "annotations/%i" % annotation.id in detail["id"]
            eq_("Annotation", detail['type'])
            eq_(Annotation.IDLING, detail['motivation'])
            compacted_target = {
                "source": identifier.urn,
                "selector": {
                    "type": "FragmentSelector",
                    "value": "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)"
                }
            }
            eq_(compacted_target, detail["target"])
コード例 #6
0
    def test_detail_body(self):
        patron = self._patron()
        identifier = self._identifier()
        body = {
            "@type": "http://www.w3.org/ns/oa#TextualBody",
            "http://www.w3.org/ns/oa#bodyValue": "A good description of the topic that bears further investigation",
            "http://www.w3.org/ns/oa#hasPurpose": {
                "@id": "http://www.w3.org/ns/oa#describing"
            }
        }

        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
            content=json.dumps(body),
        )

        with self.app.test_request_context("/"):
            detail = AnnotationWriter.detail(annotation)

            assert "annotations/%i" % annotation.id in detail["id"]
            eq_("Annotation", detail['type'])
            eq_(Annotation.IDLING, detail['motivation'])
            compacted_body = {
                "type": "TextualBody",
                "bodyValue": "A good description of the topic that bears further investigation",
                "purpose": "describing"
            }
            eq_(compacted_body, detail["body"])
コード例 #7
0
    def test_detail_target(self):
        patron = self._patron()
        identifier = self._identifier()
        target = {
            "http://www.w3.org/ns/oa#hasSource": {
                "@id": identifier.urn
            },
            "http://www.w3.org/ns/oa#hasSelector": {
                "@type": "http://www.w3.org/ns/oa#FragmentSelector",
                "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)"
            }
        }

        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
            target=json.dumps(target),
        )

        with self.app.test_request_context("/"):
            detail = AnnotationWriter.detail(annotation)

            assert "annotations/%i" % annotation.id in detail["id"]
            eq_("Annotation", detail['type'])
            eq_(Annotation.IDLING, detail['motivation'])
            compacted_target = {
                "source": identifier.urn,
                "selector": {
                    "type": "FragmentSelector",
                    "value": "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)"
                }
            }
            eq_(compacted_target, detail["target"])
コード例 #8
0
    def test_annotations_for(self):
        patron = self._patron()

        # The patron doesn't have any annotations yet.
        eq_([], AnnotationWriter.annotations_for(patron))

        identifier = self._identifier()
        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
        )

        # The patron has one annotation.
        eq_([annotation], AnnotationWriter.annotations_for(patron))
        eq_([annotation], AnnotationWriter.annotations_for(patron, identifier))

        identifier2 = self._identifier()
        annotation2, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier2,
            motivation=Annotation.IDLING,
        )

        # The patron has two annotations for different identifiers.
        eq_(set([annotation, annotation2]), set(AnnotationWriter.annotations_for(patron)))
        eq_([annotation], AnnotationWriter.annotations_for(patron, identifier))
        eq_([annotation2], AnnotationWriter.annotations_for(patron, identifier2))
コード例 #9
0
    def test_annotations_for(self):
        patron = self._patron()

        # The patron doesn't have any annotations yet.
        eq_([], AnnotationWriter.annotations_for(patron))

        identifier = self._identifier()
        annotation, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
        )

        # The patron has one annotation.
        eq_([annotation], AnnotationWriter.annotations_for(patron))
        eq_([annotation], AnnotationWriter.annotations_for(patron, identifier))

        identifier2 = self._identifier()
        annotation2, ignore = create(
            self._db, Annotation,
            patron=patron,
            identifier=identifier2,
            motivation=Annotation.IDLING,
        )

        # The patron has two annotations for different identifiers.
        eq_(set([annotation, annotation2]), set(AnnotationWriter.annotations_for(patron)))
        eq_([annotation], AnnotationWriter.annotations_for(patron, identifier))
        eq_([annotation2], AnnotationWriter.annotations_for(patron, identifier2))
コード例 #10
0
    def test_annotations_for(self):
        patron = self._patron()

        # The patron doesn't have any annotations yet.
        assert [] == AnnotationWriter.annotations_for(patron)

        identifier = self._identifier()
        annotation, ignore = create(
            self._db,
            Annotation,
            patron=patron,
            identifier=identifier,
            motivation=Annotation.IDLING,
        )

        # The patron has one annotation.
        assert [annotation] == AnnotationWriter.annotations_for(patron)
        assert [annotation
                ] == AnnotationWriter.annotations_for(patron, identifier)

        identifier2 = self._identifier()
        annotation2, ignore = create(
            self._db,
            Annotation,
            patron=patron,
            identifier=identifier2,
            motivation=Annotation.IDLING,
        )

        # The patron has two annotations for different identifiers.
        assert set([annotation, annotation2
                    ]) == set(AnnotationWriter.annotations_for(patron))
        assert [annotation
                ] == AnnotationWriter.annotations_for(patron, identifier)
        assert [annotation2
                ] == AnnotationWriter.annotations_for(patron, identifier2)
コード例 #11
0
    def test_annotation_container_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            container, timestamp = AnnotationWriter.annotation_container_for(patron)

            eq_(set([AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT]),
                set(container['@context']))
            assert "annotations" in container["id"]
            eq_(set(["BasicContainer", "AnnotationCollection"]), set(container["type"]))
            eq_(0, container["total"])

            first_page = container["first"]
            eq_("AnnotationPage", first_page["type"])

            # The page doesn't have a context, since it's in the container.
            eq_(None, first_page.get('@context'))

            # The patron doesn't have any annotations yet.
            eq_(0, container['total'])

            # There's no timestamp since the container is empty.
            eq_(None, timestamp)

            # Now, add an annotation.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db, Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )
            annotation.timestamp = datetime.datetime.now()

            container, timestamp = AnnotationWriter.annotation_container_for(patron)

            # The context, type, and id stay the same.
            eq_(set([AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT]),
                set(container['@context']))
            assert "annotations" in container["id"]
            assert identifier.identifier not in container["id"]
            eq_(set(["BasicContainer", "AnnotationCollection"]), set(container["type"]))

            # But now there is one item.
            eq_(1, container['total'])

            first_page = container["first"]

            eq_(1, len(first_page['items']))

            # The item doesn't have a context, since it's in the container.
            first_item = first_page['items'][0]
            eq_(None, first_item.get('@context'))

            # The timestamp is the annotation's timestamp.
            eq_(annotation.timestamp, timestamp)

            # If the annotation is deleted, the container will be empty again.
            annotation.active = False

            container, timestamp = AnnotationWriter.annotation_container_for(patron)
            eq_(0, container['total'])
            eq_(None, timestamp)
コード例 #12
0
    def test_annotation_container_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            container, timestamp = AnnotationWriter.annotation_container_for(patron)

            eq_(set([AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT]),
                set(container['@context']))
            assert "annotations" in container["id"]
            eq_(set(["BasicContainer", "AnnotationCollection"]), set(container["type"]))
            eq_(0, container["total"])

            first_page = container["first"]
            eq_("AnnotationPage", first_page["type"])

            # The page doesn't have a context, since it's in the container.
            eq_(None, first_page.get('@context'))

            # The patron doesn't have any annotations yet.
            eq_(0, container['total'])

            # There's no timestamp since the container is empty.
            eq_(None, timestamp)

            # Now, add an annotation.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db, Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )
            annotation.timestamp = datetime.datetime.now()

            container, timestamp = AnnotationWriter.annotation_container_for(patron)

            # The context, type, and id stay the same.
            eq_(set([AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT]),
                set(container['@context']))
            assert "annotations" in container["id"]
            assert identifier.identifier not in container["id"]
            eq_(set(["BasicContainer", "AnnotationCollection"]), set(container["type"]))

            # But now there is one item.
            eq_(1, container['total'])

            first_page = container["first"]

            eq_(1, len(first_page['items']))

            # The item doesn't have a context, since it's in the container.
            first_item = first_page['items'][0]
            eq_(None, first_item.get('@context'))

            # The timestamp is the annotation's timestamp.
            eq_(annotation.timestamp, timestamp)

            # If the annotation is deleted, the container will be empty again.
            annotation.active = False

            container, timestamp = AnnotationWriter.annotation_container_for(patron)
            eq_(0, container['total'])
            eq_(None, timestamp)
コード例 #13
0
    def test_annotation_container_for(self):
        patron = self._patron()

        with self.app.test_request_context("/"):
            container, timestamp = AnnotationWriter.annotation_container_for(
                patron)

            assert set([
                AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT
            ]) == set(container["@context"])
            assert "annotations" in container["id"]
            assert set(["BasicContainer",
                        "AnnotationCollection"]) == set(container["type"])
            assert 0 == container["total"]

            first_page = container["first"]
            assert "AnnotationPage" == first_page["type"]

            # The page doesn't have a context, since it's in the container.
            assert None == first_page.get("@context")

            # The patron doesn't have any annotations yet.
            assert 0 == container["total"]

            # There's no timestamp since the container is empty.
            assert None == timestamp

            # Now, add an annotation.
            identifier = self._identifier()
            annotation, ignore = create(
                self._db,
                Annotation,
                patron=patron,
                identifier=identifier,
                motivation=Annotation.IDLING,
            )
            annotation.timestamp = utc_now()

            container, timestamp = AnnotationWriter.annotation_container_for(
                patron)

            # The context, type, and id stay the same.
            assert set([
                AnnotationWriter.JSONLD_CONTEXT, AnnotationWriter.LDP_CONTEXT
            ]) == set(container["@context"])
            assert "annotations" in container["id"]
            assert identifier.identifier not in container["id"]
            assert set(["BasicContainer",
                        "AnnotationCollection"]) == set(container["type"])

            # But now there is one item.
            assert 1 == container["total"]

            first_page = container["first"]

            assert 1 == len(first_page["items"])

            # The item doesn't have a context, since it's in the container.
            first_item = first_page["items"][0]
            assert None == first_item.get("@context")

            # The timestamp is the annotation's timestamp.
            assert annotation.timestamp == timestamp

            # If the annotation is deleted, the container will be empty again.
            annotation.active = False

            container, timestamp = AnnotationWriter.annotation_container_for(
                patron)
            assert 0 == container["total"]
            assert None == timestamp