コード例 #1
0
ファイル: test_views.py プロジェクト: PyCon/pycon
    def test_messaging_as_speaker(self):
        speaker = SpeakerFactory(user=self.user)
        self.presentation.speaker = speaker
        self.presentation.save()
        self.login()
        rsp = self.client.get(self.tutorial_url)
        #self.assertIn('id="messages"', rsp.content)

        # We can display the page prompting for a message to send them
        url = reverse(
            'tutorial_message', kwargs={'pk': self.presentation.proposal.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)

        # "Send" a message to those two applications
        test_message = 'One if by land and two if by sea'
        data = {'message': test_message, }
        rsp = self.client.post(url, data=data)
        self.assertEqual(302, rsp.status_code)
        msg = PyConTutorialMessage.objects.get(
            user=self.user,
            tutorial=self.presentation.proposal)
        self.assertEqual(test_message, msg.message)

        send_bulk_emails()

        # For each message, it's visible, so it should have been emailed to
        # both the other attendees and speakers. Total: 1 message for this case
        self.assertEqual(1, len(mail.outbox))
コード例 #2
0
ファイル: test_views.py プロジェクト: tylerdave/PyCon-Website
    def test_messaging_as_speaker(self):
        speaker = SpeakerFactory(user=self.user)
        self.presentation.speaker = speaker
        self.presentation.save()
        self.login()
        rsp = self.client.get(self.tutorial_url)
        #self.assertIn('id="messages"', rsp.content)

        # We can display the page prompting for a message to send them
        url = reverse('tutorial_message',
                      kwargs={'pk': self.presentation.proposal.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)

        # "Send" a message to those two applications
        test_message = 'One if by land and two if by sea'
        data = {
            'message': test_message,
        }
        rsp = self.client.post(url, data=data)
        self.assertEqual(302, rsp.status_code)
        msg = PyConTutorialMessage.objects.get(
            user=self.user, tutorial=self.presentation.proposal)
        self.assertEqual(test_message, msg.message)

        send_bulk_emails()

        # For each message, it's visible, so it should have been emailed to
        # both the other attendees and speakers. Total: 1 message for this case
        self.assertEqual(1, len(mail.outbox))
コード例 #3
0
 def test_call_exceptions(self, mock_send):
     # If sending raises exceptions, we still keep going
     BulkEmailFactory(status=UNSENT)
     BulkEmailFactory(status=UNSENT)
     mock_send.side_effect = Exception("Intentional exception during testing")
     send_bulk_emails()
     self.assertEqual(2, mock_send.call_count)
コード例 #4
0
 def test_call_send(self, mock_send):
     # Make multiple BulkEmails, but we should only call send on
     # the one with the UNSENT status.
     BulkEmailFactory(status=UNSENT)
     BulkEmailFactory(status=ERROR)
     BulkEmailFactory(status=SENT)
     BulkEmailFactory(status=INPROGRESS)
     send_bulk_emails()
     self.assertEqual(1, mock_send.call_count)
コード例 #5
0
 def test_retry_error_emails(self, mock_send):
     # After long enough, retry errored emails
     BulkEmailFactory(status=ERROR, end_time=now())  # Should not retry (yet)
     bulk = BulkEmailFactory(status=ERROR, end_time=now() - 2 * RETRY_INTERVAL)
     send_bulk_emails()
     self.assertEqual(1, mock_send.call_count)
     bulk2 = BulkEmail.objects.get(pk=bulk.pk)
     self.assertEqual(UNSENT, bulk2.status)
     self.assertEqual(1, mock_send.call_count)
コード例 #6
0
 def test_long_inprogress_emails(self, mock_send):
     # If an email has been INPROGRESS too long, the task
     # should change it to UNSENT so we can do something
     # with it.
     bulk = BulkEmailFactory(status=INPROGRESS, start_time=now() - 2 * MAX_TIME)
     BulkEmailFactory(status=INPROGRESS, start_time=now())  # Should not retry (yet)
     send_bulk_emails()
     self.assertEqual(1, mock_send.call_count)
     bulk2 = BulkEmail.objects.get(pk=bulk.pk)
     self.assertEqual(UNSENT, bulk2.status)
     self.assertEqual(1, mock_send.call_count)
コード例 #7
0
 def test_nothing_to_send(self, mock_send):
     # Should just return
     send_bulk_emails()
     self.assertEqual(0, mock_send.call_count)