import logging
from unittest import mock
from unittest.mock import call

from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.signing import Signer
from django.urls import reverse
from django.http import Http404
from django.test import RequestFactory

from braces.views import LoginRequiredMixin
from django.test import override_settings
from model_mommy import mommy
from apps.notifications.models import Log, StatusUpdate, MemberUpdate, ReadLog, \
    ActionContextQuerySet
from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, \
    LogQuestionnairesListView, LogInformationUpdateCreateView, \
    LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView
from apps.qcat.tests import TestCase


class LogListViewTest(TestCase):

    def setUp(self):
        self.view = LogListView()
        self.url_path = reverse('notification_partial_list')
        self.request = RequestFactory().get(self.url_path)
        self.user = {}
        self.request.user = self.user
        self.view_instance = self.setup_view(
            view=self.view, request=self.request
        )
        member_add_log = mommy.make(
            _model=Log,
            id=8,
            action=settings.NOTIFICATIONS_ADD_MEMBER
        )
        self.change_log = mommy.make(
            _model=Log,
            id=42,
            action=settings.NOTIFICATIONS_CHANGE_STATUS
        )
        mommy.make(_model=StatusUpdate, log=self.change_log)
        mommy.make(_model=MemberUpdate, log=member_add_log)

    def get_view_with_get_querystring(self, param):
        request = RequestFactory().get(
            '{url}?{param}'.format(url=self.url_path, param=param)
        )
        request.user = self.user
        return self.setup_view(view=self.view, request=request)

    def test_force_login(self):
        self.assertIsInstance(self.view_instance, LoginRequiredMixin)

    def test_queryset_method(self):
        self.assertEqual(
            self.view_instance.queryset_method,
            'user_log_list'
        )

    def test_queryset_method_pending(self):
        self.assertEqual(
            self.get_view_with_get_querystring('is_pending').queryset_method,
            'user_pending_list'
        )

    def test_get_paginate_by(self):
        self.assertEqual(
            self.view_instance.get_paginate_by(None),
            settings.NOTIFICATIONS_LIST_PAGINATE_BY
        )

    def test_get_paginate_by_teaser(self):
        self.assertEqual(
            self.get_view_with_get_querystring('is_teaser').get_paginate_by(None),
            settings.NOTIFICATIONS_TEASER_PAGINATE_BY
        )

    @mock.patch('apps.notifications.views.Log.actions.user_log_list')
    def test_get_queryset(self, mock_actions):
        self.view_instance.get_queryset()
        mock_actions.assert_called_once_with(user={})

    @mock.patch('apps.notifications.views.Log.actions.user_pending_list')
    def test_get_queryset_pending(self, mock_actions):
        self.get_view_with_get_querystring('is_pending').get_queryset()
        mock_actions.assert_called_once_with(user={})

    @mock.patch.object(LogListView, 'add_user_aware_data')
    def test_get_context_data_logs(self, mock_add_user_aware_data):
        self.view_instance.object_list = 'foo'
        self.view_instance.get_context_data()
        mock_add_user_aware_data.assert_called_once_with('foo')

    def _test_add_user_aware_data(self):
        # for faster tests, mock all the elements. elements are created here
        # as this makes the tests more readable.
        pth = 'apps.notifications.views.Log.actions'
        with mock.patch('{}.read_id_list'.format(pth)) as read_id_list:
            read_id_list.return_value = [42]
            with mock.patch('{}.user_pending_list'.format(pth)) as pending:
                pending.values_list.return_value = [8, 42]
                logs = Log.objects.all()
                return list(self.view_instance.add_user_aware_data(logs))

    def test_add_user_aware_data_keys(self):
        data_keys = self._test_add_user_aware_data()[0].keys()
        for key in ['id', 'created', 'text', 'is_read', 'is_todo', 'edit_url']:
            self.assertTrue(key in data_keys)

    def test_add_user_aware_data_is_read(self):
        data = self._test_add_user_aware_data()
        # logs are ordered by creation date -  42 is the newer one
        self.assertTrue(data[0]['is_read'])

    def test_add_user_aware_data_is_not_read(self):
        data = self._test_add_user_aware_data()
        self.assertFalse(data[1]['is_read'])

    #def test_add_user_aware_data_is_todo(self):
    #    data = self._test_add_user_aware_data()
    #    self.assertTrue(data[1]['is_todo'])

    def test_add_user_aware_data_is_not_todo(self):
        data = self._test_add_user_aware_data()
        self.assertFalse(data[0]['is_todo'])

    @override_settings(NOTIFICATIONS_ACTIONS={'foo': 'bar', 'result': '42'})
    def test_statuses_in_context(self):
        self.view_instance.object_list = []
        context = self.view_instance.get_context_data()
        self.assertDictEqual(
            context['statuses'],
            {'foo': 'bar', 'result': '42'}
        )

    @mock.patch('apps.notifications.views.Log.actions.user_log_list')
    def test_status_filter_queryset(self, mock_user_log_list):
        mock_user_log_list.return_value = []
        self.assertEqual(
            [], self.view_instance.get_queryset()
        )

    @mock.patch('apps.notifications.views.Log.actions.user_log_list')
    def test_status_filter_queryset_for_status(self, mock_user_log_list):
        mock_user_log_list.return_value = Log.objects.filter()
        view = self.view
        view.get_statuses = mock.MagicMock(return_value=[3])
        view_instance = self.setup_view(
            view=view, request=self.request
        )
        self.assertQuerysetEqual(
            view_instance.get_queryset(),
            [self.change_log.id],
            transform=lambda item: item.id
        )

    def test_get_status_invalid(self):
        request = RequestFactory().get('{}?statuses=foo'.format(self.url_path))
        view = self.setup_view(self.view, request)
        self.assertEqual(view.get_statuses(), [])

    @override_settings(NOTIFICATIONS_ACTIONS={'2': 'bar'})
    def test_get_status_invalid_config(self):
        request = RequestFactory().get('{}?statuses=1'.format(self.url_path))
        view = self.setup_view(self.view, request)
        self.assertEqual(view.get_statuses(), [])

    def test_get_status_valid(self):
        request = RequestFactory().get('{}?statuses=1,2,3'.format(self.url_path))
        view = self.setup_view(self.view, request)
        self.assertEqual(view.get_statuses(), [1, 2, 3])


