Example #1
0
 def test_create_turtle_instance(self):
     organization = self.client.organizations.read("test")
     if organization is None:
         self.client.organizations.create(
             Organization.create_new("test", "An organization for tests"))
     domain = self.client.domains.read("test", "core")
     if domain is None:
         self.client.domains.create(
             Domain.create_new("test", "core", "A domain for tests"))
     schema = self.client.schemas.read("test", "core", "turtle", "v0.0.4")
     if schema is None:
         schema = self.client.schemas.create(
             Schema.create_new("test",
                               "core",
                               "turtle",
                               "v0.0.4",
                               self.test_turtle_schema,
                               is_turtle=True))
     if not schema.is_published():
         self.client.schemas.publish(schema, True)
     instance = self.client.instances.create(
         Instance.create_new("test",
                             "core",
                             "turtle",
                             "v0.0.4",
                             self.test_turtle_instance,
                             is_turtle=True))
     instance = self.client.instances.read(instance.get_organization(),
                                           instance.get_domain(),
                                           instance.get_schema(),
                                           instance.get_version(),
                                           instance.get_id())
     print instance
Example #2
0
    def _create_schema_or_context(self, text, repository, entity, data, force_domain_creation, update_if_already_exists, publish):
        try:
            schema_or_context = repository.read(data.organization, data.domain, data.name, data.version)
        except HTTPError as e:
            raise NexusException("Request for {} has failed: {}".format(text, e.message))

        if schema_or_context is None:
            # The schema or context does not exist yet - we create it
            if force_domain_creation:
                organization = self._client.organizations.read(data.organization)
                if organization is None:
                    self._client.organizations.create(Organization.create_new(data.organization, "Created by {} {}".format(text, data.name)))
                domain = self._client.domains.read(data.organization, data.domain)
                if domain is None:
                    self._client.domains.create(Domain.create_new(data.organization, data.domain, "Created by {} {}".format(text, data.name)))
            schema_or_context = repository.create(entity)
        elif update_if_already_exists:
            if schema_or_context.is_published():
                raise NexusException("Can not update the already published {} {}".format(text, data.name))
            schema_or_context = self._client.schemas.update(data.organization, data.domain, data.name, data.version,
                                                            data.content, schema_or_context.get_revision())
        data.revision = schema_or_context.get_revision()
        if publish and data.revision and not schema_or_context.is_published():
            repository.publish(schema_or_context, True, data.revision)
        return data
Example #3
0
 def create_domain(self) -> Optional[Domain]:
     if self.is_domain_pushed():
         self._print_already_pushed(self.domain)
         return None
     else:
         local = Domain.create_new(self.organization, self.domain,
                                   self.domain_desc)
         distant = self.client.domains.create(local)
         self._print_pushed(self.domain)
         return distant
Example #4
0
 def create_domain(self) -> Domain:
     domain = self.client.domains.read(self.organization, self.domain)
     if domain is not None:
         self._print_already_created(self.domain)
         return domain
     else:
         local = Domain.create_new(self.organization, self.domain, self.domain_desc)
         distant = self.client.domains.create(local)
         self._print_created(self.domain)
         return distant
Example #5
0
 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)
Example #6
0
 def create_domain(self) -> Domain:
     domain = self.client.domains.read(self.organization, self.domain)
     if domain is not None:
         self._print_already_created(self.domain)
         return domain
     else:
         local = Domain.create_new(self.organization, self.domain,
                                   self.domain_desc)
         distant = self.client.domains.create(local)
         self._print_created(self.domain)
         return distant
Example #7
0
naro = Organization.create_new(organisation_name,
                               "HBP Neural Activity Resource")
# create organization on KG
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":