def test_not_memoized_pair_score_and_topic(): match_maker = MatchMaker(match_request_since_date='does not matter') now = datetime.now().astimezone(timezone.utc) match_maker._recent_match_by_profile_pair = { key('A', 'B'): { 'date': now - timedelta(weeks=20) }, } match_maker._most_recent_match_by_profile = { key('A'): { 'date': now - timedelta(weeks=20) }, key('B'): { 'date': now - timedelta(weeks=20) }, } match_maker._recent_match_by_profile_pair_and_topic = { key('A', 'B', 'science'): { 'date': now - timedelta(weeks=10) }, key('A', 'B', 'art'): { 'date': now - timedelta(weeks=20) }, } match_maker._match_requests_profile_to_topic = { 'A': {'science', 'art', 'history'}, 'B': {'science', 'art', 'religion'}, } score, topic = match_maker._not_memoized_pair_score_and_topic('A', 'B') assert score > 0 assert score != int( score ), "score is a whole number, that's unlikely if we're really exercising the functionality" assert topic == 'art'
def test_pair_score_and_topic__is_memoized(mocker): match_maker = MatchMaker(match_request_since_date='does not matter') match_maker._not_memoized_pair_score_and_topic = mocker.Mock() match_maker._not_memoized_pair_score_and_topic.return_value = 'output' # intentionally call this multiple times and assert that _not_memoized is called once assert match_maker._pair_score_and_topic('profile_1', 'profile_2') == 'output' assert match_maker._pair_score_and_topic('profile_1', 'profile_2') == 'output' assert match_maker._pair_score_and_topic('profile_2', 'profile_1') == 'output' assert match_maker._not_memoized_pair_score_and_topic.call_count == 1 assert match_maker._pair_score_and_topic('profile_1', 'profile_999') == 'output' assert match_maker._not_memoized_pair_score_and_topic.call_count == 2