Ejemplo n.º 1
0
 def test_search_by_target_generated_since(self):
     since = datetime.datetime(year=2000, month=1, day=1)
     ec = ElucidateClient(BASE_URI, raise_exceptions=False)
     response = (ec.search_by_target_generated_since(since))
     annotation_collection = get_result(response)
     self.assert_search_by_temporal_results(
         annotation_collection=annotation_collection,
         expected_levels='target',
         expected_types='generated',
         since=since)
Ejemplo n.º 2
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
Ejemplo n.º 3
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/')
Ejemplo n.º 4
0
    def test_statistics(self):
        ec = ElucidateClient(BASE_URI)
        stats = ec.get_body_id_statistics()
        assert stats['items'] is not None
        ic(stats['items'])

        stats = ec.get_body_source_statistics()
        assert stats['items'] is not None
        ic(stats['items'])

        stats = ec.get_target_id_statistics()
        assert stats['items'] is not None
        ic(stats['items'])

        stats = ec.get_target_source_statistics()
        assert stats['items'] is not None
        ic(stats['items'])
Ejemplo n.º 5
0
    def test_create_container_and_annotation_with_custom_names(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)

        annotation_name = "custom_annotation_name"
        annotation_id = ec.create_annotation(container_id=container_id,
                                             body={},
                                             target={},
                                             annotation_id=annotation_name)
        ic(annotation_id)
        expected_url = f"{BASE_URI}/{ec.version}/{container_name}/{annotation_name}"
        self.assertEqual(expected_url, annotation_id.url)

        ok = ec.delete_annotation(annotation_identifier=annotation_id)
        assert ok
Ejemplo n.º 6
0
 def test_group(self):
     ec = ElucidateClient(BASE_URI)
     group_id = ec.create_group("test_group")
     ic(group_id)
     assert isinstance(group_id, str)
     assert group_id is not None
Ejemplo n.º 7
0
 def test_read_current_user(self):
     ec = ElucidateClient(BASE_URI, raise_exceptions=False)
     response = ec.read_current_user()
     assert isinstance(response, ElucidateSuccess)
     ic(response.result)
Ejemplo n.º 8
0
 def test_search_by_target_source(self):
     ec = ElucidateClient(BASE_URI)
     annotation_collection = ec.search_by_target_source(
         'http://example.org')
     ic(annotation_collection)
     ic(annotation_collection.total)