def test_get_send_welcome_notifications(self): handler = actions.MockHandler(app_context=actions.MockAppContext()) self.assertFalse( models.StudentProfileDAO._get_send_welcome_notifications(handler)) handler = actions.MockHandler( app_context=actions.MockAppContext(environ={ 'course': {} })) self.assertFalse( models.StudentProfileDAO._get_send_welcome_notifications(handler)) handler = actions.MockHandler( app_context=actions.MockAppContext(environ={ 'course': {'send_welcome_notifications': False} })) self.assertFalse( models.StudentProfileDAO._get_send_welcome_notifications(handler)) handler = actions.MockHandler( app_context=actions.MockAppContext(environ={ 'course': {'send_welcome_notifications': True} })) self.assertTrue( models.StudentProfileDAO._get_send_welcome_notifications(handler))
def test_send_welcome_notification_enqueues_and_sends(self): nick_name = 'No Body' email = '*****@*****.**' sender = '*****@*****.**' title = 'title' student = models.Student(key_name=email, name=nick_name) student.put() self.swap(services.notifications, 'enabled', lambda: True) self.swap(services.unsubscribe, 'enabled', lambda: True) handler = actions.MockHandler(app_context=actions.MockAppContext( environ={ 'course': { 'send_welcome_notifications': True, 'title': title, 'welcome_notifications_sender': sender, }, })) models.StudentProfileDAO._send_welcome_notification(handler, student) self.execute_all_deferred_tasks() notification = notifications.Notification.all().get() payload = notifications.Payload.all().get() audit_trail = notification.audit_trail self.assertEqual(title, audit_trail['course_title']) self.assertEqual('http://mycourse.appspot.com/slug/', audit_trail['course_url']) self.assertTrue(audit_trail['unsubscribe_url'].startswith( 'http://mycourse.appspot.com/slug/modules/unsubscribe')) self.assertTrue(notification._done_date) self.assertEqual(email, notification.to) self.assertEqual(sender, notification.sender) self.assertEqual('Welcome to ' + title, notification.subject) self.assertTrue(payload)
def test_can_send_welcome_notifications_true_if_all_true(self): self.swap(services.notifications, 'enabled', lambda: True) self.swap(services.unsubscribe, 'enabled', lambda: True) handler = actions.MockHandler(app_context=actions.MockAppContext( environ={'course': { 'send_welcome_notifications': True }})) self.assertTrue( models.StudentProfileDAO._can_send_welcome_notifications(handler))
def setUp(self): super(UnsubscribeHandlerTests, self).setUp() self.slug = 'a' self.namespace = 'ns_a' sites.setup_courses('course:/%s::%s' % (self.slug, self.namespace)) self.app_context = actions.MockAppContext(namespace=self.namespace, slug=self.slug) self.handler = actions.MockHandler(base_href='http://localhost/', app_context=self.app_context) self.email = '*****@*****.**' actions.login(self.email, is_admin=True)
def test_get_unsubscribe_url(self): handler = actions.MockHandler(app_context=actions.MockAppContext( slug='new_course')) url = unsubscribe.get_unsubscribe_url(handler, '*****@*****.**') parsed_url = urlparse.urlparse(url) self.assertEquals('http', parsed_url.scheme) self.assertEquals('mycourse.appspot.com', parsed_url.netloc) self.assertEquals('/new_course/modules/unsubscribe', parsed_url.path) query_dict = urlparse.parse_qs(parsed_url.query) self.assertEquals(['*****@*****.**'], query_dict['email']) self.assertRegexpMatches(query_dict['s'][0], r'[0-9a-f]{32}')
def get_runtime(self): mock_context = actions.MockAppContext( environ=self.environ, namespace=self.app_context.get_namespace_name(), slug=self.app_context.get_slug()) return lti._Runtime(mock_context)