Exemple #1
0
 def test_reply(self, mock_support):
     """Given a message, a support notification should be sent to the task's user."""
     # pylint: disable=no-self-use
     flagged_task = FlaggedTaskFactory()
     reply = 'Lorem ipsum'
     flagged_task.reply(reply)
     mock_support.assert_called_with(flagged_task.user, reply, flagged_task)
Exemple #2
0
 def test_reply(self, mock_support):
     """Given a message, a support notification should be sent to the task's user."""
     flagged_task = FlaggedTaskFactory()
     reply = "Lorem ipsum"
     flagged_task.reply(reply)
     mock_support.assert_called_with(flagged_task.user.pk, reply,
                                     flagged_task.pk)
Exemple #3
0
 def setUp(self):
     password = "******"
     self.user = UserFactory(is_staff=True, password=password)
     self.url = reverse("flagged-task-list")
     self.view = FlaggedTaskList.as_view()
     self.task = FlaggedTaskFactory()
     self.request_factory = RequestFactory()
     self.client.login(username=self.user.username, password=password)
Exemple #4
0
class FlaggedTaskViewTests(TestCase):
    """Tests FlaggedTask POST handlers"""
    @mock.patch('muckrock.task.tasks.create_zoho_ticket.delay', mock.Mock())
    def setUp(self):
        self.user = UserFactory(is_staff=True)
        self.url = reverse('flagged-task-list')
        self.view = FlaggedTaskList.as_view()
        self.task = FlaggedTaskFactory()
        self.request_factory = RequestFactory()

    def test_get_single(self, mock_reply):
        """Should be able to view a single task"""
        # pylint: disable=unused-argument
        request = self.request_factory.get(
            reverse('flagged-task', kwargs={'pk': self.task.pk}))
        request.user = self.user
        request = mock_middleware(request)
        response = self.view(request)
        eq_(response.status_code, 200)

    def post_request(self, data):
        """Helper to post data and get a response"""
        request = self.request_factory.post(self.url, data)
        request.user = self.user
        request = mock_middleware(request)
        response = self.view(request)
        return response

    def test_post_reply(self, mock_reply):
        """Staff should be able to reply to the user who raised the flag"""
        test_text = 'Lorem ipsum'
        form = FlaggedTaskForm({'text': test_text})
        ok_(form.is_valid())
        post_data = form.cleaned_data
        post_data.update({'reply': 'truthy', 'task': self.task.pk})
        self.post_request(post_data)
        self.task.refresh_from_db()
        ok_(not self.task.resolved,
            'The task should not automatically resolve when replying.')
        mock_reply.assert_called_with(test_text)

    def test_post_reply_resolve(self, mock_reply):
        """The task should optionally resolve when replying"""
        test_text = 'Lorem ipsum'
        form = FlaggedTaskForm({'text': test_text})
        ok_(form.is_valid())
        post_data = form.cleaned_data
        post_data.update({
            'reply': 'truthy',
            'resolve': True,
            'task': self.task.pk
        })
        self.post_request(post_data)
        self.task.refresh_from_db()
        ok_(self.task.resolved, 'The task should resolve.')
        mock_reply.assert_called_with(test_text)
Exemple #5
0
 def test_create_zend_ticket(self, mock_requests):
     """Test the creation of a zendesk help ticket when a flag is created"""
     mock_requests.post(
         "https://muckrock.zendesk.com/api/v2/requests.json",
         json={"request": {
             "id": "ticket_id"
         }},
     )
     flagged_task = FlaggedTaskFactory(user__email="*****@*****.**",
                                       text="Example flag text")
     flagged_task.refresh_from_db()
     ok_(flagged_task.resolved)
     eq_(flagged_task.form_data, {"zen_id": "ticket_id"})
Exemple #6
0
 def test_create_zoho_ticket(self, mock_requests):
     """Test the creation of a zoho help ticket when a flag is created"""
     mock_requests.get(
         settings.ZOHO_URL + "contacts/search",
         json={
             "count": 1,
             "data": [{
                 "id": "contact_id"
             }]
         },
     )
     mock_requests.post(settings.ZOHO_URL + "tickets",
                        json={"id": "ticket_id"})
     flagged_task = FlaggedTaskFactory(user__email="*****@*****.**",
                                       text="Example flag text")
     flagged_task.refresh_from_db()
     ok_(flagged_task.resolved)
     eq_(flagged_task.form_data, {"zoho_id": "ticket_id"})
