def test_graph_sample_profile_listing(self): graph = GraphFactory.load_sample_profile_listing_graph() self.assertEqual(str(graph), 'Graph(vertices: 15, edges: 23)') query_results = graph.query().v('p-1').id().to_list() output = ['p-1'] self.assertEqual(query_results, output) query_results = graph.query().v('p-1').out('bookmarked').id().to_list() output = ['l-1', 'l-2', 'l-3'] self.assertEqual(query_results, output) query_results = graph.query().v('p-1').out('bookmarked').in_( 'bookmarked').id().to_list() output = [ 'p-1', 'p-2', 'p-3', 'p-3', 'p-1', 'p-4', 'p-5', 'p-1', 'p-5' ] self.assertEqual(query_results, output) query_results = graph.query().v('p-1').out('bookmarked').in_( 'bookmarked').id().distinct().to_list() output = ['p-1', 'p-2', 'p-3', 'p-4', 'p-5'] self.assertEqual(query_results, output) query_results = graph.query().v('p-1').out('bookmarked').in_( 'bookmarked').distinct().id().to_list() output = ['p-1', 'p-2', 'p-3', 'p-4', 'p-5'] self.assertEqual(query_results, output) query_results = graph.query().v('p-1').out('bookmarked').in_( 'bookmarked').distinct().exclude_ids(['p-1']).id().to_list() output = ['p-2', 'p-3', 'p-4', 'p-5'] self.assertEqual(query_results, output)
def test_graph_recommendation(self): graph = GraphFactory.load_sample_profile_listing_graph() results = graph.algo().recommend_listings_for_profile('p-1') expected_results = [('l-5', 2), ('l-8', 1), ('l-7', 1), ('l-6', 1), ('l-4', 1)] self.assertEqual(results, expected_results)
def test_graph_sample_profile_listing_categories(self): graph = GraphFactory.load_sample_profile_listing_graph() self.assertEqual(str(graph), 'Graph(vertices: 15, edges: 23)') query_results = ( graph.query().v('p-1') # Profile .out('bookmarked') # Listing .out('listingCategory').id().to_list() ) # Get listings of target profile ids expected_categories = ['c-1', 'c-2', 'c-1'] self.assertEqual(expected_categories, query_results)
def test_graph_recommendation(self): graph = GraphFactory.load_sample_profile_listing_graph() results = graph.algo().recommend_listings_for_profile('p-1') expected_results = [ ('l-5', 2), ('l-8', 1), ('l-7', 1), ('l-6', 1), ('l-4', 1) ] self.assertEqual(results, expected_results)
def test_graph_sample_profile_listing_in(self): graph = GraphFactory.load_sample_profile_listing_graph() self.assertEqual(str(graph), 'Graph(vertices: 15, edges: 23)') query_results = graph.query().v('l-1').id().to_list() expected_results = ['l-1'] self.assertEqual(query_results, expected_results) query_results = graph.query().v('l-1').in_('bookmarked').id().to_list() expected_results = ['p-1', 'p-2', 'p-3'] self.assertEqual(query_results, expected_results) query_results = graph.query().v('l-1', 'l-2', 'l-3').id().to_list() expected_results = ['l-1', 'l-2', 'l-3'] self.assertEqual(query_results, expected_results)
def test_graph_sample_profile_listing_side_effect(self): graph = GraphFactory.load_sample_profile_listing_graph() self.assertEqual(str(graph), 'Graph(vertices: 15, edges: 23)') profile_listing_categories_ids = [] query_results = (graph.query().v('p-1').out('bookmarked').side_effect( lambda current_vertex: [ profile_listing_categories_ids.append(current) for current in current_vertex.query().out('listingCategory').id().to_list() ]).id().to_list()) # Get listings of target profile ids expected_categories = ['c-1', 'c-2', 'c-1'] expected_listing = ['l-1', 'l-2', 'l-3'] self.assertEqual(expected_categories, profile_listing_categories_ids) self.assertEqual(expected_listing, query_results)