Esempio n. 1
0
 def _put(self, id=random_string()):
     my_schema = """{
       "shapes": [
         {
           "@id": "this:MyShape",
           "@type": "sh:NodeShape",
           "nodeKind": "sh:BlankNodeOrIRI",
           "targetClass": "ex:Custom",
           "property": [
             {
               "path": "ex:name",
               "datatype": "xsd:string",
               "minCount": 1
             },
             {
               "path": "ex:number",
               "datatype": "xsd:integer",
               "minCount": 1
             },
             {
               "path": "ex:bool",
               "datatype": "xsd:boolean",
               "minCount": 1
             }
           ]
         }
       ]
     }"""
     payload = self.nexus.schemas.create(self.org, self.prj, my_schema, schema_id=id)
     pretty_print(payload)
     payload = self.nexus.schemas.fetch(self.org, self.prj, id)
     self.assertEqual(len(payload["shapes"]), 1)
Esempio n. 2
0
 def test_es_query(self):
     resource = self.nexus.resources.create(self.org, self.prj, {
         "firstname": "Johnny",
         "lastname": "Bravo"
     })
     resource = self.nexus.resources.fetch(self.org, self.prj,
                                           resource["@id"])
     self.assertEqual(resource["_rev"], 1)
     query = """
     {
       "query": {
         "term": {
           "firstname": "Johnny"
         }
       }
     }
     """
     id = f"nxv:{random_string()}"
     self._put(id)
     time.sleep(10)
     payload_view = self.nexus.views.fetch(self.org, self.prj, id)
     pretty_print(payload_view)
     payload = self.nexus.views.query_es(self.org, self.prj, query, id)
     pretty_print(payload)
     self.assertGreater(len(payload["hits"]["hits"]), 0)
Esempio n. 3
0
 def test_deprecate(self):
     id = random_string()
     self._put(id)
     payload = self.nexus.schemas.fetch(self.org, self.prj, id)
     payload = self.nexus.schemas.deprecate(payload)
     pretty_print(payload)
     self.assertEqual(payload["_deprecated"], True)
Esempio n. 4
0
 def test_list(self):
     self._post()
     self._put()
     time.sleep(10)
     payload = self.nexus.files.list(self.org, self.prj)
     pretty_print(payload)
     self.assertGreater(len(payload["_results"]), 0)
Esempio n. 5
0
 def test_tag(self):
     id = random_string()
     payload = self.nexus.resources.create(self.org, self.prj, self.data, resource_id=id)
     self.nexus.resources.tag(payload, "mytag")
     tags = self.nexus.resources.tags(payload)
     pretty_print(tags)
     self.assertEqual(tags["tags"][0]["tag"], "mytag")
Esempio n. 6
0
 def test_update(self):
     id = random_string()
     self._put(id)
     payload = self.nexus.schemas.fetch(self.org, self.prj, id)
     payload["shapes"][0]["property"][0]["minCount"] = 10
     payload = self.nexus.schemas.update(payload)
     self.assertEqual(payload["_rev"], 2)
     pretty_print(payload)
Esempio n. 7
0
 def test_tag(self):
     id = random_string()
     self._put(id)
     payload = self.nexus.schemas.fetch(self.org, self.prj, id)
     payload = self.nexus.resources.tag(payload, "mytag")
     tags = self.nexus.resources.tags(payload)
     pretty_print(tags)
     self.assertEqual(tags["tags"][0]["tag"], "mytag")
Esempio n. 8
0
 def test_list(self):
     self._put()
     time.sleep(10)
     payload = self.nexus.views.list(self.org, self.prj)
     pretty_print(payload)
     self.assertGreater(len(payload["_results"]), 0)
     es = self.nexus.views.list_keep_only_es(payload)
     self.assertNotEqual(payload, es)
Esempio n. 9
0
 def test_attach(self):
     # Attach a file to an existing resource
     id = random_string()
     self._put(id)
     payload = self.nexus.resources.fetch(self.org, self.prj, resource_id=id)
     f = "./an_attachment.txt"
     payload = self.nexus.resources.add_attachement(payload, f)
     f = "./an_attachment_image.jpg"
     payload = self.nexus.resources.add_attachement(payload, f)
     pretty_print(payload)
Esempio n. 10
0
    def test_list(self):
        self._post()
        self._put()
        time.sleep(10)
        payload = self.nexus.resources.list(self.org, self.prj)
        pretty_print(payload)
        self.assertGreater(len(payload["_results"]), 0)

        payload = self.nexus.resources.list(self.org, self.prj, schema="context")
        self.assertEqual(len(payload["_results"]), 0)
