Beispiel #1
0
def _subscription():
    zone = 'US/Pacific'
    preference_1 = SubscriptionDateTime(
        datetime=datetime(2017, 1, 20, 23, 0, tzinfo=utc))
    # Easier to think/verify in Pacific time since we are based in SF
    assert preference_1.datetime.astimezone(timezone(zone)).hour == 15
    preference_1.datetime = preference_1.datetime.replace(tzinfo=None)
    preference_1.put()

    preference_2 = SubscriptionDateTime(
        datetime=datetime(2017, 1, 20, 19, 0, tzinfo=utc))
    # Easier to think/verify in Pacific time since we are based in SF
    assert preference_2.datetime.astimezone(timezone(zone)).hour == 11
    preference_2.datetime = preference_2.datetime.replace(tzinfo=None)
    preference_2.put()

    rule = Rule(name='office', value='USA: CA SF New Montgomery Office').put()

    subscription = MeetingSubscription(
        title='Yelp Weekly',
        size=2,
        location='8th Floor',
        office='USA: CA SF New Montgomery Office',
        timezone=zone,
        datetime=[preference_1.key, preference_2.key],
        rules=[rule])
    subscription.put()
    return subscription
Beispiel #2
0
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 == []
Beispiel #3
0
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())]
Beispiel #4
0
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())])
Beispiel #5
0
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]
Beispiel #6
0
def test_get_previous_meetings(session):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() -
                                  timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    subscription = MeetingSubscription(title='all engineering weekly',
                                       datetime=[pref_1])
    user_pref = UserSubscriptionPreferences(preference=pref_1,
                                            subscription=subscription)
    user1 = User(email='*****@*****.**',
                 meta_data={'department': 'dept'},
                 subscription_preferences=[user_pref])
    user2 = User(email='*****@*****.**',
                 meta_data={'department': 'dept2'},
                 subscription_preferences=[user_pref])
    meeting_spec = MeetingSpec(meeting_subscription=subscription,
                               datetime=pref_1.datetime)
    meeting = Meeting(meeting_spec=meeting_spec, cancelled=False)
    mp1 = MeetingParticipant(meeting=meeting, user=user2)
    mp2 = MeetingParticipant(meeting=meeting, user=user1)

    session.add(pref_1)
    session.add(subscription)
    session.add(user_pref)
    session.add(user1)
    session.add(user2)
    session.add(meeting_spec)
    session.add(meeting)
    session.add(mp1)
    session.add(mp2)
    session.commit()

    assert get_previous_meetings(subscription) == set([(user1.id, user2.id)])
Beispiel #7
0
def test_no_re_matches(session):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1])
    user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription)
    meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.datetime)
    session.add(pref_1)
    session.add(subscription)
    session.add(user_pref)
    session.add(meeting_spec)

    users = []
    num_users = 20
    for i in range(0, num_users):
        user = User(email='{}@yelp.com'.format(i), meta_data={
                    'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref])
        session.add(user)
        mr = MeetingRequest(user=user, meeting_spec=meeting_spec)
        session.add(mr)
        users.append(user)
    session.commit()

    previous_meetings = {pair for pair in itertools.combinations([user.id for user in users], 2)}
    previous_meetings = previous_meetings - {(users[0].id, users[1].id)}
    matches, unmatched = generate_meetings(users, meeting_spec, previous_meetings)
    assert len(unmatched) == num_users - 2
    assert [(match[0].id, match[1].id) for match in matches] == [(users[0].id, users[1].id)]
Beispiel #8
0
def test_generate_group_meeting(session):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1])
    user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription)
    meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.datetime)
    session.add(pref_1)
    session.add(subscription)
    session.add(user_pref)
    session.add(meeting_spec)

    users = []
    num_users = 21
    for i in range(0, num_users):
        user = User(email='{}@yelp.com'.format(i), meta_data={
                    'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref])
        session.add(user)
        mr = MeetingRequest(user=user, meeting_spec=meeting_spec)
        session.add(mr)
        users.append(user)

    session.commit()
    matches, unmatched = generate_meetings(users, meeting_spec, prev_meeting_tuples=None, group_size=3)
    assert(len(matches) == 7)
    assert (len(unmatched) == 0)
    matches, unmatched = generate_meetings(users, meeting_spec, prev_meeting_tuples=None, group_size=5)
    assert(len(matches) == 4)
    assert (len(unmatched) == 1)
Beispiel #9
0
def test_generate_group_meetings(session):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1])
    user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription)
    user1 = User(email='*****@*****.**', meta_data={'department': 'dept'}, subscription_preferences=[user_pref])
    user2 = User(email='*****@*****.**', meta_data={'department': 'dept2'}, subscription_preferences=[user_pref])
    user3 = User(email='*****@*****.**', meta_data={'department': 'dept3'}, subscription_preferences=[user_pref])
    meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.datetime)
    meeting = Meeting(meeting_spec=meeting_spec, cancelled=False)
    mp1 = MeetingParticipant(meeting=meeting, user=user3)
    mp2 = MeetingParticipant(meeting=meeting, user=user2)
    mp3 = MeetingParticipant(meeting=meeting, user=user1)

    session.add(pref_1)
    session.add(subscription)
    session.add(user_pref)
    session.add(user1)
    session.add(user2)
    session.add(user3)
    session.add(meeting_spec)
    session.add(meeting)
    session.add(mp1)
    session.add(mp2)
    session.add(mp3)
    session.commit()

    matched, unmatched = generate_group_meetings([user1, user2, user3], meeting_spec, 3, 10, 5)
    assert {user for user in matched[0]} == {user1, user2, user3}
    assert unmatched == []
