A pytest-implementation test for the Graph API endpoints.
"""
# used to store graph UUIDs in the build test and reuse these in the delete test
graph_1_test_id="graph_mock_uuid1"
graph_2_test_id="graph_mock_uuid2"
@pytest.fixture(autouse=True)
defapp_config(self):
"""
...
...
@@ -95,15 +96,15 @@ class TestGraphAPI(object):
error_raised=True
asserterror_raised,error_msg
deftest_build(self,db_testing_data):
@patch('clmcservice.graphapi.views.uuid4')
deftest_build(self,uuid_mock,db_testing_data):
"""
Tests the graph build API endpoint - it makes 2 API calls and checks that the expected graph was created (the influx data that's being used is reported to InfluxDB in the conftest file)
:param uuid_mock: mock object to mock the behaviour of the uuid4 function
:param db_testing_data: pair of time stamps - the from-to range of the generated influx test data, test database name and the graph db client object (this is a fixture from conftest)
"""
globalgraph_1_id,graph_2_id# these variables are used to store the ID of the graphs that were created during the execution of this test method; they are reused later when testing the delete method
# remove the "from" and "to" keys, these will be returned in the graph_subresponse
build_json_body.pop("from")
build_json_body.pop("to")
assertresponse==build_json_body,"Response must contain the request body"
assertgraph_subresponse.get("uuid")isnotNone,"Request UUID must be attached to the response."
assertresponse=={"database":"test_sfc"},"Response must contain the database name"
assertgraph_subresponse["uuid"]==self.graph_2_test_id,"Request UUID must be attached to the response."
assertgraph_subresponse["time_range"]["from"]==from_timestamp*10**9# timestamp returned in nanoseconds
assertgraph_subresponse["time_range"]["to"]==to_timestamp*10**9# timestamp returned in nanoseconds
request_id=graph_subresponse["uuid"]
graph_2_id=request_id
# check the new nodes have been created
assertgraph_db.nodes.match("ServiceFunctionPackage",name="apache").first()isnotNone,"Service function package apache must have been added to the graph"
...
...
@@ -262,8 +263,6 @@ class TestGraphAPI(object):
:param db_testing_data: pair of time stamps - the from-to range of the generated influx test data, test database name and the graph db client object (this is a fixture from conftest)