Пример #1
0
def test_match_unmatched(mocker):
    # scenario: assume that the matches are A+B in the topic of 'math' and C+D in the topic of 'history', and E and F are
    # unmatched. E is a _possible_match with A or C in the topic of 'math' and F is a _possible_match with A or C in the
    # topic of 'history' therefore the final matching should be A+B+E in 'math' and C+D+F in 'history'
    match_maker = MatchMaker(match_request_since_date='does not matter')
    matches = [['A', 'B'], ['C', 'D']]

    def mock_pair_score_and_topic(p1, p2):
        return {
            key('A', 'B'): (1, 'math'),
            key('C', 'D'): (1, 'history'),
        }[key(p1, p2)]

    match_maker._pair_score_and_topic = mocker.Mock()
    match_maker._pair_score_and_topic.side_effect = mock_pair_score_and_topic
    match_maker._match_requests_profile_to_topic = {
        'A': ['math'],
        'B': ['math'],
        'C': ['history'],
        'D': ['history'],
        'E': ['math'],
        'F': ['history'],
    }
    match_maker._possible_matches = {
        'E': ['A', 'C'],
        'F': ['A', 'C'],
        # really the other keys would be here, but the method wouldn't currently call them
    }
    matches = match_maker._match_unmatched(matches)
    matches = set(
        key(*m) for m in matches
    )  # convert to set of sorted tuples so that ordering doesn't matter
    assert matches == {key('A', 'B', 'E'), key('C', 'D', 'F')}
Пример #2
0
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'