forked from auth0/jupiterone-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_delete_relationship.py
More file actions
73 lines (59 loc) · 2.31 KB
/
test_delete_relationship.py
File metadata and controls
73 lines (59 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import pytest
import responses
from jupiterone.client import JupiterOneClient
from jupiterone.errors import JupiterOneClientError
MOCK_RESPONSE = {
'data': {
'deleteRelationship': {
'relationship': {
'_id': '1'
},
'edge': {
'id': '1',
'toVertexId': '1',
'fromVertexId': '2',
'relationship': {
'_id': '1'
},
'properties': {}
}
}
}
}
def _make_callback(captured_requests):
"""Return a callback that records request bodies and returns a success response."""
def request_callback(request):
captured_requests.append(json.loads(request.body))
return (200, {'Content-Type': 'application/json'}, json.dumps(MOCK_RESPONSE))
return request_callback
@responses.activate
def test_delete_relationship_sends_required_variables():
captured = []
responses.add_callback(
responses.POST, 'https://graphql.us.jupiterone.io',
callback=_make_callback(captured),
content_type='application/json',
)
j1 = JupiterOneClient(account='testAccount', token='testToken1234567890')
response = j1.delete_relationship(
relationship_id='1',
from_entity_id='2222222222',
to_entity_id='3333333333'
)
assert len(captured) == 1
variables = captured[0]['variables']
assert variables['relationshipId'] == '1'
assert variables['fromEntityId'] == '2222222222'
assert variables['toEntityId'] == '3333333333'
assert response['relationship']['_id'] == '1'
assert response['edge']['toVertexId'] == '1'
assert response['edge']['fromVertexId'] == '2'
def test_delete_relationship_raises_without_from_entity_id():
j1 = JupiterOneClient(account='testAccount', token='testToken1234567890')
with pytest.raises(JupiterOneClientError, match="from_entity_id is required"):
j1.delete_relationship(relationship_id='1', to_entity_id='3333333333')
def test_delete_relationship_raises_without_to_entity_id():
j1 = JupiterOneClient(account='testAccount', token='testToken1234567890')
with pytest.raises(JupiterOneClientError, match="to_entity_id is required"):
j1.delete_relationship(relationship_id='1', from_entity_id='2222222222')