class ReadLogUpdateViewTest(TestCase):

    def setUp(self):
        self.view = ReadLogUpdateView()
        self.request = RequestFactory().post(
            reverse('notification_read'),
            data={'user': 123, 'log': 'log', 'checked': 'true'}
        )
        self.user = mock.MagicMock(id=123)
        self.request.user = self.user
        self.view_instance = self.setup_view(view=self.view, request=self.request)

    def test_validate_data_all_keys(self):
        self.assertFalse(
            self.view_instance.validate_data()
        )

    def test_validate_data_id_type(self):
        self.assertFalse(
            self.view_instance.validate_data(checked='1', log='1', user='foo')
        )

    def test_validate_data_invalid_user(self):
        self.assertFalse(
            self.view_instance.validate_data(checked='456', log='1', user='456')
        )

    def test_validate_data_valid(self):
        self.assertTrue(
            self.view_instance.validate_data(checked='1', log='1', user='123')
        )

    @mock.patch('apps.notifications.views.ReadLog.objects.update_or_create')
    def test_post_valid_checked(self, mock_get_or_create):
        self.view_instance.post(request=self.request)
        mock_get_or_create.assert_called_once_with(
            user_id='123', log_id='log', defaults={'is_read': True}
        )

    @mock.patch('apps.notifications.views.ReadLog.objects.update_or_create')
    def test_post_valid_unchecked(self, mock_get_or_create):
        request = RequestFactory().post(
            reverse('notification_read'),
            data={'user': 123, 'log': 'log', 'checked': 'false'}
        )
        self.view_instance.post(request=request)
        mock_get_or_create.assert_called_once_with(
            user_id='123', log_id='log', defaults={'is_read': False}
        )

    @mock.patch.object(ReadLogUpdateView, 'validate_data')
    def test_post_invalid(self, mock_validate_data):
        logging.disable(logging.CRITICAL)
        mock_validate_data.return_value = False
        with self.assertRaises(Http404):
            self.view_instance.post(request=self.request)


