Ejemplo n.º 1
0
    def test_perceive(self):
        gaia_ref = mock_gaia_ref(lambda x: MockResponse({
            "data": {
                "perceive": {
                    "perceiveData": {
                        "id": "asdf"
                    },
                    "perceiveAction": {
                        "id": "qwer"
                    }
                }
            }
        }))
        impulse1 = PerceiveActionImpulse(False, str(uuid.uuid4()), "", {})
        impulse2 = PerceiveDataImpulse(str(uuid.uuid4()), "", {})

        def perceive(p: Perception):
            p.perceive_action(impulse1, lambda x: x.id())
            p.perceive_data(impulse2, lambda x: x.id())

        result = pipe(ops.first())(gaia_ref.perceive(perceive)).run()
        perceiveData = result.dictionary.get("perceiveData")
        perceiveAction = result.dictionary.get("perceiveAction")
        assert perceiveData.get(
            "id") is not None, "PerceiveData.id is in response"
        assert perceiveAction.get(
            "id") is not None, "perceiveAction.id is in response"
Ejemplo n.º 2
0
    def test_export_identity_no_id(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/identity/source")
            return MockResponse(bytes("identity content", encoding="utf-8"))

        self.gaiaRef = mock_gaia_ref(mock)
        self.assertRaises(TypeError, lambda: pipe(ops.first())(self.gaiaRef.identity().export()).run())
Ejemplo n.º 3
0
    def test_list_files_in_nonexistent_dir(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/data/list")
            return MockResponse([])

        self.gaiaRef = mock_gaia_ref(mock)
        result = pipe(ops.first())(self.gaiaRef.data("gaia://tenant1/nonexistentDirectory").list()).run()
        self.assertEqual(len(result), 0)
Ejemplo n.º 4
0
 def test_write_new_file_with_path(self):
     file = Path(tempfile.gettempdir()) / "file"
     self.gaiaRef = mock_gaia_ref(self.mock_write)
     with open(str(file), "wb+") as f:
         f.write(b"f\x00\x00bar")
     path = Path(file)
     response = self.gaiaRef.data("gaia://tenant/somefolder").add("newFile", path)
     assert pipe(ops.first())(response).run().uri == "gaia://tenant/somefolder/newFile"
Ejemplo n.º 5
0
    def test_remove_nonexistent_file(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/data/remove")
            return MockResponse({"fileExisted": False})

        self.gaiaRef = mock_gaia_ref(mock)
        result = pipe(ops.first())(self.gaiaRef.data("gaia://tenant/somefolder/nonexistentFile").remove()).run()
        self.assertEqual(result.file_existed, False)
Ejemplo n.º 6
0
    def test_export_identity_mock(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/identity/source")
            return MockResponse(bytes("identity content", encoding="utf-8"))

        self.gaiaRef = mock_gaia_ref(mock)
        result = pipe(ops.first())(
            self.gaiaRef.identity().export("00000000-0000-0000-0000-000000000000")).run()
        self.assertEqual(result, bytes("identity content", "utf-8"))
Ejemplo n.º 7
0
    def test_retrieve_data_as_bytes(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/data/source")
            return MockResponse(bytes("hello world", encoding="utf-8"))

        self.gaiaRef = mock_gaia_ref(mock)
        result: bytes = pipe(ops.first())(
            self.gaiaRef.data("gaia://tenant/somefolder/somefolder/asdf1.pdf").as_bytes()).run()
        self.assertEqual(result, bytes("hello world", "utf-8"))
Ejemplo n.º 8
0
    def test_list_files_in_existing_dir(self):
        def mock(request):
            self.assertEqual(request.url_post_fix, "/data/list")
            return MockResponse([{"tenant": "tenant1", "filePath": "existingDirectory/file1",
                                  "lastModified": "2020-11-18", "size": "1000"}])

        self.gaiaRef = mock_gaia_ref(mock)
        result = pipe(ops.first())(self.gaiaRef.data("gaia://tenant1/existingDirectory").list()).run()
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0], FileListing({"tenant": "tenant1", "filePath": "existingDirectory/file1",
                                                 "lastModified": "2020-11-18", "size": "1000"}))
Ejemplo n.º 9
0
    def test_write_new_file_progress(self):
        self.gaiaRef = mock_gaia_ref(self.mock_write)
        data = bytes("234", encoding="utf-8")

        def test_progress(value):
            assert value == 100

        config: DataRefRequestConfig = DataRefRequestConfig(test_progress)

        response = self.gaiaRef.data("gaia://tenant/somefolder").add("newFile", data, False, config)
        assert pipe(ops.first())(response).run().uri == "gaia://tenant/somefolder/newFile"
Ejemplo n.º 10
0
    def test_does_not_block(self):
        gaia_ref = mock_gaia_ref(self.return_after_seconds(5))

        def config(x):
            x.identity_id()
            x.qualifier()

        t0 = time.perf_counter()
        pipe(ops.first())(gaia_ref.retrieve_intents(str(uuid4()), config))
        t1 = time.perf_counter()
        exec_time = t1 - t0

        self.assertLess(exec_time, 5)
Ejemplo n.º 11
0
    def test_retrieve_data_as_file(self):
        file = Path(tempfile.gettempdir()) / "file"
        content = b"binary data \x01\x00"

        def mock(request):
            self.assertEqual(request.url_post_fix, "/data/source")
            return MockResponse(content)

        self.gaiaRef = mock_gaia_ref(mock)
        result: Path = pipe(ops.first())(
            self.gaiaRef.data("gaia://tenant/somefolder/somefolder/file").as_file(str(file))).run()
        self.assertEqual(result, file)
        self.assertEqual(result.read_bytes(), content)
Ejemplo n.º 12
0
    def test_perceive_action(self):
        gaia_ref = mock_gaia_ref(lambda x: MockResponse(
            {"data": {
                "perceive": {
                    "perceiveAction": {
                        "id": "asdf"
                    }
                }
            }}))
        impulse = PerceiveActionImpulse(False, str(uuid.uuid4()), "", {})

        result = pipe(ops.first())(gaia_ref.perceive_action(impulse)).run()
        assert result.dictionary.get(
            "id") is not None, "PerceiveAction.id is in response"
Ejemplo n.º 13
0
 def test_cancel(self):
     gaia_ref = mock_gaia_ref(lambda x: MockResponse({
         "data": {
             "practice": {
                 "cancel": {
                     "id": "a8181dcd-84f5-45a0-ae77-cb0f89e3d7c2",
                     "data": {
                         "name": "skill-omdb-v0.1.3-build",
                         "reference":
                         "47de74f7-3dd3-34ca-9b92-3690a2f8cc91",
                         "tenantId": "f000f000-f000-f000-f000-f000f000f000",
                         "tag": "v0.1.3"
                     }
                 }
             }
         }
     }))
     result = gaia_ref.practice_cancel(
         CancelSkillBuildJobImpulse("f000f000-f000-f000-f000-f000f000f000", "47de74f7-3dd3-34ca-9b92-3690a2f8cc91"))\
     .run()
     assert result.data.name == "skill-omdb-v0.1.3-build"
Ejemplo n.º 14
0
 def test_build(self):
     gaia_ref = mock_gaia_ref(lambda x: MockResponse({
         "data": {
             "practice": {
                 "build": {
                     "id": "e2b92d76-b9ac-4626-8a97-fc25f0b79160",
                     "data": {
                         "name": "skill-omdb-v0.1.3-build",
                         "reference":
                         "47de74f7-3dd3-34ca-9b92-3690a2f8cc91",
                         "tenantId": "f000f000-f000-f000-f000-f000f000f000",
                         "skillRef": "a244d3d9-10fb-453a-8f9c-bb7e5e52a619",
                         "tag": "v0.1.3"
                     }
                 }
             }
         }
     }))
     result = gaia_ref.practice_build(
         CreateSkillBuildJobImpulse("f000f000-f000-f000-f000-f000f000f000",
                                    "a244d3d9-10fb-453a-8f9c-bb7e5e52a619",
                                    "v0.1.3")).run()
     assert result.data.name == "skill-omdb-v0.1.3-build"
Ejemplo n.º 15
0
    def test_get_build_jobs(self):
        gaia_ref = mock_gaia_ref(lambda x: MockResponse({
            "data": {
                "introspect": {
                    "buildJobs": [{
                        "reference": "47de74f7-3dd3-34ca-9b92-3690a2f8cc91",
                        "name": "skill-omdb-v0.1.3-build",
                        "tenantId": "f000f000-f000-f000-f000-f000f000f000",
                        "tag": "v0.1.3",
                        "status": {
                            "failures": [],
                            "running": 1,
                            "pending": 0,
                            "health": "BUILDING"
                        }
                    }]
                }
            }
        }))

        result = gaia_ref.introspect_build_jobs(
            "f000f000-f000-f000-f000-f000f000f000").run()
        assert result.tag == "v0.1.3"
        assert result.name == "skill-omdb-v0.1.3-build"
Ejemplo n.º 16
0
 def test_preserve_delete_fulfilment(self):
     gaia_ref = mock_gaia_ref(lambda request: self.entityDeleteMockResponse("fulfilments"))
     impulses = DeleteFulfilmentImpulse(str(uuid4()), str(uuid4()))
     result: DeletedFulfilmentImpulse = pipe(ops.first())(gaia_ref.preserve_delete_fulfilments([impulses])).run()
     self.assert_delete_entity(result)
Ejemplo n.º 17
0
 def test_overwrite_existing_file_doesnt_work(self):
     self.gaiaRef = mock_gaia_ref(self.mock_write_existing_fail)
     data = bytes("234", encoding="utf-8")
     self.assertRaises(Exception,
                       lambda: self.gaiaRef.data("gaia://tenant/somefolder").add("existingFile", data).pipe(
                           ops.first()).run())
Ejemplo n.º 18
0
 def test_write_new_file_with_bytes(self):
     self.gaiaRef = mock_gaia_ref(self.mock_write)
     data = bytes("234", encoding="utf-8")
     response = self.gaiaRef.data("gaia://tenant/somefolder").add("newFile", data)
     assert pipe(ops.first())(response).run().uri == "gaia://tenant/somefolder/newFile"
Ejemplo n.º 19
0
 def test_overwrite_file(self):
     self.gaiaRef = mock_gaia_ref(self.mock_write)
     data = bytes("234", encoding="utf-8")
     response = self.gaiaRef.data("gaia://tenant/somefolder").add("existingFile", data, override=True)
     assert pipe(ops.first())(response).run().uri == "gaia://tenant/somefolder/existingFile"
Ejemplo n.º 20
0
 def test_import_identity(self):
     self.gaiaRef = mock_gaia_ref(self.mock_write)
     data = bytes("identity content", encoding="utf-8")
     result = pipe(ops.first())(self.gaiaRef.identity().import_identity('tenantId', 'identityName', data)).run()
     self.assertEqual(result['uri'], 'gaia://tenantId/identities/identityName')
     self.assertEqual(result['partitionKey'], '0123456789')
Ejemplo n.º 21
0
 def test_preserve_delete_identity(self):
     gaia_ref = mock_gaia_ref(lambda request: self.identityDeleteMockResponse())
     impulses = DeleteIdentityImpulse(str(uuid4()))
     result: DeletedIdentityImpulse = pipe(ops.first())(gaia_ref.preserve_delete_identities([impulses])).run()
     self.assert_delete_identity(result)
Ejemplo n.º 22
0
 def test_preserve_update_identity(self):
     gaia_ref = mock_gaia_ref(lambda request: self.identityMockCreateUpdateResponse("update"))
     impulses = UpdateIdentityImpulse(str(uuid4()), str(uuid4()), "qualifier", {"de": "Deutsch"})
     result: UpdatedIdentityImpulse = pipe(ops.first())(gaia_ref.preserve_update_identities([impulses])).run()
     self.assert_create_update_identity(result)
Ejemplo n.º 23
0
 def test_preserve_update_fulfilment(self):
     gaia_ref = mock_gaia_ref(lambda request: self.entityCreateUpdateMockResponse("update", "fulfilments"))
     impulses = UpdateFulfilmentImpulse(str(uuid4()), str(uuid4()), "", "", dict(), list())
     result: UpdatedFulfilmentImpulse = pipe(ops.first())(gaia_ref.preserve_update_fulfilments([impulses])).run()
     self.assert_create_update_entity(result)
Ejemplo n.º 24
0
 def test_preserve_create_prompt(self):
     gaia_ref = mock_gaia_ref(lambda request: self.entityCreateUpdateMockResponse("create", "prompts"))
     impulses = CreatePromptImpulse(str(uuid4()), "", "", dict(), list())
     result: CreatedPromptImpulse = pipe(ops.first())(gaia_ref.preserve_create_prompts([impulses])).run()
     self.assert_create_update_entity(result)
Ejemplo n.º 25
0
 def test_preserve_delete_edge(self):
     gaia_ref = mock_gaia_ref(lambda request: self.edgeDeleteMockResponse())
     impulses = DeleteEdgeImpulse(str(uuid4()), str(uuid4()))
     result: DeletedEdgeImpulse = pipe(ops.first())(gaia_ref.preserve_delete_edges([impulses])).run()
     self.assert_delete_edge(result)
Ejemplo n.º 26
0
 def test_preserve_create_edge(self):
     gaia_ref = mock_gaia_ref(lambda request: self.edgeCreateMockResponse())
     impulses = CreateEdgeImpulse(str(uuid4()), str(uuid4()), "someType", 2.7, dict())
     result: CreatedEdgeImpulse = pipe(ops.first())(gaia_ref.preserve_create_edges([impulses])).run()
     self.assert_create_edge(result)
Ejemplo n.º 27
0
 def test_preserve_update_code(self):
     gaia_ref = mock_gaia_ref(lambda request: self.codeCreateUpdateMockResponse("update"))
     impulses = UpdateCodeImpulse(str(uuid4()), str(uuid4()), "", "", dict(), "", list())
     result: UpdatedCodeImpulse = pipe(ops.first())(gaia_ref.preserve_update_codes([impulses])).run()
     self.assert_create_update_code(result)
Ejemplo n.º 28
0
 def test_preserve_delete_behaviour(self):
     gaia_ref = mock_gaia_ref(lambda request: self.behaviourDeleteMockResponse())
     impulses = DeleteBehaviourImpulse(str(uuid4()), str(uuid4()))
     result: DeletedBehaviourImpulse = pipe(ops.first())(gaia_ref.preserve_delete_behaviours([impulses])).run()
     self.assert_delete_behaviour(result)
Ejemplo n.º 29
0
 def test_preserve_update_behaviour(self):
     gaia_ref = mock_gaia_ref(lambda request: self.behaviourCreateUpdateMockResponse("update"))
     impulses = UpdateBehaviourImpulse(str(uuid4()), str(uuid4()), "", "", "", list())
     result: UpdatedBehaviourImpulse = pipe(ops.first())(gaia_ref.preserve_update_behaviours([impulses])).run()
     self.assert_create_update_behaviour(result)