def test_get_previous_meetings(minimal_database): pref_1 = SubscriptionDateTime( datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() user1 = User(email='*****@*****.**', metadata={ 'department': 'dept' }, subscription_preferences=[user_pref]).put() user2 = User(email='*****@*****.**', metadata={ 'department': 'dept2' }, subscription_preferences=[user_pref]).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime).put() meeting = Meeting(meeting_spec=meeting_spec, cancelled=False).put() MeetingParticipant(meeting=meeting, user=user2).put() MeetingParticipant(meeting=meeting, user=user1).put() assert get_previous_meetings() == set([(user1.id(), user2.id())])
def test_no_re_matches(minimal_database): pref_1 = SubscriptionDateTime( datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) meeting_spec.put() users = [] num_users = 20 for i in range(0, num_users): user = User(email='{}@yelp.com'.format(i), metadata={'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref]) user.put() MeetingRequest(user=user.key, meeting_spec=meeting_spec.key).put() users.append(user) previous_meetings = { pair for pair in itertools.combinations([user.key.id() for user in users], 2) } previous_meetings = previous_meetings - { (users[0].key.id(), users[1].key.id()) } matches, unmatched = generate_meetings(users, meeting_spec, previous_meetings) assert len(unmatched) == num_users - 2 assert [(match[0].key.id(), match[1].key.id()) for match in matches] == [(users[0].key.id(), users[1].key.id())]
def test_generate_save_meetings(minimal_database, subscription): pref_1 = SubscriptionDateTime( datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() user1 = User(email='*****@*****.**', metadata={ 'department': 'dept' }, subscription_preferences=[user_pref]).put() user2 = User(email='*****@*****.**', metadata={ 'department': 'dept2' }, subscription_preferences=[user_pref]).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) meeting_spec.put() MeetingRequest(user=user1, meeting_spec=meeting_spec.key).put() MeetingRequest(user=user2, meeting_spec=meeting_spec.key).put() matches, unmatched = generate_meetings( [user1.get(), user2.get()], meeting_spec) save_meetings(matches, meeting_spec) assert unmatched == [] participants = [ participant.user for participant in MeetingParticipant.query().fetch() ] assert participants == [user1, user2]
def test_generate_group_meetings(): pref_1 = SubscriptionDateTime( datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() user1 = User(email='*****@*****.**', metadata={ 'department': 'dept' }, subscription_preferences=[user_pref]).put() user2 = User(email='*****@*****.**', metadata={ 'department': 'dept2' }, subscription_preferences=[user_pref]).put() user3 = User(email='*****@*****.**', metadata={ 'department': 'dept3' }, subscription_preferences=[user_pref]).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime).put() meeting = Meeting(meeting_spec=meeting_spec, cancelled=False).put() MeetingParticipant(meeting=meeting, user=user3).put() MeetingParticipant(meeting=meeting, user=user2).put() MeetingParticipant(meeting=meeting, user=user1).put() matched, unmatched = generate_group_meetings( [user1.get(), user2.get(), user3.get()], meeting_spec.get(), 3, 10, 5) assert {user.key for user in matched[0]} == {user1, user2, user3} assert unmatched == []
def test_previous_meeting_penalty(minimal_database): pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() pref_2 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 2)).put() pref_3 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 3)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1, pref_2, pref_3]).put() user_pref1 = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() user_pref2 = UserSubscriptionPreferences(preference=pref_2, subscription=subscription).put() user_pref3 = UserSubscriptionPreferences(preference=pref_3, subscription=subscription).put() meeting_spec1 = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) meeting_spec1.put() meeting_spec2 = MeetingSpec(meeting_subscription=subscription, datetime=pref_2.get().datetime) meeting_spec2.put() meeting_spec3 = MeetingSpec(meeting_subscription=subscription, datetime=pref_3.get().datetime) meeting_spec3.put() users = [] num_users = 20 for i in range(0, num_users): user = User(email='{}@yelp.com'.format(i), metadata={ 'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref1, user_pref2, user_pref3]) user.put() MeetingRequest(user=user.key, meeting_spec=meeting_spec1.key).put() MeetingRequest(user=user.key, meeting_spec=meeting_spec2.key).put() MeetingRequest(user=user.key, meeting_spec=meeting_spec3.key).put() users.append(user) meeting1 = Meeting(meeting_spec=meeting_spec1.key, cancelled=False).put() MeetingParticipant(meeting=meeting1, user=users[1].key).put() MeetingParticipant(meeting=meeting1, user=users[0].key).put() meeting2 = Meeting(meeting_spec=meeting_spec2.key, cancelled=False).put() MeetingParticipant(meeting=meeting2, user=users[1].key).put() MeetingParticipant(meeting=meeting2, user=users[0].key).put() meeting3 = Meeting(meeting_spec=meeting_spec3.key, cancelled=False).put() MeetingParticipant(meeting=meeting3, user=users[1].key).put() MeetingParticipant(meeting=meeting3, user=users[0].key).put() for run in range(10): matches, unmatched = generate_meetings(users, meeting_spec1, prev_meeting_tuples=None, group_size=3) assert(len(matches) == 6) assert (len(unmatched) == 2) for matched_group in matches: assert(not (users[0] in matched_group and users[1] in matched_group))
def test_generate_group_meeting_invalid_number_of_users(minimal_database): pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) meeting_spec.put() users = [] for i in range(0, 2): user = User(email='{}@yelp.com'.format(i), metadata={ 'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref]) user.put() MeetingRequest(user=user.key, meeting_spec=meeting_spec.key).put() users.append(user) matches, unmatched = generate_meetings(users, meeting_spec, prev_meeting_tuples=None, group_size=3) assert(len(matches) == 0) assert (len(unmatched) == 2)