Exemple #7
0
 def setUp(self):
     AgencyFactory()
     ArticleFactory()
     CrowdsourceResponseFactory()
     FOIARequestFactory()
     FlaggedTaskFactory()
     NewAgencyTaskFactory()
     OrphanTaskFactory()
     QuestionFactory()
     ResponseTaskFactory()
     SnailMailTaskFactory()
     UserFactory()
 def test_create_zoho_ticket(self, mock_requests):
     """Test the creation of a zoho help ticket when a flag is created"""
     mock_requests.get(
         settings.ZOHO_URL + 'contacts/search',
         json={
             'count': 1,
             'data': [{
                 'id': 'contact_id'
             }]
         },
     )
     mock_requests.post(
         settings.ZOHO_URL + 'tickets',
         json={'id': 'ticket_id'},
     )
     flagged_task = FlaggedTaskFactory(
         user__email='*****@*****.**',
         text='Example flag text',
     )
     flagged_task.refresh_from_db()
     ok_(flagged_task.resolved)
     eq_(flagged_task.form_data, {'zoho_id': 'ticket_id'})
Exemple #9
0
 def test_support(self, mock_send):
     """Notifies the user with a support response."""
     task = FlaggedTaskFactory()
     tasks.support(self.user, 'Hello', task)
     mock_send.assert_called_with(fail_silently=False)
Exemple #10
0
 def setUp(self):
     self.user = factories.UserFactory(is_staff=True)
     self.url = reverse('flagged-task-list')
     self.view = task.views.FlaggedTaskList.as_view()
     self.task = FlaggedTaskFactory()
     self.request_factory = RequestFactory()
Exemple #11
0
class FlaggedTaskViewTests(TestCase):
    """Tests FlaggedTask POST handlers"""

    @mock.patch("muckrock.task.tasks.create_ticket.delay", mock.Mock())
    def setUp(self):
        password = "******"
        self.user = UserFactory(is_staff=True, password=password)
        self.url = reverse("flagged-task-list")
        self.view = FlaggedTaskList.as_view()
        self.task = FlaggedTaskFactory()
        self.request_factory = RequestFactory()
        self.client.login(username=self.user.username, password=password)

    def test_get_single(self, mock_reply):
        """Should be able to view a single task"""
        # pylint: disable=unused-argument
        request = self.request_factory.get(
            reverse("flagged-task", kwargs={"pk": self.task.pk})
        )
        request.user = self.user
        request = mock_middleware(request)
        response = self.view(request)
        eq_(response.status_code, 200)

    def post_request(self, data):
        """Helper to post data and get a response"""
        request = self.request_factory.post(self.url, data)
        request.user = self.user
        request = mock_middleware(request)
        response = self.view(request)
        return response

    def test_post_reply(self, mock_reply):
        """Staff should be able to reply to the user who raised the flag"""
        test_text = "Lorem ipsum"
        form = FlaggedTaskForm({"text": test_text})
        ok_(form.is_valid())
        post_data = form.cleaned_data
        post_data.update({"reply": "truthy", "task": self.task.pk})
        self.post_request(post_data)
        self.task.refresh_from_db()
        ok_(
            not self.task.resolved,
            "The task should not automatically resolve when replying.",
        )
        mock_reply.assert_called_with(test_text)

    def test_post_reply_resolve(self, mock_reply):
        """The task should optionally resolve when replying"""
        test_text = "Lorem ipsum"
        form = FlaggedTaskForm({"text": test_text})
        ok_(form.is_valid())
        post_data = form.cleaned_data
        post_data.update({"reply": "truthy", "resolve": True, "task": self.task.pk})
        self.post_request(post_data)
        self.task.refresh_from_db()
        ok_(self.task.resolved, "The task should resolve.")
        mock_reply.assert_called_with(test_text)

    @tag("slow")
    def _test_n_plus_one_query(self, mock_reply):
        """Should make the same number of SQL queries regardless of amount of data"""
        # pylint: disable=unused-argument
        n_plus_one_query(self.client, self.url, FlaggedTaskFactory)