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_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 )