예제 #1
0
 def test_create_multiple(self, mock_rel_response):
     rel1 = Relationship(
         external_id="new1",
         confidence=0.5,
         relationship_type="flowsTo",
         source={
             "resourceId": "aaa",
             "resource": "Asset"
         },
         target={
             "resourceId": "bbb",
             "resource": "Asset"
         },
     )
     rel2 = Relationship(
         external_id="new2",
         confidence=0.1,
         relationship_type="flowsTo",
         source={
             "resourceId": "aaa",
             "resource": "Asset"
         },
         target={
             "resourceId": "bbb",
             "resource": "Asset"
         },
     )
     res = REL_API.create([rel1, rel2])
     assert isinstance(res, RelationshipList)
     assert mock_rel_response.calls[0].response.json()["items"] == res.dump(
         camel_case=True)
    def test_create_single_types(self, mock_rel_response):
        types = [Asset, TimeSeries, FileMetadata, Event, Sequence]
        for cls in types:
            test = cls(external_id="test")
            res = REL_API.create(
                Relationship(
                    external_id="1",
                    confidence=0.5,
                    relationship_type="belongsTo",
                    source=test,
                    target={"resourceId": "bbb", "resource": "Asset"},
                )
            )
            assert isinstance(res, Relationship)
            res = REL_API.create(
                Relationship(
                    external_id="1",
                    confidence=0.5,
                    relationship_type="belongsTo",
                    source={"resourceId": "bbb", "resource": "Asset"},
                    target=test,
                )
            )
            assert isinstance(res, Relationship)
            res = REL_API.create(
                Relationship(external_id="1", confidence=0.5, relationship_type="belongsTo", source=test, target=test)
            )
            assert isinstance(res, Relationship)

        for call in mock_rel_response.calls:
            it = json.loads(gzip.decompress(call.request.body).decode("utf-8"))["items"][0]
            assert isinstance(it["source"], dict)
            assert isinstance(it["target"], dict)
 def test_create_wrong_type(self, mock_rel_response):
     with pytest.raises(ValueError):
         REL_API.create(
             Relationship(
                 external_id="1",
                 confidence=0.5,
                 relationship_type="belongsTo",
                 source=Relationship(external_id="a"),
                 target={"resourceId": "bbb", "resource": "Asset"},
             )
         )
 def test_create_single(self, mock_rel_response):
     res = REL_API.create(
         Relationship(
             external_id="1",
             confidence=0.5,
             relationship_type="flowsTo",
             source={"resourceId": "aaa", "resource": "Asset"},
             target={"resourceId": "bbb", "resource": "Asset"},
         )
     )
     assert isinstance(res, Relationship)
     assert mock_rel_response.calls[0].response.json()["items"][0] == res.dump(camel_case=True)