Example #1
0
    def test_dict_round_trip(self):
        # noinspection SpellCheckingInspection
        d_a = json.loads(r'''{
  "ogit\/_created-on": 1585068142772,
  "\/ProcessIssue": "process_me",
  "ogit\/status": "TERMINATED",
  "ogit\/_modified-on": 1585069015158,
  "ogit\/_graphtype": "vertex",
  "ogit\/_owner": "arago.co",
  "ogit\/_v": 8,
  "ogit\/Automation\/deployStatus": "initialized",
  "ogit\/_modified-by-app": "cjix82tev000ou473gko8jgey",
  "ogit\/_type": "ogit\/Automation\/AutomationIssue",
  "ogit\/Automation\/suspendUntil": "2020-03-25 09:22:23.213112Z",
  "\/Counter": "1",
  "ogit\/Automation\/originNode": "ck0r9ti7f079qtv02hc4qsf28",
  "ogit\/_id": "ck864nagkv8qfgx02r2ybfoob",
  "ogit\/_creator": "*****@*****.**",
  "ogit\/_v-id": "1585069015158-fmpmKq",
  "ogit\/subject": "",
  "ogit\/_is-deleted": false,
  "ogit\/_creator-app": "cjix82rxi000gu473w5kvkpqv",
  "ogit\/_modified-by": "hiro_engine",
  "ogit\/Automation\/processingTimestamp": "1585068143245"
}''')
        v = Vertex(d_a, draft=False)
        d_b = v.to_dict()
        for k_a, v_a in d_a.items():
            assert k_a in d_b.keys()
            v_b = d_b[k_a]
            assert v_a == v_b
Example #2
0
 def test_blob_ogit_v(self, client: HiroClient):
     from arago.hiro.backend.six.graph import Hiro6GraphModel
     graph = Hiro6GraphModel(client)
     res = graph.vertex.create(OgitEntity.OGIT_ATTACHMENT, Vertex({
         OgitAttribute.OGIT_NAME: 'foo'
     }))
     assert isinstance(res, BlobVertex)
     assert res[OgitAttribute.OGIT_NAME] == 'foo'
     res.delete()
     pass
    def test_sig_args_vertex(self, client: HiroClient, user_agent: str):
        # when:
        created = client.model.graph.vertex.create(
            Vertex({'ogit/_type': 'ogit/Note'}))

        # then:
        assert created.created_by is not None

        # cleanup:
        deleted = client.model.graph.vertex.delete(created.id)
        assert deleted.is_deleted is True
 def test_vertex_update_10(self, client: HiroClient, user_agent: str):
     created = client.model.graph.vertex.create('ogit/Note')
     updated = client.model.graph.vertex.update(
         vertex=Vertex({
             'ogit/_id': created.id,
             'ogit/name': uuid(),
             'ogit/content': 'Unit Test: %s' % user_agent,
         }))
     assert updated.v == 2
     deleted = client.model.graph.vertex.delete(updated.id)
     assert deleted.is_deleted is True
Example #5
0
def to_vertex(data: Mapping[str, Any],
              client: HIRO_BASE_CLIENT_T_co) -> VERTEX_T_co:
    vertex_type = GraphDict(data).get(OgitAttribute.OGIT__TYPE)
    e_vertex_type = to_vertex_type(vertex_type)

    if e_vertex_type is OgitEntity.OGIT_ATTACHMENT:
        return BlobVertex(data, client=client, draft=False)
    elif e_vertex_type is OgitEntity.OGIT_DATA_LOG:
        raise NotImplementedError()
    elif e_vertex_type is OgitEntity.OGIT_TIME_SERIES:
        return TimeSeriesVertex(data, client=client, draft=False)
    else:
        return Vertex(data, client=client, draft=False)
    def test_vertex_create_args_type_vertex(self, client: HiroClient,
                                            user_agent: str):
        # when:
        created = client.model.graph.vertex.create(
            'ogit/Note',
            Vertex({
                'ogit/name': uuid(),
                'ogit/content': 'Unit Test: %s' % user_agent,
            }))

        # then:
        assert created.created_by is not None

        # cleanup:
        deleted = client.model.graph.vertex.delete(created.id)
        assert deleted.is_deleted is True
Example #7
0
 def transform(src_item: Dict[str, Any]) -> Vertex:
     return Vertex(src_item, self.__base_client,
                   False)  # frozen=True
