def startup_notification_subsystem(): """ Initialize the Notification subsystem """ try: startup.initialize() # register the scope resolvers that the runtime will be providing # to edx-notifications register_user_scope_resolver('course_enrollments', CourseEnrollmentsScopeResolver()) register_user_scope_resolver('course_group', CourseGroupScopeResolver()) register_user_scope_resolver('group_project_participants', GroupProjectParticipantsScopeResolver()) register_user_scope_resolver('group_project_workgroup', GroupProjectParticipantsScopeResolver()) register_user_scope_resolver('user_email_resolver', StudentEmailScopeResolver()) # register namespace resolver register_namespace_resolver(CourseNamespaceResolver()) except Exception, ex: # Note this will fail when we try to run migrations as manage.py will call startup.py # and startup.initialze() will try to manipulate some database tables. # We need to research how to identify when we are being started up as part of # a migration script log.error( 'There was a problem initializing notifications subsystem. ' 'This could be because the database tables have not yet been created and ' './manage.py lms syncdb needs to run setup.py. Error was "{err_msg}". Continuing...' .format(err_msg=str(ex)))
def test_bad_email_resolver(self): """ Cover some error cases """ resolver = StudentEmailScopeResolver() self.assertIsNone(resolver.resolve('bad', {'course_id': 'foo'}, None)) self.assertIsNone( resolver.resolve('course_enrollments', {'bad': 'foo'}, None))
def test_email_resolver(self): """ Make sure we can resolve emails """ test_user_1 = UserFactory.create(password='******') resolver = StudentEmailScopeResolver() resolved_scopes = resolver.resolve('user_email_resolver', { 'user_id': test_user_1.id, }, None) emails = [ resolved_scope['email'] for resolved_scope in resolved_scopes ] self.assertTrue(test_user_1.email in emails)