Esempio n. 1
0
 def test_reminders(self):
     user_datas = {
         'userA': sample_userA,
         'userB': sample_userB,
     }
     user_ids, user_headers = self.create_users(user_datas)
     searchA_id, searchB_id = self.create_searches(user_ids, user_headers)
     conversation_data = self.make_conversation(
         user_headers['userA'], search_id=searchA_id, title='Trip to moon.',
         userA_id=user_ids['userA'], userB_id=user_ids['userB'])
     conversation_id = conversation_data['id']
     share_data = self.make_share(
         user_headers['userA'], conversation_id,
         educator_user_id=user_ids['userA'],
         community_partner_user_id=user_ids['userB'],
         starting_in_hours=0.5)
     mailer = mail.get_mailer()
     while mailer.queue:
         mailer.pop()
     events = EventReminder.get_oneday_reminder_events()
     assert(len(events) == 1)
     worker.work_loop(target_time_between_calls=datetime.timedelta(seconds=1),
                      max_loops=2)
     events = EventReminder.get_oneday_reminder_events()
     assert(len(events) == 0)
     # Two reminder emails should have been sent.
     assert(len(mailer.queue) == 2)
     email1 = mailer.pop()
     email2 = mailer.pop()
     expected_email_addresses = set([sample_userA['email'], sample_userB['email']])
     rcvd_email_addresses = set([email1.to_address, email2.to_address])
     assert(expected_email_addresses == rcvd_email_addresses)
Esempio n. 2
0
 def test_reminders(self):
     user_datas = {
         'userA': sample_userA,
         'userB': sample_userB,
     }
     user_ids, user_headers = self.create_users(user_datas)
     searchA_id, searchB_id = self.create_searches(user_ids, user_headers)
     conversation_data = self.make_conversation(
         user_headers['userA'],
         search_id=searchA_id,
         title='Trip to moon.',
         userA_id=user_ids['userA'],
         userB_id=user_ids['userB'],
     )
     conversation_id = conversation_data['id']
     share_data = self.make_share(
         user_headers['userA'],
         conversation_id,
         educator_user_id=user_ids['userA'],
         community_partner_user_id=user_ids['userB'],
         starting_in_hours=0.5,
     )
     mailer = mail.get_mailer()
     while mailer.queue:
         mailer.pop()
     events = EventReminder.get_oneday_reminder_events()
     self.assertEqual(len(events), 1)
     worker.work_loop(
         target_time_between_calls=datetime.timedelta(seconds=1),
         max_loops=2)
     events = EventReminder.get_oneday_reminder_events()
     self.assertEqual(len(events), 0)
     # Two reminder emails should have been sent.
     self.assertEqual(len(mailer.queue), 2)
     email1 = mailer.pop()
     email2 = mailer.pop()
     expected_email_addresses = set(
         [sample_userA['email'], sample_userB['email']])
     rcvd_email_addresses = set([email1.to_address, email2.to_address])
     self.assertEqual(expected_email_addresses, rcvd_email_addresses)
Esempio n. 3
0
#! /usr/bin/python3

import os
import logging
import argparse

from community_share import worker, config

logger = logging.getLogger(__name__)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    default_pid_dir = os.path.join('var', 'run', 'cs_worker')
    parser.add_argument('--pid-dir', dest='pid_dir', default=default_pid_dir)
    args = parser.parse_args()
    if args.pid_dir is not None:
        pid = str(os.getpid())
        with open(os.path.join(args.pid_dir, 'cs_worker.pid'), 'w') as f:
            f.write(pid)
    config.load_config('./config.production.json')
    logger.info('Starting community share worker.')
    worker.work_loop()
Esempio n. 4
0
 def test_user_review(self):
     user_datas = {
         'userA': sample_userA,
         'userB': sample_userB,
         'userC': sample_userC,
     }
     user_ids, user_headers = self.create_users(user_datas)
     searchA_id, searchB_id = self.create_searches(user_ids, user_headers)
     conversation_data = self.make_conversation(
         user_headers['userA'], search_id=searchA_id, title='Trip to moon.',
         userA_id=user_ids['userA'], userB_id=user_ids['userB'])
     conversation_id = conversation_data['id']
     share_data = self.make_share(
         user_headers['userA'], conversation_id,
         educator_user_id=user_ids['userA'],
         community_partner_user_id=user_ids['userB'],
         starting_in_hours=0.5, force_past_events=False)
     # We shouldn't be able to save a review for the current event
     # because it is in the future
     share_id = share_data['id']
     eventA_id = share_data['events'][0]['id']
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userA'],
         'rating': 3,
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 403)
     # Two reminder emails should have been sent.
     # This check is mostly here since we need to flush the emails out
     # to test review reminder emails later.
     mailer = mail.get_mailer()
     while mailer.queue:
         mailer.pop()
     worker.work_loop(target_time_between_calls=datetime.timedelta(seconds=1),
                      max_loops=2)
     assert(len(mailer.queue) == 2)
     while mailer.queue:
         mailer.pop()
     # Let's make another conversation and share this time but put event in past.
     conversation_data = self.make_conversation(
         user_headers['userA'], search_id=searchA_id, title='Trip to moon.',
         userA_id=user_ids['userA'], userB_id=user_ids['userB'])
     conversation_id = conversation_data['id']
     share_data = self.make_share(
         user_headers['userA'], conversation_id,
         educator_user_id=user_ids['userA'],
         community_partner_user_id=user_ids['userB'],
         starting_in_hours=-26, force_past_events=True)
     eventA_id = share_data['events'][0]['id']
     # We should receive an email telling us to review it.
     events = EventReminder.get_review_reminder_events()
     assert(len(events) == 1)
     while mailer.queue:
         mailer.pop()
     worker.work_loop(target_time_between_calls=datetime.timedelta(seconds=1),
                      max_loops=2)
     events = EventReminder.get_review_reminder_events()
     assert(len(events) == 0)
     # Two reminder emails should have been sent.
     assert(len(mailer.queue) == 2)
     # Now try to make a review for the wrong user
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userC'],
         'rating': 3,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 403)
     # Now try to make a review for oneself
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userB'],
         'rating': 3,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 403)
     # Now try to make a review with invalid rating
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userA'],
         'rating': 6,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 400)
     # Now try to make a review with invalid rating again
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userA'],
         'rating': -1,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 400)
     # Make a valid review
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userA'],
         'rating': 3,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 200)
     # We can't make a second review based off the same event
     review_data = {
         'event_id': eventA_id,
         'user_id': user_ids['userA'],
         'rating': 3,
         'review': 'Was really super'
     }
     serialized = json.dumps(review_data)
     rv = self.app.post('/api/user_review', data=serialized, headers=user_headers['userB'])
     assert(rv.status_code == 403)