class LogCountViewTest(TestCase):

    def setUp(self):
        super().setUp()
        self.request = RequestFactory().get(reverse('notification_new_count'))
        self.request.user = mommy.make(_model=get_user_model())
        self.view = self.setup_view(view=LogCountView(), request=self.request)
        mommy.make(
            _model=Log,
            catalyst=self.request.user,
            action=settings.NOTIFICATIONS_CHANGE_STATUS,
            _quantity=4
        )
        mommy.make(
            _model=Log,
            catalyst=self.request.user,
            action=settings.NOTIFICATIONS_EDIT_CONTENT,
            _quantity=2
        )

    @mock.patch('apps.notifications.views.Log.actions.only_unread_logs')
    def test_get_unread_only(self, mock_only_unread_logs):
        self.view.get(request=self.request)
        mock_only_unread_logs.assert_called_once_with(
            user=self.request.user
        )

    def test_log_count(self):
        response = self.view.get(request=self.request)
        self.assertEqual(response.content, b'4')

    def test_log_count_one_read(self):
        mommy.make(
            _model=ReadLog,
            log=Log.objects.filter(action=settings.NOTIFICATIONS_CHANGE_STATUS).first(),
            user=self.request.user,
            is_read=True
        )
        response = self.view.get(request=self.request)
        self.assertEqual(response.content, b'3')


class LogQuestionnairesListViewTest(TestCase):

    def setUp(self):
        super().setUp()
        self.request = RequestFactory().get(reverse('notification_questionnaire_logs'))
        self.request.user = 'foo'
        self.view = self.setup_view(view=LogQuestionnairesListView(), request=self.request)

    @mock.patch.object(ActionContextQuerySet, 'user_log_list')
    def test_get_questionnaire_logs(self, mock_user_log_list):
        self.view.get_questionnaire_logs('foo')
        mock_user_log_list.assert_called_once_with(user='foo')


    @mock.patch.object(LogQuestionnairesListView, 'get_questionnaire_logs')
    def test_get(self, mock_get_questionnaire_logs):
        mock_get_questionnaire_logs.return_value = ['foo_1', 'foo_2', 'bar_3']
        response = self.view.get(self.request)
        self.assertEqual(
            response.content, b'{"questionnaires": ["bar_3", "foo_1", "foo_2"]}'
        )