Beispiel #10
0
def test_get_specs_from_subscription_pdt(minimal_database):
    preference = SubscriptionDateTime(
        datetime=datetime(2017, 1, 20, 13, 0)).put()
    subscription = MeetingSubscription(timezone='America/Los_Angeles',
                                       datetime=[preference]).put()
    _, specs = get_specs_from_subscription(subscription.get())
    assert get_meeting_datetime(specs[0]).hour == 13
Beispiel #11
0
def test_get_specs_from_subscription_pdt(session):
    preference = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0))
    session.add(preference)
    subscription = MeetingSubscription(timezone='America/Los_Angeles',
                                       datetime=[preference])
    session.add(subscription)
    session.commit()
    _, specs = get_specs_from_subscription(subscription)
    assert get_meeting_datetime(specs[0]).hour == 13
Beispiel #12
0
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)
Beispiel #13
0
def _subscription(session):
    zone = 'America/Los_Angeles'
    preference_1 = SubscriptionDateTime(
        datetime=datetime(2017, 1, 20, 23, 0, tzinfo=utc))
    # Easier to think/verify in Pacific time since we are based in SF
    assert preference_1.datetime.astimezone(timezone(zone)).hour == 15
    preference_1.datetime = preference_1.datetime.replace(tzinfo=None)
    session.add(preference_1)

    preference_2 = SubscriptionDateTime(
        datetime=datetime(2017, 1, 20, 19, 0, tzinfo=utc))
    # Easier to think/verify in Pacific time since we are based in SF
    assert preference_2.datetime.astimezone(timezone(zone)).hour == 11
    preference_2.datetime = preference_2.datetime.replace(tzinfo=None)
    session.add(preference_2)

    rule = Rule(name='office', value='USA: CA SF New Montgomery Office')
    session.add(rule)

    subscription = MeetingSubscription(
        title='Yelp Weekly',
        size=2,
        location='8th Floor',
        office='USA: CA SF New Montgomery Office',
        timezone=zone,
        datetime=[preference_1, preference_2],
        user_rules=[rule])
    session.add(subscription)
    session.commit()
    return subscription
Beispiel #14
0
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))
Beispiel #15
0
def _subscription():
    zone = 'America/Los_Angeles'
    preference_1 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0))
    preference_1.put()

    preference_2 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 11, 0))
    preference_2.put()

    rule = Rule(name='office', value='USA: CA SF New Montgomery Office').put()

    subscription = MeetingSubscription(
        title='Yelp Weekly',
        size=2,
        location='8th Floor',
        office='USA: CA SF New Montgomery Office',
        timezone=zone,
        datetime=[preference_1.key, preference_2.key],
        user_rules=[rule])
    subscription.put()
    return subscription
Beispiel #16
0
def test_clean_user_subscriptions(session):
    preference = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 23, 0))
    subscription = MeetingSubscription(
        title='Test Weekly',
        size=2,
        location='8th Floor',
        office='USA: CA SF New Montgomery Office',
        timezone='America/Los_Angeles',
        datetime=[preference],
        user_rules=[Rule(name='department', value='dept')],
        rule_logic='all',
    )
    user_1 = User(
        email="*****@*****.**",
        meta_data={'department': 'dept'},
        subscription_preferences=[
            UserSubscriptionPreferences(preference=preference,
                                        subscription=subscription)
        ],
    )
    # Should be removed because of incorrect department
    user_2 = User(
        email="*****@*****.**",
        meta_data={'department': 'other dept'},
        subscription_preferences=[
            UserSubscriptionPreferences(preference=preference,
                                        subscription=subscription)
        ],
    )

    session.add(subscription)
    session.add(user_1)
    session.add(user_2)
    session.commit()

    response = clean_user_subscriptions()
    assert response == 'OK'

    user_sub_prefs = UserSubscriptionPreferences.query.all()
    assert len(user_sub_prefs) == 1
