def test_occurrence(): occurrence1 = Occurrence(identifier='test-occurrence1', topic_identifier='test-topic1', resource_ref='http://example.com/resource.pdf', language=Language.DEU) # Instantiate and open topic store. store = TopicStore(username, password) store.open() # Persist occurrence to store. if not store.occurrence_exists(TOPIC_MAP_IDENTIFIER, 'test-occurrence1'): store.set_occurrence(TOPIC_MAP_IDENTIFIER, occurrence1) # Retrieve occurrence from store. occurrence2 = store.get_occurrence(TOPIC_MAP_IDENTIFIER, 'test-occurrence1', resolve_attributes=RetrievalOption.RESOLVE_ATTRIBUTES) store.close() assert occurrence2.identifier == 'test-occurrence1' assert occurrence2.topic_identifier == 'test-topic1' assert occurrence2.instance_of == 'occurrence' assert occurrence2.scope == '*' # Universal scope. assert occurrence2.resource_ref == 'http://example.com/resource.pdf' assert occurrence2.resource_data is None assert occurrence2.language is Language.DEU assert len(occurrence2.attributes) == 1
def test_occurrence_resource_data(): resource_data = '<p>This is some text with a <a href="https://www.google.com">test</a> link.</p>' occurrence1 = Occurrence(identifier='test-occurrence2', topic_identifier='test-topic1', resource_data=resource_data) # Instantiate and open topic store. store = TopicStore(username, password) store.open() # Persist occurrence to store. if not store.occurrence_exists(TOPIC_MAP_IDENTIFIER, 'test-occurrence2'): store.set_occurrence(TOPIC_MAP_IDENTIFIER, occurrence1) # Retrieve occurrence from store. occurrence2 = store.get_occurrence(TOPIC_MAP_IDENTIFIER, 'test-occurrence2', resolve_attributes=RetrievalOption.RESOLVE_ATTRIBUTES, inline_resource_data=RetrievalOption.INLINE_RESOURCE_DATA) store.close() # Converting the resource data from bytes to string. assert occurrence2.resource_data.decode("utf-8") == '<p>This is some text with a <a href="https://www.google.com">test</a> link.</p>'