@@ -228,18 +228,64 @@ def setUp(self, redis_mock, classEndpoint_mock):
228228 self .cpv = ClassPropertiesValue (api_doc , url , graph )
229229
230230 def test_data_from_server (self ):
231+ # endpoint param for data_from_server
231232 endpoint = "TestEndpoint"
232233 clas_mock = self .cpv .clas
233234 connection_mock = self .cpv .connection
234235
236+ # call to data_from_server
235237 self .cpv .data_from_server (endpoint )
236238
239+ # asserting that load_from_server was called with correct params
237240 clas_mock .load_from_server .assert_called_with (endpoint , self .cpv .api_doc , self .cpv .url , connection_mock )
238241
242+ # asserting that redis_query was called with correct params
239243 connection_mock .execute_command .assert_called_with ('GRAPH.QUERY' , 'apidoc' , """MATCH(p:classes)
240244 WHERE(p.type='TestEndpoint')
241245 RETURN p.property_value""" )
242246
247+ def smembers_mock_func (self , inp ):
248+ if inp == "fs:endpoints" :
249+ return [b"TestClass" ]
250+
251+ def test_get_property_value (self ):
252+ # query param for get_property_value
253+ query = "classTestClass property_value"
254+ connection_mock = self .cpv .connection
255+
256+ # making the if condition true
257+ connection_mock .keys .return_value = [b'fs:endpoints' ]
258+ connection_mock .smembers .side_effect = self .smembers_mock_func
259+
260+ # call to get_members
261+ self .cpv .get_property_value (query )
262+
263+ # checking the call made to connection_mock.execute_command with correct params
264+ connection_mock .execute_command .assert_called_with ('GRAPH.QUERY' , 'apidoc' , """MATCH (p:classes)
265+ WHERE (p.type = 'TestClass')
266+ RETURN p.property_value""" )
267+
268+ # asserting that connection.sadd was not called
269+ connection_mock .sadd .assert_not_called ()
270+
271+ def smembers_mock_func_else (self ):
272+ return []
273+
274+ def test_get_property_value_else (self ):
275+ # query param for get_property_value
276+ query = "classTestClass property_value"
277+ connection_mock = self .cpv .connection
278+
279+ # making the if condition false
280+ connection_mock .keys .return_value = []
281+ connection_mock .smembers .side_effect = self .smembers_mock_func_else
282+
283+ # call to get_members
284+ self .cpv .get_property_value (query )
285+
286+ # asserting that connection.sadd was called
287+ connection_mock .sadd .assert_called_with ("fs:endpoints" , "TestClass" )
288+
243289
244290if __name__ == "__main__" :
245291 unittest .main ()
0 commit comments