def test_tree_query_v1(): def request_callback(request): headers = {'Content-Type': 'application/json'} response = { 'data': { 'updateEntity': { 'entity': { '_id': '1' }, 'vertex': { 'id': '1' } } } } return (200, headers, json.dumps(response)) responses.add_callback( responses.POST, 'https://api.us.jupiterone.io/graphql', callback=request_callback, content_type='application/json', ) j1 = JupiterOneClient(account='testAccount', token='testToken') response = j1.update_entity('1', properties={'testKey': 'testValue'}) assert type(response) == dict assert type(response['entity']) == dict assert type(response['vertex']) == dict assert response['entity']['_id'] == '1'
def test_query_v1(): responses.add_callback( responses.POST, 'https://api.us.jupiterone.io/graphql', callback=request_callback, content_type='application/json', ) j1 = JupiterOneClient(account='testAccount', token='testToken') query = "find Host with _id='1'" response = j1.query_v1(query) assert type(response) == dict assert len(response['data']) == 1 assert type(response['data']) == list assert response['data'][0]['entity']['_id'] == '1'
def test_tree_query_v1(): def request_callback(request): headers = {'Content-Type': 'application/json'} response = { 'data': { 'createRelationship': { 'relationship': { '_id': '1' }, 'edge': { 'id': '1', 'toVertexId': '1', 'fromVertexId': '2', 'relationship': { '_id': '1' }, 'properties': {} } } } } return (200, headers, json.dumps(response)) responses.add_callback( responses.POST, 'https://api.us.jupiterone.io/graphql', callback=request_callback, content_type='application/json', ) j1 = JupiterOneClient(account='testAccount', token='testToken') response = j1.create_relationship(relationship_key='relationship1', relationship_type='test_relationship', relationship_class='TestRelationship', from_entity_id='2', to_entity_id='1') assert type(response) == dict assert type(response['relationship']) == dict assert response['relationship']['_id'] == '1' assert response['edge']['toVertexId'] == '1' assert response['edge']['fromVertexId'] == '2'
def test_tree_query_v1(): def request_callback(request): headers = { 'Content-Type': 'application/json' } response = { 'data': { 'queryV1': { 'type': 'tree', 'data': { 'vertices': [ { 'id': '1', 'entity': {}, 'properties': {} } ], 'edges': [] } } } } return (200, headers, json.dumps(response)) responses.add_callback( responses.POST, 'https://api.us.jupiterone.io/graphql', callback=request_callback, content_type='application/json', ) j1 = JupiterOneClient(account='testAccount', token='testToken') query = "find Host with _id='1' return tree" response = j1.query_v1(query) assert type(response) == dict assert 'edges' in response assert 'vertices' in response assert type(response['edges']) == list assert type(response['vertices']) == list assert response['vertices'][0]['id'] == '1'
def test_execute_query(): responses.add_callback( responses.POST, 'https://api.us.jupiterone.io/graphql', callback=request_callback, content_type='application/json', ) j1 = JupiterOneClient(account='testAccount', token='testToken') query = "find Host with _id='1'" variables = { 'query': query, 'includeDeleted': False } response = j1._execute_query( query=QUERY_V1, variables=variables ) assert 'data' in response assert 'queryV1' in response['data'] assert len(response['data']['queryV1']['data']) == 1 assert type(response['data']['queryV1']['data']) == list assert response['data']['queryV1']['data'][0]['entity']['_id'] == '1'
def test_missing_account(): with pytest.raises(Exception) as ex: j1 = JupiterOneClient(token='123') assert 'account is required' in str(ex.value)
def test_missing_token(): with pytest.raises(Exception) as ex: j1 = JupiterOneClient(account='test') assert 'token is required' in str(ex.value)