Example #1
0
    def test_custom_fields_are_preserved(self):
        ec = ElucidateClient(BASE_URI)
        container_name = 'custom_container_name4'

        container_id = ec.read_container_identifier(name=container_name)
        if not container_id:
            container_id = ec.create_container(label='This is the label',
                                               container_id=container_name)
        ic(container_id)
        expected_url = f"{BASE_URI}/{ec.version}/{container_name}/"
        self.assertEqual(expected_url, container_id.url)

        custom_context = {'custom_field': 'urn:custom_field'}
        annotation_id = ec.create_annotation(
            container_id=container_id,
            body={"custom_field": "custom_value"},
            target={},
            custom_contexts=custom_context)
        ic(annotation_id)

        annotation = ec.read_annotation(annotation_identifier=annotation_id)
        ic(annotation)
        self.assertEqual("custom_value",
                         annotation['body']['urn:custom_field'])

        ok = ec.delete_annotation(annotation_identifier=annotation_id)
        assert ok
Example #2
0
    def test_elucidate_client(self):
        ec = ElucidateClient(BASE_URI)
        container_id = ec.create_container(label='Annotation Container')
        assert container_id is not None
        ic(container_id)

        body = {"type": "TextualBody", "value": "I like this page!"}
        target = "http://www.example.com/index.html"
        annotation_id = ec.create_annotation(container_id=container_id,
                                             body=body,
                                             target=target,
                                             custom={"motivation": "tagging"})
        assert annotation_id is not None
        ic(annotation_id)

        annotation = ec.read_annotation(annotation_id)
        ic(annotation)

        new_body = {"type": "TextualBody", "value": "This page is massive!"}
        new_target = "http://www.example.com/index.html"
        updated_annotation_id = ec.update_annotation(annotation_id, new_body,
                                                     new_target)
        ic(updated_annotation_id)

        deleted = ec.delete_annotation(updated_annotation_id)
        assert deleted == True

        try:
            annotation = ec.read_annotation(updated_annotation_id)
            ic(annotation)
        except Exception as e:
            ic(e)

        self._assert_read_container(ec, container_id, '/w3c/')
        ec.use_oa()
        self._assert_read_container(ec, container_id, '/oa/')