org_repo = OrganizationRepository(nar_client) org_repo.create(naro) # List all organisation : new organization should be listed there kg_organizations = org_repo.list() [print(x) for x in kg_organizations.results] # # 3. Create a new domain and list it. (test_schema) # from pyxus.resources.repository import DomainRepository from pyxus.resources.entity import Domain naro_tests = Domain.create_new(organisation_name, domain_name, "Test schemas") # create Domain on naro domain_repo = DomainRepository(nar_client) domain_repo.create(naro_tests) # List all domain in naro : new organization should be listed there naro_domains = domain_repo.list() [str(x) for x in naro_domains.results] # # 4. Upload schema and read it. ('foaf_sh_schema') # host_schema = "http://" + host_url + "/v0/schemas/" + fpath test_schema = { "@id": host_schema, "@type": "owl:Ontology",
class TestDomainRepository(TestCase): default_prefix = "hbp" @staticmethod def _assert_valid_default_entity(result, identifier="hbp/core"): assert_that(result, instance_of(Domain)) assert_that(result.data, not_none()) assert_that(result.get_revision(), greater_than(0)) assert_that(result.id, equal_to(identifier)) assert_that(result.path, equal_to("/domains/" + identifier)) @staticmethod def _assert_valid_search_list_result(search, expected_length=None): assert_that(search, not_none()) assert_that(search, instance_of(SearchResultList)) assert_that(search.results, not_none()) if expected_length is not None: assert_that(len(search.results), expected_length) def setUp(self): logging.basicConfig(level=logging.DEBUG) self.repository = DomainRepository(NexusClient()._http_client) def test_read_latest_revision(self): result = self.repository.read(self.default_prefix, "core") self._assert_valid_default_entity(result) def test_read_revision_one(self): result = self.repository.read(self.default_prefix, "core", 1) self._assert_valid_default_entity(result) assert_that(result.get_revision(), equal_to(1)) def test_read_unknown(self): result = self.repository.read("acme_corp", "core") assert_that(result, none()) # ATTENTION: This test creates entities with random names. The execution of the test therefore increases data volume def test_create_and_deprecate(self): random_name = "{}".format(uuid.uuid4()).replace("-", "") entity = Domain.create_new(self.default_prefix, random_name, "Test driven creation of a domain") result = self.repository.create(entity) assert_that(result, equal_to(entity)) self._assert_valid_default_entity( result, self.default_prefix + "/" + random_name) assert_that(result.get_revision(), equal_to(1)) self._test_deprecate(entity) def _test_deprecate(self, entity): # deprecate organization result = self.repository.delete(entity) self._assert_valid_default_entity(result, entity.id) assert_that(result.get_revision(), equal_to(2)) def test_update(self): entity = self.repository.read(self.default_prefix, "core") initial_description = entity.get_data("description") entity.data["description"] = "New description" entity = self.repository.update(entity) assert_that(entity.get_data("description"), is_not(equal_to(initial_description))) entity.data["description"] = initial_description self.repository.update(entity) def test_search_fulltext(self): search = self.repository.list(full_text_query="Domain") self._assert_valid_search_list_result(search, 1) def test_search_limit(self): search = self.repository.list(size=1) self._assert_valid_search_list_result(search, 1) assert_that(len(search.results), less_than(search.total)) def test_list_default(self): search = self.repository.list() self._assert_valid_search_list_result(search) assert_that(len(search.results), greater_than(0)) def test_list_incl_deprecated(self): search = self.repository.list(deprecated=None) self._assert_valid_search_list_result(search) assert_that(len(search.results), greater_than(0)) def test_list_and_resolve_first(self): search = self.repository.list() self._assert_valid_search_list_result(search) assert_that(len(search.results), greater_than(0)) result = self.repository.resolve(search.results[0]) self._assert_valid_default_entity(result, result.id) def test_list_and_resolve_all(self): search = self.repository.list() self._assert_valid_search_list_result(search) assert_that(len(search.results), greater_than(0)) result = self.repository.resolve_all(search) assert_that(result, not_none()) assert_that(result, instance_of(list)) assert_that(len(result), greater_than(0)) self._assert_valid_default_entity(result[0], result[0].id)