예제 #1
0
def test_get_matches(mocker):
    # Given these possible connections where every pair is scored 1, there is only one matching that scores
    # as high as 2, we better get that!
    #
    #    A---B
    #     \ /
    #      C
    #      |
    #      D

    match_maker = MatchMaker(match_request_since_date='does not matter')
    match_maker._pair_score_and_topic = mocker.Mock()
    match_maker._pair_score_and_topic.return_value = (1, 'history')

    match_maker._possible_matches = {
        'A': ['B', 'C'],
        'B': ['A', 'C'],
        'C': ['A', 'B', 'D'],
        'D': ['C'],
    }
    matches = match_maker._get_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'), key('C', 'D')}
    for forbidden_call in [
            call('D', 'A'),
            call('A', 'D'),
            call('D', 'B'),
            call('B', 'D')
    ]:
        assert forbidden_call not in match_maker._pair_score_and_topic.call_args_list, \
            "we should not make score calls for pairs that aren't in _possible_matches (very inefficient)"
예제 #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