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
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
def test_get_subscribed_users_multiple(database, fake_user): subscription2 = MeetingSubscription(title='test1').put() subscribed_users = get_subscribers() assert len(subscribed_users) == 2 assert subscribed_users[subscription2.urlsafe()] == [] assert subscribed_users[database.sub.key.urlsafe()] == ['*****@*****.**']
def test_get_metrics_multiple(app, database, subscription, fake_user): with app.test_request_context('/v1/metrics'): response = json.loads(metrics_api()) assert len(response) == 1 response = response[0] assert response['key'] == database.sub.key.urlsafe() assert response['subscribed'] == ['*****@*****.**'] assert response['title'] == database.sub.title assert response['week_participants'] == 1 new_subscription = MeetingSubscription(title='test1') new_subscription.put() with app.test_request_context('/v1/metrics'): response = json.loads(metrics_api()) assert len(response) == 2 assert response[0]['key'] == database.sub.key.urlsafe() assert response[0]['subscribed'] == [fake_user.email] assert response[0]['title'] == database.sub.title assert response[0]['week_participants'] == 1 assert response[1]['key'] == new_subscription.key.urlsafe() assert response[1]['subscribed'] == [] assert response[1]['title'] == new_subscription.title assert response[1]['week_participants'] == 0
def test_get_metrics(app, minimal_database): with app.test_request_context('/v1/metrics'): response = metrics_api() assert response == '[]' new_subscription = MeetingSubscription(title='test1') new_subscription.put() with app.test_request_context('/v1/metrics'): response = json.loads(metrics_api()) assert response[0]["title"] == new_subscription.title assert response[0]["key"] == new_subscription.key.urlsafe() assert response[0]["week_participants"] == 0 assert response[0]["subscribed"] == []
def test_get_previous_meetings_multi_subscription(minimal_database): pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() subscription1 = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() subscription2 = MeetingSubscription(title='all sales weekly', datetime=[pref_1]).put() user_pref1 = UserSubscriptionPreferences(preference=pref_1, subscription=subscription1).put() user_pref2 = UserSubscriptionPreferences(preference=pref_1, subscription=subscription2).put() user1 = User(email='*****@*****.**', metadata={'department': 'dept'}, subscription_preferences=[user_pref1, user_pref2]).put() user2 = User(email='*****@*****.**', metadata={'department': 'dept2'}, subscription_preferences=[user_pref1, user_pref2]).put() meeting_spec1 = MeetingSpec(meeting_subscription=subscription1, datetime=pref_1.get().datetime).put() meeting = Meeting(meeting_spec=meeting_spec1, cancelled=False).put() MeetingParticipant(meeting=meeting, user=user2).put() MeetingParticipant(meeting=meeting, user=user1).put() assert get_previous_meetings(subscription1) == set([(user1.id(), user2.id())]) assert get_previous_meetings(subscription2) == set([])
def test_get_user_weights(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() previous_meetings_count = get_previous_meetings_counts( [user1.get(), user2.get()], subscription) assert (get_user_weights([user1.get(), user2.get()], previous_meetings_count, 10, 5) == [[0, 5], [5, 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)]
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)
def _fake_user(): user_list = [] subscription = MeetingSubscription.query().get() for user in FAKE_USER: preferences = UserSubscriptionPreferences( preference=subscription.datetime[0], subscription=subscription.key, ).put() user_entity = User( first_name=user['first_name'], last_name=user['last_name'], email=user['email'], photo_url=user['photo_url'], metadata={ 'department': user['department'], 'office': 'USA: CA SF New Montgomery Office', 'company_profile_url': 'https://www.yelp.com/user_details?userid=nkN_do3fJ9xekchVC-v68A', }, subscription_preferences=[preferences], ) user_entity.put() user_list.append(user_entity) return user_list[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
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_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_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 == []
def test_get_previous_meetings_no_specs(database_no_specs): 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([])
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 merge_subscriptions_with_preferences(user): user_preferences = [{ 'subscription_id': user_subscription.get().subscription.urlsafe(), 'datetime_id': user_subscription.get().preference.urlsafe() } for user_subscription in user.subscription_preferences] subscriptions = [{ 'id': subscription.key.urlsafe(), 'title': subscription.title, 'office': subscription.office, 'location': subscription.location, 'size': subscription.size, 'timezone': subscription.timezone, 'rule_logic': subscription.rule_logic, 'datetime': get_subscription_dates(subscription), } for subscription in MeetingSubscription.query().fetch()] for subscription in subscriptions: for user_preference in user_preferences: if subscription['id'] == user_preference['subscription_id']: for date in subscription['datetime']: if date['id'] == user_preference['datetime_id']: date['active'] = True return subscriptions
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)])
def test_get_subscribed_users_multiple(database, fake_user, session): subscription2 = MeetingSubscription(title='test1') session.add(subscription2) session.commit() subscribed_users = get_subscribers() assert len(subscribed_users) == 2 assert subscribed_users[subscription2.id] == [] assert subscribed_users[database.sub.id] == ['*****@*****.**']
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
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
def create_dev_data(): email = FAKE_USER[0]['email'] user = User.query(User.email == email).get() if not user: _subscription() time.sleep(2) _fake_user() subscription = MeetingSubscription.query().get() week_start, specs = get_specs_from_subscription(subscription) store_specs_from_subscription(subscription.key, week_start, specs) logging.info('generated fake date for dev')
def meeting_subscribers(): metrics = [] subscribed_users = get_subscribers() subscriptions = MeetingSubscription.query().fetch() for subscription in subscriptions: subscribed = set(subscribed_users[subscription.key.urlsafe()]) for subscriber in subscribed: metrics.append({ 'title': subscription.title, 'subscriber': subscriber, }) return json.dumps(metrics)
def get_subscribers(): users = User.query().fetch() subscriptions = MeetingSubscription.query().fetch() metrics = defaultdict(set) # creates metrics keys for all subscriptions including ones without users for subscription in subscriptions: metrics[subscription.key.urlsafe()] = [] # creates metrics keys for all subscriptions that have users with user data for user in users: for preference in user.subscription_preferences: metrics[preference.get().subscription.urlsafe()].append(user.email) return metrics
def test_get_metrics(app, minimal_database): with app.test_request_context('/v1/metrics'): response = metrics_api() assert response == '[]' MeetingSubscription(title='test1').put() with app.test_request_context('/v1/metrics'): response = metrics_api() assert response == json.dumps([{ "meetings": 0, "subscribed": 0, "title": "test1", }])
def test_get_metrics_multiple(app, database, subscription, fake_user): with app.test_request_context('/v1/metrics'): response = metrics_api() assert response == json.dumps([{ "meetings": 0, "subscribed": 1, "title": "Yelp Weekly", }]) MeetingSubscription(title='test1').put() with app.test_request_context('/v1/metrics'): response = metrics_api() assert response == json.dumps([ {"meetings": 0, "subscribed": 1, "title": "Yelp Weekly"}, {"meetings": 0, "subscribed": 0, "title": "test1"} ])
def metrics_api(): keys_only = ndb.QueryOptions(keys_only=True) meeting_subscriptions = MeetingSubscription.query().fetch() metrics = [] for subscription in meeting_subscriptions: data = { 'title': subscription.title, 'subscribed': UserSubscriptionPreferences.query( UserSubscriptionPreferences.subscription == subscription.key).count(options=keys_only), 'meetings': Meeting.query().count(options=keys_only), } metrics.append(data) return json.dumps(metrics)
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)
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_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