def test_get_widget_context(self): """ Make sure we get the render context that we expect """ render_context = get_notifications_widget_context( override_context={ 'test_settings': 'ok', 'global_variables': { 'always_show_dates_on_unread': False } } ) self.assertIn('endpoints', render_context) endpoints = render_context['endpoints'] self.assertIn('unread_notification_count', endpoints) self.assertIn('user_notifications_all', endpoints) self.assertIn('renderer_templates_urls', endpoints) self.assertIn('ok', render_context['test_settings']) # make sure nested dictionary overrides work without destroying # the base values self.assertFalse(render_context['global_variables']['always_show_dates_on_unread']) self.assertEquals(render_context['global_variables']['app_name'], 'Your App Name Here')
def test_get_widget_context(self): """ Make sure we get the render context that we expect """ render_context = get_notifications_widget_context( override_context={ 'test_settings': 'ok', 'global_variables': { 'always_show_dates_on_unread': False } } ) self.assertIn('endpoints', render_context) endpoints = render_context['endpoints'] self.assertIn('unread_notification_count', endpoints) self.assertIn('user_notifications_all', endpoints) self.assertIn('renderer_templates_urls', endpoints) self.assertIn('ok', render_context['test_settings']) # make sure nested dictionary overrides work without destroying # the base values self.assertFalse(render_context['global_variables']['always_show_dates_on_unread']) self.assertEqual(render_context['global_variables']['app_name'], 'Your App Name Here')
def notifications_configs(request): """ Context processor to set global configs for edx-notifications :param request: :return: edx-notifications global configs """ configs = { "refresh_watcher": { "name": "short-poll", "args": { "poll_period_secs": 5, } }, "global_variables": { # we only selectively want dates in the unread # pane "always_show_dates_on_unread": False, "hide_link_is_visible": False, }, "view_audios": { # no audio alert for now "notification_alert": None, }, } data = get_notifications_widget_context(configs) return data
def index(request): """ Returns a basic HTML snippet rendering of a notification count """ global NAMESPACE if request.method == 'POST': register_user_scope_resolver('user_email_resolver', TestUserResolver(request.user)) if request.POST.get('change_namespace'): namespace_str = request.POST['namespace'] NAMESPACE = namespace_str if namespace_str != "None" else None elif request.POST.get('send_digest'): send_digest(request, request.POST.get('digest_email')) else: type_name = request.POST['notification_type'] channel_name = request.POST['notification_channel'] if not channel_name: channel_name = None msg_type = get_notification_type(type_name) msg = NotificationMessage( msg_type=msg_type, namespace=NAMESPACE, payload=CANNED_TEST_PAYLOAD[type_name], ) if type_name == 'testserver.msg-with-resolved-click-link': msg.add_click_link_params({ 'param1': 'param_val1', 'param2': 'param_val2', }) publish_notification_to_user(request.user.id, msg, preferred_channel=channel_name) template = loader.get_template('index.html') # call to the helper method to build up all the context we need # to render the "notification_widget" that is embedded in our # test page context_dict = get_notifications_widget_context({ 'user': request.user, 'notification_types': get_all_notification_types(), 'global_variables': { 'app_name': 'Notification Test Server', 'hide_link_is_visible': settings.HIDE_LINK_IS_VISIBLE, 'always_show_dates_on_unread': True, 'notification_preference_tab_is_visible': settings.NOTIFICATION_PREFERENCES_IS_VISIBLE, }, # for test purposes, set up a short-poll which contacts the server # every 10 seconds to see if there is a new notification # # NOTE: short-poll technique should not be used in a production setting with # any reasonable number of concurrent users. This is just for # testing purposes. # 'refresh_watcher': { 'name': 'short-poll', 'args': { 'poll_period_secs': 10, }, }, 'include_framework_js': True, 'namespace': NAMESPACE, }) return HttpResponse(template.render(RequestContext(request, context_dict)))