Example #8
0
class TestClassGraphVertexCreate:
    @pytest.mark.parametrize('vertex_type', [
        OgitEntity.OGIT_COMMENT,
        OgitEntity.OGIT_COMMENT.value,
        OgitEntity.OGIT_COMMENT.value.name.uri
    ])
    def test_type_no_data(self, client: HiroClient, vertex_type: VERTEX_TYPE_T):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        vertex = graph.vertex.create(vertex_type)
        assert isinstance(vertex, Vertex)
        vertex.delete()
        pass

    @pytest.mark.parametrize('vertex_type', [
        OgitEntity.OGIT_COMMENT,
        OgitEntity.OGIT_COMMENT.value,
        OgitEntity.OGIT_COMMENT.value.name.uri
    ])
    @pytest.mark.parametrize('vertex_data', [
        Vertex({OgitAttribute.OGIT_CONTENT: 'foo'}),
        BlobVertex({OgitAttribute.OGIT_CONTENT: 'foo'}),
        TimeSeriesVertex({OgitAttribute.OGIT_CONTENT: 'foo'}),
        {SystemAttribute.OGIT__XID: uuid()},
        {FinalAttribute.OGIT__XID: uuid()},
        {OgitAttribute.OGIT_CONTENT: 'foo'},
        {OgitAttribute.OGIT_CONTENT.value: 'foo'},
        {OgitAttribute.OGIT_CONTENT.value.name.uri: 'foo'},
        {FreeAttribute('/bar'): 'foo'},
    ])
    def test_type_data(self, client: HiroClient, vertex_type: VERTEX_TYPE_T, vertex_data: Optional[VERTEX_T]):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        vertex = graph.vertex.create(vertex_type, vertex_data)
        assert isinstance(vertex, Vertex)
        vertex.delete()
        pass

    @pytest.mark.parametrize('vertex_data', [
        Vertex({
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            OgitAttribute.OGIT_CONTENT: 'foo'}),
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            SystemAttribute.OGIT__XID: uuid()},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            FinalAttribute.OGIT__XID: uuid()},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            OgitAttribute.OGIT_CONTENT: 'foo'},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            OgitAttribute.OGIT_CONTENT.value: 'foo'},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            OgitAttribute.OGIT_CONTENT.value.name.uri: 'foo'},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT,
            FreeAttribute('/bar'): 'foo'},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT.value,
            FreeAttribute('/bar'): 'foo'},
        {
            FinalAttribute.OGIT__TYPE: OgitEntity.OGIT_COMMENT.value.name.uri,
            FreeAttribute('/bar'): 'foo'},
    ])
    def test_data_no_type(self, client: HiroClient, vertex_data: Optional[VERTEX_T]):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        vertex = graph.vertex.create(vertex_data)
        assert isinstance(vertex, Vertex)
        vertex.delete()
        pass

    @pytest.mark.parametrize('vertex_type,cls', [
        (OgitEntity.OGIT_TIME_SERIES, TimeSeriesVertex),
        (OgitEntity.OGIT_ATTACHMENT, BlobVertex),
    ])
    def test_upcast(self, client: HiroClient, vertex_type: VERTEX_TYPE_T, cls: Type[VERTEX_T_co]):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(vertex_type)
        assert isinstance(res, cls)
        res.delete()
        pass

    def test_ts(self, client: HiroClient):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(OgitEntity.OGIT_TIME_SERIES)
        assert isinstance(res, TimeSeriesVertex)
        res.delete()
        pass

    def test_blob_ogit(self, client: HiroClient):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(OgitEntity.OGIT_ATTACHMENT)
        assert isinstance(res, BlobVertex)
        res.delete()
        pass

    def test_blob_ogit_map(self, client: HiroClient):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(OgitEntity.OGIT_ATTACHMENT, {
            OgitAttribute.OGIT_NAME: 'foo'
        })
        assert isinstance(res, BlobVertex)
        assert res[OgitAttribute.OGIT_NAME] == 'foo'
        res.delete()
        pass

    def test_blob_ogit_v(self, client: HiroClient):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(OgitEntity.OGIT_ATTACHMENT, Vertex({
            OgitAttribute.OGIT_NAME: 'foo'
        }))
        assert isinstance(res, BlobVertex)
        assert res[OgitAttribute.OGIT_NAME] == 'foo'
        res.delete()
        pass

    def test_blob_ontology(self, client: HiroClient):
        from arago.hiro.backend.six.graph import Hiro6GraphModel
        graph = Hiro6GraphModel(client)
        res = graph.vertex.create(OgitEntity.OGIT_ATTACHMENT.value)
        assert isinstance(res, BlobVertex)
        res.delete()
        pass