class LogInformationUpdateCreateViewTest(TestCase):

    def setUp(self):
        super().setUp()
        self.url = reverse('notification_inform_compiler')
        self.view = LogInformationUpdateCreateView()
        self.request = RequestFactory().get(self.url)
        self.request.user = 'foo'
        self.view = self.setup_view(view=self.view, request=self.request)

    def test_get_compiler_query(self):
        questionnaire = mock.MagicMock()
        self.view.get_compiler(questionnaire)
        self.assertEqual(
            questionnaire.method_calls[0],
            call.questionnairemembership_set.get(role='compiler')
        )

    def test_get_compiler(self):
        sentinel = mock.sentinel
        questionnaire = mock.MagicMock()
        questionnaire.questionnairemembership_set.get.return_value = sentinel
        self.assertEqual(
            self.view.get_compiler(questionnaire),
            sentinel.user
        )

    @mock.patch('apps.notifications.views.query_questionnaire')
    def test_get_questionnaire(self, mock_query_questionnaire):
        one_questionnaire = mock.MagicMock()
        one_questionnaire.first = lambda : 'foo'
        mock_query_questionnaire.return_value = one_questionnaire
        self.assertEqual(
            self.view.get_questionnaire('foo'), 'foo'
        )

    @mock.patch('apps.notifications.views.query_questionnaire')
    def test_get_questionnaire_raises(self, mock_query_questionnaire):
        not_exists = mock.MagicMock()
        not_exists.exists = lambda : False
        mock_query_questionnaire.return_value = not_exists
        with self.assertRaises(Http404):
            self.view.get_questionnaire('foo')

    @mock.patch('apps.notifications.views.query_questionnaire')
    def test_get_questionnaire_calls_filter(self, mock_query_questionnaire):
        self.view.get_questionnaire('foo')
        mock_query_questionnaire.assert_called_once_with(
            identifier='foo', request=self.request
        )

    @override_settings(NOTIFICATIONS_FINISH_EDITING='setting')
    @mock.patch.object(LogInformationUpdateCreateView, 'get_questionnaire')
    @mock.patch.object(LogInformationUpdateCreateView, 'get_compiler')
    def test_post(self, mock_get_compiler, mock_get_questionnaire):
        compiler = mock.MagicMock()
        mock_get_questionnaire.return_value = mock.sentinel.questionnaire
        mock_get_compiler.return_value = compiler
        request = RequestFactory().post(self.url, data={
            'identifier': 'foo',
            'message': 'bar'
        })
        with mock.patch('apps.notifications.views.InformationLog') as mock_create:
            self.setup_view(view=self.view, request=self.request).post(request)
            mock_create.assert_called_once_with(
                action='setting',
                questionnaire=mock.sentinel.questionnaire,
                receiver=compiler,
                sender='foo'
            )


class LogSubscriptionPreferencesMixinTest(TestCase):

    def setUp(self):
        self.url = reverse('notification_preferences')
        self.view = LogSubscriptionPreferencesView()
        self.request = RequestFactory().get(self.url)
        self.user = mommy.make(_model=get_user_model())
        self.obj = self.user.mailpreferences
        self.request.user = self.user
        self.request._messages = mock.MagicMock()
        self.view = self.setup_view(view=self.view, request=self.request)
        self.view.object = self.obj

    def test_get_initial(self):
        self.obj.wanted_actions = 'some,thing,yay'
        self.assertEqual(
            ['some', 'thing', 'yay'],
            self.view.get_initial()['wanted_actions']
        )

    def test_get_form_valid_changed_language(self):
        self.view.object = mock.MagicMock()
        self.view.object.has_changed_language = False
        form = mock.MagicMock()
        form.changed_data = ['language']
        self.view.form_valid(form)
        self.assertTrue(self.view.object.has_changed_language)

    def test_get_form_valid_message(self):
        self.view.form_valid(mock.MagicMock())
        self.assertTrue(self.request._messages.method_calls)


class SignedLogSubscriptionPreferencesViewTest(TestCase):

    def setUp(self):
        self.user = mommy.make(_model=get_user_model())
        self.obj = self.user.mailpreferences
        self.view = SignedLogSubscriptionPreferencesView()
        self.request = RequestFactory().get(str(self.obj.get_signed_url()))
        self.request._messages = mock.MagicMock()
        self.view = self.setup_view(view=self.view, request=self.request)
        self.view.object = self.obj

    def test_get_success_url_signed(self):
        mock_user = mock.MagicMock(return_value=self.user)
        mock_user.is_authenticated = False
        mock_user.id = self.user.id
        self.request.user = mock_user
        self.assertEqual(
            self.view.get_success_url(),
            self.obj.get_signed_url()
        )

    def test_get_success_url_user(self):
        self.request.user = self.user
        self.assertEqual(
            self.view.get_success_url(),
            reverse('notification_preferences')
        )

    def test_get_object_user(self):
        self.request.user = self.user
        self.assertEqual(
            self.view.get_object(),
            self.obj
        )

    def test_get_signed_object(self):
        mock_user = mock.MagicMock(return_value=self.user)
        mock_user.is_authenticated = False
        mock_user.id=self.user.id
        self.request.user = mock_user
        self.view.kwargs['token'] = mock.MagicMock()
        with mock.patch.object(Signer, 'unsign') as mock_unsign:
            mock_unsign.return_value = self.obj.id
            self.assertEqual(
                self.view.get_object(), self.obj
            )
            mock_unsign.assert_called_with(self.view.kwargs['token'])

    def test_get_signed_object_404(self):
        mock_user = mock.MagicMock(return_value=self.user)
        mock_user.is_authenticated = False
        mock_user.id = self.user.id
        self.request.user = mock_user
        self.view.kwargs['token'] = mock.MagicMock()
        with self.assertRaises(Http404):
            self.view.get_object()