Beispiel #17
0
def test_generate_save_meetings(session, subscription):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() -
                                  timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    subscription = MeetingSubscription(title='all engineering weekly',
                                       datetime=[pref_1])
    user_pref = UserSubscriptionPreferences(preference=pref_1,
                                            subscription=subscription)
    user1 = User(email='*****@*****.**',
                 meta_data={'department': 'dept'},
                 subscription_preferences=[user_pref])
    user2 = User(email='*****@*****.**',
                 meta_data={'department': 'dept2'},
                 subscription_preferences=[user_pref])
    meeting_spec = MeetingSpec(meeting_subscription=subscription,
                               datetime=pref_1.datetime)
    mr1 = MeetingRequest(user=user1, meeting_spec=meeting_spec)
    mr2 = MeetingRequest(user=user2, meeting_spec=meeting_spec)

    session.add(pref_1)
    session.add(subscription)
    session.add(user_pref)
    session.add(user1)
    session.add(user2)
    session.add(meeting_spec)
    session.add(mr1)
    session.add(mr2)
    session.commit()

    matches, unmatched = generate_meetings([user1, user2], meeting_spec)
    save_meetings(matches, meeting_spec)

    assert unmatched == []

    participants = [
        participant.user for participant in MeetingParticipant.query.all()
    ]

    assert participants == [user1, user2]
Beispiel #18
0
def test_previous_meeting_penalty(session):
    pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1))
    pref_2 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 2))
    pref_3 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 3))
    subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1, pref_2, pref_3])
    user_pref1 = UserSubscriptionPreferences(preference=pref_1, subscription=subscription)
    user_pref2 = UserSubscriptionPreferences(preference=pref_2, subscription=subscription)
    user_pref3 = UserSubscriptionPreferences(preference=pref_3, subscription=subscription)
    meeting_spec1 = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.datetime)
    meeting_spec2 = MeetingSpec(meeting_subscription=subscription, datetime=pref_2.datetime)
    meeting_spec3 = MeetingSpec(meeting_subscription=subscription, datetime=pref_3.datetime)
    session.add(pref_1)
    session.add(pref_2)
    session.add(pref_3)
    session.add(subscription)
    session.add(user_pref1)
    session.add(user_pref2)
    session.add(user_pref3)
    session.add(meeting_spec1)
    session.add(meeting_spec2)
    session.add(meeting_spec3)

    users = []
    num_users = 20
    for i in range(0, num_users):
        user = User(email='{}@yelp.com'.format(i), meta_data={
                    'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref1, user_pref2, user_pref3])
        session.add(user)
        mr1 = MeetingRequest(user=user, meeting_spec=meeting_spec1)
        mr2 = MeetingRequest(user=user, meeting_spec=meeting_spec2)
        mr3 = MeetingRequest(user=user, meeting_spec=meeting_spec3)
        session.add(mr1)
        session.add(mr2)
        session.add(mr3)
        users.append(user)

    meeting1 = Meeting(meeting_spec=meeting_spec1, cancelled=False)
    mp1 = MeetingParticipant(meeting=meeting1, user=users[1])
    mp2 = MeetingParticipant(meeting=meeting1, user=users[0])
    session.add(meeting1)
    session.add(mp1)
    session.add(mp2)

    meeting2 = Meeting(meeting_spec=meeting_spec2, cancelled=False)
    mp1 = MeetingParticipant(meeting=meeting2, user=users[1])
    mp2 = MeetingParticipant(meeting=meeting2, user=users[0])
    session.add(meeting2)
    session.add(mp1)
    session.add(mp2)

    meeting3 = Meeting(meeting_spec=meeting_spec3, cancelled=False)
    mp1 = MeetingParticipant(meeting=meeting3, user=users[1])
    mp2 = MeetingParticipant(meeting=meeting3, user=users[0])
    session.add(meeting3)
    session.add(mp1)
    session.add(mp2)

    session.commit()

    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))