예제 #1
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
예제 #2
0
def test_gather_data():
    now = datetime.now().astimezone(timezone.utc)
    prof1, prof2, prof3, prof4, prof5, prof6, prof_too_old = [
        SocialProfileFactory(email=f'prof{i+1}@email.com') for i in range(7)
    ]
    prof_too_old.email = '*****@*****.**'
    prof_too_old.save()

    topic_channel_science = TopicChannelFactory(name='science')
    topic_channel_art = TopicChannelFactory(name='art')

    with freeze_time(now - timedelta(weeks=52), tz_offset=0):
        MatchRequestFactory(profile=prof_too_old)

    with freeze_time(now - timedelta(weeks=1), tz_offset=0):
        MatchRequestFactory(
            profile=prof1,
            topic_channel=topic_channel_art,
        )
        MatchRequestFactory(
            profile=prof1,
            topic_channel=topic_channel_science,
        )
        MatchRequestFactory(profile=prof2, topic_channel=topic_channel_art)
        MatchRequestFactory(profile=prof3, topic_channel=topic_channel_science)
        MatchRequestFactory(profile=prof4, topic_channel=topic_channel_science)

    with freeze_time(now - timedelta(weeks=3), tz_offset=0):
        MatchFactory(
            topic_channel=topic_channel_art,
            profiles=(prof1, prof2, prof3),
        )
        MatchFactory(
            topic_channel=topic_channel_science,
            profiles=(prof4, prof5),
        )
        MatchFactory(
            topic_channel=topic_channel_science,
            profiles=(prof6, prof_too_old),
        )

    match_maker = MatchMaker(match_request_since_date=now - timedelta(weeks=2))
    match_maker._gather_data()

    # _recent_match_by_profile_pair, _recent_match_by_profile_pair, and _recent_match_by_profile_pair_and_topic
    # are used to look up information useful in creating a score
    assert 'prof_too_old' not in set(
        chain(*set(match_maker._recent_match_by_profile_pair.keys())))
    assert set(match_maker._recent_match_by_profile_pair.keys()) == {
        key('*****@*****.**', '*****@*****.**'),
        # note that the meeting with 3 people got turned into 3 pairs here
        key('*****@*****.**', '*****@*****.**'),
        key('*****@*****.**', '*****@*****.**'),
        key('*****@*****.**', '*****@*****.**'),
    }
    assert match_maker._recent_match_by_profile_pair[key(
        '*****@*****.**', '*****@*****.**')]['num_attending'] == 3

    assert set(match_maker._recent_match_by_profile_topic) == {
        key('*****@*****.**', 'art'),
        key('*****@*****.**', 'art'),
        key('*****@*****.**', 'art'),
        key('*****@*****.**', 'science'),
        key('*****@*****.**', 'science'),
    }

    assert set(match_maker._recent_match_by_profile_pair_and_topic.keys()) == {
        key('*****@*****.**', '*****@*****.**', 'art'),
        key('*****@*****.**', '*****@*****.**', 'art'),
        key('*****@*****.**', '*****@*****.**', 'art'),
        key('*****@*****.**', '*****@*****.**', 'science'),
    }

    # _match_requests_profile_to_topic, _match_requests_topic_to_profile, and _possible_matches
    # are used largely as filters to quickly find topics for people, people for topics, and people that share a topic
    # respectively
    assert match_maker._match_requests_profile_to_topic == {
        '*****@*****.**': {'science', 'art'},
        '*****@*****.**': {'art'},
        '*****@*****.**': {'science'},
        '*****@*****.**': {'science'},
    }
    assert match_maker._match_requests_topic_to_profile == {
        'art': {'*****@*****.**', '*****@*****.**'},
        'science': {'*****@*****.**', '*****@*****.**', '*****@*****.**'},
    }
    assert match_maker._possible_matches == {
        '*****@*****.**':
        {'*****@*****.**', '*****@*****.**', '*****@*****.**'},
        '*****@*****.**': {'*****@*****.**'},
        '*****@*****.**': {'*****@*****.**', '*****@*****.**'},
        '*****@*****.**': {'*****@*****.**', '*****@*****.**'},
    }