[((2679, 2743), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.Log.actions.user_log_list"""'], {}), "('apps.notifications.views.Log.actions.user_log_list')\n", (2689, 2743), False, 'from unittest import mock\n'), ((2893, 2961), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.Log.actions.user_pending_list"""'], {}), "('apps.notifications.views.Log.actions.user_pending_list')\n", (2903, 2961), False, 'from unittest import mock\n'), ((3149, 3202), 'unittest.mock.patch.object', 'mock.patch.object', (['LogListView', '"""add_user_aware_data"""'], {}), "(LogListView, 'add_user_aware_data')\n", (3166, 3202), False, 'from unittest import mock\n'), ((4901, 4972), 'django.test.override_settings', 'override_settings', ([], {'NOTIFICATIONS_ACTIONS': "{'foo': 'bar', 'result': '42'}"}), "(NOTIFICATIONS_ACTIONS={'foo': 'bar', 'result': '42'})\n", (4918, 4972), False, 'from django.test import override_settings\n'), ((5235, 5299), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.Log.actions.user_log_list"""'], {}), "('apps.notifications.views.Log.actions.user_log_list')\n", (5245, 5299), False, 'from unittest import mock\n'), ((5500, 5564), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.Log.actions.user_log_list"""'], {}), "('apps.notifications.views.Log.actions.user_log_list')\n", (5510, 5564), False, 'from unittest import mock\n'), ((6273, 6326), 'django.test.override_settings', 'override_settings', ([], {'NOTIFICATIONS_ACTIONS': "{'2': 'bar'}"}), "(NOTIFICATIONS_ACTIONS={'2': 'bar'})\n", (6290, 6326), False, 'from django.test import override_settings\n'), ((7820, 7891), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.ReadLog.objects.update_or_create"""'], {}), "('apps.notifications.views.ReadLog.objects.update_or_create')\n", (7830, 7891), False, 'from unittest import mock\n'), ((8141, 8212), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.ReadLog.objects.update_or_create"""'], {}), "('apps.notifications.views.ReadLog.objects.update_or_create')\n", (8151, 8212), False, 'from unittest import mock\n'), ((8618, 8671), 'unittest.mock.patch.object', 'mock.patch.object', (['ReadLogUpdateView', '"""validate_data"""'], {}), "(ReadLogUpdateView, 'validate_data')\n", (8635, 8671), False, 'from unittest import mock\n'), ((9573, 9640), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.Log.actions.only_unread_logs"""'], {}), "('apps.notifications.views.Log.actions.only_unread_logs')\n", (9583, 9640), False, 'from unittest import mock\n'), ((10646, 10703), 'unittest.mock.patch.object', 'mock.patch.object', (['ActionContextQuerySet', '"""user_log_list"""'], {}), "(ActionContextQuerySet, 'user_log_list')\n", (10663, 10703), False, 'from unittest import mock\n'), ((10885, 10955), 'unittest.mock.patch.object', 'mock.patch.object', (['LogQuestionnairesListView', '"""get_questionnaire_logs"""'], {}), "(LogQuestionnairesListView, 'get_questionnaire_logs')\n", (10902, 10955), False, 'from unittest import mock\n'), ((12203, 12261), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.query_questionnaire"""'], {}), "('apps.notifications.views.query_questionnaire')\n", (12213, 12261), False, 'from unittest import mock\n'), ((12582, 12640), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.query_questionnaire"""'], {}), "('apps.notifications.views.query_questionnaire')\n", (12592, 12640), False, 'from unittest import mock\n'), ((12946, 13004), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.query_questionnaire"""'], {}), "('apps.notifications.views.query_questionnaire')\n", (12956, 13004), False, 'from unittest import mock\n'), ((13250, 13307), 'django.test.override_settings', 'override_settings', ([], {'NOTIFICATIONS_FINISH_EDITING': '"""setting"""'}), "(NOTIFICATIONS_FINISH_EDITING='setting')\n", (13267, 13307), False, 'from django.test import override_settings\n'), ((13313, 13383), 'unittest.mock.patch.object', 'mock.patch.object', (['LogInformationUpdateCreateView', '"""get_questionnaire"""'], {}), "(LogInformationUpdateCreateView, 'get_questionnaire')\n", (13330, 13383), False, 'from unittest import mock\n'), ((13389, 13454), 'unittest.mock.patch.object', 'mock.patch.object', (['LogInformationUpdateCreateView', '"""get_compiler"""'], {}), "(LogInformationUpdateCreateView, 'get_compiler')\n", (13406, 13454), False, 'from unittest import mock\n'), ((857, 870), 'apps.notifications.views.LogListView', 'LogListView', ([], {}), '()\n', (868, 870), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((895, 931), 'django.urls.reverse', 'reverse', (['"""notification_partial_list"""'], {}), "('notification_partial_list')\n", (902, 931), False, 'from django.urls import reverse\n'), ((1182, 1252), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'Log', 'id': '(8)', 'action': 'settings.NOTIFICATIONS_ADD_MEMBER'}), '(_model=Log, id=8, action=settings.NOTIFICATIONS_ADD_MEMBER)\n', (1192, 1252), False, 'from model_mommy import mommy\n'), ((1325, 1399), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'Log', 'id': '(42)', 'action': 'settings.NOTIFICATIONS_CHANGE_STATUS'}), '(_model=Log, id=42, action=settings.NOTIFICATIONS_CHANGE_STATUS)\n', (1335, 1399), False, 'from model_mommy import mommy\n'), ((1454, 1506), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'StatusUpdate', 'log': 'self.change_log'}), '(_model=StatusUpdate, log=self.change_log)\n', (1464, 1506), False, 'from model_mommy import mommy\n'), ((1515, 1566), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'MemberUpdate', 'log': 'member_add_log'}), '(_model=MemberUpdate, log=member_add_log)\n', (1525, 1566), False, 'from model_mommy import mommy\n'), ((5681, 5701), 'apps.notifications.models.Log.objects.filter', 'Log.objects.filter', ([], {}), '()\n', (5699, 5701), False, 'from apps.notifications.models import Log, StatusUpdate, MemberUpdate, ReadLog, ActionContextQuerySet\n'), ((5755, 5787), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {'return_value': '[3]'}), '(return_value=[3])\n', (5769, 5787), False, 'from unittest import mock\n'), ((6863, 6882), 'apps.notifications.views.ReadLogUpdateView', 'ReadLogUpdateView', ([], {}), '()\n', (6880, 6882), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((7065, 7087), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {'id': '(123)'}), '(id=123)\n', (7079, 7087), False, 'from unittest import mock\n'), ((8733, 8766), 'logging.disable', 'logging.disable', (['logging.CRITICAL'], {}), '(logging.CRITICAL)\n', (8748, 8766), False, 'import logging\n'), ((9226, 9339), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'Log', 'catalyst': 'self.request.user', 'action': 'settings.NOTIFICATIONS_CHANGE_STATUS', '_quantity': '(4)'}), '(_model=Log, catalyst=self.request.user, action=settings.\n    NOTIFICATIONS_CHANGE_STATUS, _quantity=4)\n', (9236, 9339), False, 'from model_mommy import mommy\n'), ((9401, 9513), 'model_mommy.mommy.make', 'mommy.make', ([], {'_model': 'Log', 'catalyst': 'self.request.user', 'action': 'settings.NOTIFICATIONS_EDIT_CONTENT', '_quantity': '(2)'}), '(_model=Log, catalyst=self.request.user, action=settings.\n    NOTIFICATIONS_EDIT_CONTENT, _quantity=2)\n', (9411, 9513), False, 'from model_mommy import mommy\n'), ((11371, 11410), 'django.urls.reverse', 'reverse', (['"""notification_inform_compiler"""'], {}), "('notification_inform_compiler')\n", (11378, 11410), False, 'from django.urls import reverse\n'), ((11431, 11463), 'apps.notifications.views.LogInformationUpdateCreateView', 'LogInformationUpdateCreateView', ([], {}), '()\n', (11461, 11463), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((11690, 11706), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (11704, 11706), False, 'from unittest import mock\n'), ((11989, 12005), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (12003, 12005), False, 'from unittest import mock\n'), ((12354, 12370), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (12368, 12370), False, 'from unittest import mock\n'), ((12733, 12749), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (12747, 12749), False, 'from unittest import mock\n'), ((13542, 13558), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (13556, 13558), False, 'from unittest import mock\n'), ((14292, 14327), 'django.urls.reverse', 'reverse', (['"""notification_preferences"""'], {}), "('notification_preferences')\n", (14299, 14327), False, 'from django.urls import reverse\n'), ((14348, 14380), 'apps.notifications.views.LogSubscriptionPreferencesView', 'LogSubscriptionPreferencesView', ([], {}), '()\n', (14378, 14380), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((14607, 14623), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (14621, 14623), False, 'from unittest import mock\n'), ((15026, 15042), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (15040, 15042), False, 'from unittest import mock\n'), ((15112, 15128), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (15126, 15128), False, 'from unittest import mock\n'), ((15623, 15661), 'apps.notifications.views.SignedLogSubscriptionPreferencesView', 'SignedLogSubscriptionPreferencesView', ([], {}), '()\n', (15659, 15661), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((15771, 15787), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (15785, 15787), False, 'from unittest import mock\n'), ((15962, 16000), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {'return_value': 'self.user'}), '(return_value=self.user)\n', (15976, 16000), False, 'from unittest import mock\n'), ((16665, 16703), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {'return_value': 'self.user'}), '(return_value=self.user)\n', (16679, 16703), False, 'from unittest import mock\n'), ((16855, 16871), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (16869, 16871), False, 'from unittest import mock\n'), ((17214, 17252), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {'return_value': 'self.user'}), '(return_value=self.user)\n', (17228, 17252), False, 'from unittest import mock\n'), ((17406, 17422), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (17420, 17422), False, 'from unittest import mock\n'), ((6941, 6969), 'django.urls.reverse', 'reverse', (['"""notification_read"""'], {}), "('notification_read')\n", (6948, 6969), False, 'from django.urls import reverse\n'), ((8327, 8355), 'django.urls.reverse', 'reverse', (['"""notification_read"""'], {}), "('notification_read')\n", (8334, 8355), False, 'from django.urls import reverse\n'), ((9040, 9073), 'django.urls.reverse', 'reverse', (['"""notification_new_count"""'], {}), "('notification_new_count')\n", (9047, 9073), False, 'from django.urls import reverse\n'), ((10470, 10512), 'django.urls.reverse', 'reverse', (['"""notification_questionnaire_logs"""'], {}), "('notification_questionnaire_logs')\n", (10477, 10512), False, 'from django.urls import reverse\n'), ((11834, 11887), 'unittest.mock.call.questionnairemembership_set.get', 'call.questionnairemembership_set.get', ([], {'role': '"""compiler"""'}), "(role='compiler')\n", (11870, 11887), False, 'from unittest.mock import call\n'), ((13826, 13879), 'unittest.mock.patch', 'mock.patch', (['"""apps.notifications.views.InformationLog"""'], {}), "('apps.notifications.views.InformationLog')\n", (13836, 13879), False, 'from unittest import mock\n'), ((15341, 15357), 'unittest.mock.MagicMock', 'mock.MagicMock', ([], {}), '()\n', (15355, 15357), False, 'from unittest import mock\n'), ((16392, 16427), 'django.urls.reverse', 'reverse', (['"""notification_preferences"""'], {}), "('notification_preferences')\n", (16399, 16427), False, 'from django.urls import reverse\n'), ((16885, 16920), 'unittest.mock.patch.object', 'mock.patch.object', (['Signer', '"""unsign"""'], {}), "(Signer, 'unsign')\n", (16902, 16920), False, 'from unittest import mock\n'), ((955, 971), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (969, 971), False, 'from django.test import RequestFactory\n'), ((1638, 1654), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (1652, 1654), False, 'from django.test import RequestFactory\n'), ((3924, 3941), 'apps.notifications.models.Log.objects.all', 'Log.objects.all', ([], {}), '()\n', (3939, 3941), False, 'from apps.notifications.models import Log, StatusUpdate, MemberUpdate, ReadLog, ActionContextQuerySet\n'), ((6104, 6120), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (6118, 6120), False, 'from django.test import RequestFactory\n'), ((6391, 6407), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (6405, 6407), False, 'from django.test import RequestFactory\n'), ((6608, 6624), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (6622, 6624), False, 'from django.test import RequestFactory\n'), ((6906, 6922), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (6920, 6922), False, 'from django.test import RequestFactory\n'), ((8292, 8308), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (8306, 8308), False, 'from django.test import RequestFactory\n'), ((9019, 9035), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (9033, 9035), False, 'from django.test import RequestFactory\n'), ((9121, 9137), 'django.contrib.auth.get_user_model', 'get_user_model', ([], {}), '()\n', (9135, 9137), False, 'from django.contrib.auth import get_user_model\n'), ((9180, 9194), 'apps.notifications.views.LogCountView', 'LogCountView', ([], {}), '()\n', (9192, 9194), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((10449, 10465), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (10463, 10465), False, 'from django.test import RequestFactory\n'), ((10589, 10616), 'apps.notifications.views.LogQuestionnairesListView', 'LogQuestionnairesListView', ([], {}), '()\n', (10614, 10616), False, 'from apps.notifications.views import LogListView, LogCountView, ReadLogUpdateView, LogQuestionnairesListView, LogInformationUpdateCreateView, LogSubscriptionPreferencesView, SignedLogSubscriptionPreferencesView\n'), ((11487, 11503), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (11501, 11503), False, 'from django.test import RequestFactory\n'), ((13701, 13717), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (13715, 13717), False, 'from django.test import RequestFactory\n'), ((14404, 14420), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (14418, 14420), False, 'from django.test import RequestFactory\n'), ((14473, 14489), 'django.contrib.auth.get_user_model', 'get_user_model', ([], {}), '()\n', (14487, 14489), False, 'from django.contrib.auth import get_user_model\n'), ((15540, 15556), 'django.contrib.auth.get_user_model', 'get_user_model', ([], {}), '()\n', (15554, 15556), False, 'from django.contrib.auth import get_user_model\n'), ((15685, 15701), 'django.test.RequestFactory', 'RequestFactory', ([], {}), '()\n', (15699, 15701), False, 'from django.test import RequestFactory\n'), ((10083, 10146), 'apps.notifications.models.Log.objects.filter', 'Log.objects.filter', ([], {'action': 'settings.NOTIFICATIONS_CHANGE_STATUS'}), '(action=settings.NOTIFICATIONS_CHANGE_STATUS)\n', (10101, 10146), False, 'from apps.notifications.models import Log, StatusUpdate, MemberUpdate, ReadLog, ActionContextQuerySet\n')]