Esempio n. 11
0
 def test_sparql_query(self):
     resource = self.nexus.resources.create(self.org, self.prj, {
         "firstname": "Johnny",
         "lastname": "Bravo"
     })
     resource = self.nexus.resources.fetch(self.org, self.prj,
                                           resource["@id"])
     self.assertEqual(resource["_rev"], 1)
     time.sleep(10)
     query = 'SELECT ?s where {?s ?p "Bravo"} LIMIT 10'
     payload = self.nexus.views.query_sparql(self.org, self.prj, query)
     pretty_print(payload)
     self.assertGreater(len(payload["results"]["bindings"]), 0)
Esempio n. 12
0
    def test_projects(self):
        nexus = new_client()
        org = random_string()
        prj = random_string()

        # listing projects
        payload = nexus.projects.list()
        pretty_print(payload)

        nexus.organizations.create(
            org,
            description=
            "This is my org, there are many like it but this one is mine.")
        nexus.projects.create(org, prj, "This is my awesome project")

        # Getting a specific project
        project = nexus.projects.fetch(org, prj)
        pretty_print(project)

        # Updating a project
        project["apiMappings"] = ["not", "sure", "what", "to", "put", "there"]
        updated = nexus.projects.update(project)
        pretty_print(updated)
        rev = updated["_rev"]
        self.assertEqual(rev, 2)

        # Deprecate a project
        deprecated = nexus.projects.deprecate(project, rev)
        pretty_print(project)
        self.assertEqual(deprecated["_rev"], 3)
    def test_orgs(self):
        nexus = new_client()
        org = random_string()

        # listing organizations
        payload = nexus.organizations.list(pagination_size=100)
        pretty_print(payload)

        # getting a specific organization
        nexus.organizations.create(org)
        payload = nexus.organizations.fetch(org)
        pretty_print(payload)
        self.assertEqual(payload["_rev"], 1)

        # Updating values of an organization
        payload["description"] = "an updated description v2"
        payload = nexus.organizations.update(payload)
        pretty_print(payload)
        self.assertEqual(payload["_rev"], 2)

        # Deprecate an Organization
        payload = nexus.organizations.deprecate(org, 2)
        pretty_print(payload)
        self.assertEqual(payload["_rev"], 3)
Esempio n. 14
0
 def _put(self, id=random_string()):
     self.nexus.resources.create(self.org, self.prj, self.data, resource_id=id)
     payload = self.nexus.resources.fetch(self.org, self.prj, id)
     pretty_print(payload)
     self.assertEqual(payload["_rev"], 1)
Esempio n. 15
0
 def _put(self, id=f"nxv:{random_string()}"):
     payload = self.nexus.views.create_es(self.org,
                                          self.prj,
                                          self.mapping,
                                          view_id=id)
     pretty_print(payload)
Esempio n. 16
0
 def _post(self):
     payload = self.nexus.resources.create(self.org, self.prj, self.data)
     payload = self.nexus.resources.fetch(self.org, self.prj, payload["@id"])
     pretty_print(payload)
     self.assertEqual(payload["_rev"], 1)
Esempio n. 17
0
 def _put(self, id=random_string()):
     payload = self.nexus.files.create(self.org, self.prj, "tests/an_attachment_image.jpg", file_id=id)
     pretty_print(payload)
     self.nexus.files.fetch(self.org, self.prj, id, out_filepath="/tmp/")
     self.assertTrue(filecmp.cmp("tests/an_attachment_image.jpg", "/tmp/an_attachment_image.jpg"))
Esempio n. 18
0
 def test_deprecate(self):
     id = random_string()
     payload = self.nexus.resources.create(self.org, self.prj, self.data, resource_id=id)
     deprecated = self.nexus.resources.deprecate(payload)
     pretty_print(deprecated)
     self.assertEqual(deprecated["_deprecated"], True)
Esempio n. 19
0
 def _post(self):
     payload = self.nexus.files.create(self.org, self.prj, "tests/an_attachment.txt")
     pretty_print(payload)
     self.nexus.files.fetch(self.org, self.prj, payload["@id"], out_filepath="/tmp/")
     self.assertTrue(filecmp.cmp("tests/an_attachment.txt", "/tmp/an_attachment.txt"))