def test_no_entities(self): target = Target("content") target.get_content_list_response = Mock() target.get_content_list_response.side_effect = [ [], [ { "_id": "1", "score": 1 }, { "_id": "2", "score": 1 } ], [ { "_id": "1", "score": 1 }, { "_id": "2", "score": 1 } ] ] actual = target.score_items( { "entities": [] } ) self.assertDictEqual( actual, {} )
def test_has_scores(self): content = Mock() target = Target(content) target.get_reason_summary = Mock() target.get_reason_summary.return_value = "reason_summary_value" target.weight_item_scores = Mock() target.weight_item_scores.return_value = "weighted_scores_value" target.score_items = Mock() target.score_items.return_value = ["score_1", "score_2"] target.sort_items = Mock() target.sort_items.return_value = "sort_scores_value" actual = target.create_suggestion_items("context") self.assertEqual("weighted_scores_value", actual) self.assertEqual(1, target.score_items.call_count) self.assertEqual("context", target.score_items.call_args_list[0][0][0]) self.assertEqual(1, target.weight_item_scores.call_count) self.assertEqual('sort_scores_value', target.weight_item_scores.call_args_list[0][0][0]) self.assertEqual(1, target.sort_items.call_count) self.assertEqual(["score_1", "score_2"], target.sort_items.call_args_list[0][0][0])
def test_none_response_for_one_entity(self): target = Target("content") target.get_content_list_response = Mock() target.get_content_list_response.side_effect = [ [ { "_id": ObjectId("55d39f1c7d391b49e1569fa1"), "score": 100 }, { "_id": ObjectId("55d39f1c7d391b49e1569fa2"), "score": 100 } ], None, [ { "_id": ObjectId("55d39f1c7d391b49e1569fa1"), "score": 50 }, { "_id": ObjectId("55d39f1c7d391b49e1569fa4"), "score": 100 } ], [ { "_id": ObjectId("55d39f1c7d391b49e1569fa3"), "score": 100 }, { "_id": ObjectId("55d39f1c7d391b49e1569fa2"), "score": 20 } ] ] actual = target.score_items( { "entities": [ { "type": "color", "key": "black", "weighting": 60.0 }, { "type": "color", "key": "no_data", "weighting": 60.0 } ] } ) self.assertDictEqual( { ObjectId("55d39f1c7d391b49e1569fa1"): { "_id": ObjectId("55d39f1c7d391b49e1569fa1"), 'reasons': [ { 'key': 'black', 'score': 60.0, 'type': 'color', 'raw_score': 100, 'weighting': 60.0 }, { 'raw_score': 50, 'score': 3.912023005428146, 'type': 'popular' } ], 'score': 63.912023005428146 }, ObjectId("55d39f1c7d391b49e1569fa2"): { "_id": ObjectId("55d39f1c7d391b49e1569fa2"), 'reasons': [ { 'key': 'black', 'score': 60.0, 'type': 'color', 'raw_score': 100, 'weighting': 60.0 }, { 'raw_score': 20, 'score': 2.995732273553991, 'type': 'popular' } ], 'score': 62.99573227355399 } }, actual )