Exemplo n.º 1
0
 def mock_write(self, request):
     if request.url_post_fix == "/data/sink/init":
         return MockResponse({"uploadId": "A123"})
     elif request.url_post_fix == "/data/sink/chunk":
         return MockResponse({"chunkId": "B123"})
     elif request.url_post_fix == "/data/sink/complete":
         return MockResponse("asdfqwer")
     else:
         raise RuntimeError('On purpose')
Exemplo n.º 2
0
 def mock_write(self, request):
     if request.url_post_fix == "/data/sink/init":
         return MockResponse({"uploadId": "A123"})
     elif request.url_post_fix == "/data/sink/chunk":
         return MockResponse({"chunkId": "B123"})
     elif request.url_post_fix == "/data/sink/complete":
         return MockResponse("asdfqwer")
     elif request.url_post_fix == "/identity/import":
         return MockResponse({'partitionKey': '0123456789', 'uri': 'gaia://tenantId/identities/identityName'})
     else:
         raise RuntimeError('On purpose')
Exemplo n.º 3
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"
Exemplo n.º 4
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"
Exemplo n.º 5
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"
Exemplo n.º 6
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"
Exemplo n.º 7
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"
Exemplo n.º 8
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/identity/source")
     return MockResponse(bytes("identity content", encoding="utf-8"))
Exemplo n.º 9
0
    def setUp(self) -> None:
        self.identityMockCreateUpdateResponse: Callable[[str], MockResponse] = lambda t: MockResponse(
            {"data": {"preserve": {t: {"identities": [
                {"id": "asdf", "data": {"identityId": "i1",
                                        "tenantId": "foo",
                                        "qualifier": "bar",
                                        "availableLanguages": {"de": "Deutsch"}}}
            ]}}}}
        )

        self.identityDeleteMockResponse: Callable[[str], MockResponse] = lambda: MockResponse(
            {"data": {"preserve": {"delete": {"identities": [
                {"id": "asdf", "data": {"identityId": "i1"}}
            ]}}}}
        )

        self.deleteMockResponse: Callable[[str], MockResponse] = lambda t: MockResponse(
            {"data": {"preserve": {"delete": {t: [
                {"id": "asdf", "data": {"identityId": "i1",
                                        "reference": "r1"}}
            ]}}}}
        )

        """Entity = ("prompt" | "intent" | "fulfilment" | "statement") """
        self.entityCreateUpdateMockResponse: Callable[[str], MockResponse] = lambda t1, t2: MockResponse(
            {"data": {"preserve": {t1: {t2: [
                {"id": "asdf", "data": {"identityId": "i1",
                                        "reference": "r1",
                                        "qualifier": "foo",
                                        "appendent": "bar",
                                        "utterance": {"de": ["content"]},
                                        "labelList": [],
                                        "version": "2.7.0-SNAPSHOT"}}
            ]}}}}
        )

        self.entityDeleteMockResponse: Callable[[str], MockResponse] = lambda t: self.deleteMockResponse(t)

        self.behaviourCreateUpdateMockResponse: Callable[[str], MockResponse] = lambda t: MockResponse(
            {"data": {"preserve": {t: {"behaviours": [
                {"id": "asdf", "data": {"identityId": "i1",
                                        "reference": "r1",
                                        "qualifier": "foo",
                                        "appendent": "bar",
                                        "labelList": []}}
            ]}}}}
        )

        self.behaviourDeleteMockResponse: Callable[[str], MockResponse] = lambda: self.deleteMockResponse("behaviours")

        self.codeCreateUpdateMockResponse: Callable[[str], MockResponse] = lambda t: MockResponse(
            {"data": {"preserve": {t: {"codes": [
                {"id": "asdf", "data": {"identityId": "i1",
                                        "reference": "r1",
                                        "qualifier": "foo",
                                        "appendent": "bar",
                                        "code": {"index": "httpGet(\"https://postman-echo.com/get?foo=bar\")"},
                                        "type": "atreus",
                                        "labelList": []}}
            ]}}}}
        )

        self.codeDeleteMockResponse: Callable[[str], MockResponse] = lambda: self.deleteMockResponse("codes")

        self.edgeCreateMockResponse: Callable[[str], MockResponse] = lambda: MockResponse(
            {"data": {"preserve": {"create": {"edges": [
                {"id": "asdf", "data": {"source": "n1",
                                        "target": "n2",
                                        "type": "someType",
                                        "weight": 2.7,
                                        "edgeId": "e1",
                                        "properties": {}}}
            ]}}}}
        )

        self.edgeDeleteMockResponse: Callable[[str], MockResponse] = lambda: MockResponse(
            {"data": {"preserve": {"delete": {"edges": [
                {"id": "asdf", "data": {"source": "n1",
                                        "edgeId": "e1"}}
            ]}}}}
        )
Exemplo n.º 10
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/data/list")
     return MockResponse([])
Exemplo n.º 11
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/data/list")
     return MockResponse([{"tenant": "tenant1", "filePath": "existingDirectory/file1",
                           "lastModified": "2020-11-18", "size": "1000"}])
Exemplo n.º 12
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/data/source")
     return MockResponse(content)
Exemplo n.º 13
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/data/source")
     return MockResponse(bytes("hello world", encoding="utf-8"))
Exemplo n.º 14
0
 def mock_write_existing_fail(self, request):
     if request.url_post_fix == "/data/sink/init":
         raise RuntimeError('On purpose')
     else:
         return MockResponse({"x": "y"})
Exemplo n.º 15
0
 def mock(request):
     self.assertEqual(request.url_post_fix, "/data/remove")
     return MockResponse({"fileExisted": False})