Exemple #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')}
Exemple #2
0
def test_run(mocker):
    # just make sure everything is wired up
    match_maker = MatchMaker(match_request_since_date='does not matter')
    match_maker._gather_data = mocker.Mock()
    match_maker._get_matches = mocker.Mock()
    match_maker._get_matches.return_value = "a"
    match_maker._match_unmatched = mocker.Mock()
    match_maker._match_unmatched.side_effect = lambda x: x + 'b'
    match_maker._add_topics_to_matches = mocker.Mock()
    match_maker._add_topics_to_matches.side_effect = lambda x: x + 'c'

    matches = match_maker.run()
    assert matches == "abc"
    assert match_maker._gather_data.called