Esempio n. 1
0
 def test_for_milestone_returns_letters(self):
     qs = Record.objects.for_milestone()
     self.assertFalse(
         qs.filter(letters_letters=IncomingLetterFactory(
             is_spam=Letter.SPAM.spam)).exists())
     self.assertTrue(
         qs.filter(letters_letters=IncomingLetterFactory(
             is_spam=Letter.SPAM.non_spam)).exists())
Esempio n. 2
0
 def test_with_select_related_content(self):
     ilf = IncomingLetterFactory()
     ipp = IncomingParcelPostFactory()
     with self.assertNumQueries(num=1):
         objects = list(Record.objects.with_select_related_content().all())
         self.assertEquals(objects[0].content_object, ilf)
         self.assertEquals(objects[1].content_object, ipp)
Esempio n. 3
0
 def test_serialization_of_letter(self):
     attachment = AttachmentFactory(letter=IncomingLetterFactory())
     result = RecordSerializer(instance=attachment.letter.record,
                               context=self.context).data
     self.assertEqual(result["content_object"]["title"],
                      attachment.letter.title)
     attachments = result["content_object"]["attachments"]
     self.assertEqual(len(attachments), 1)
     attachment = attachments[0]
     self.assertTrue(attachment["url"].startswith("http"))
Esempio n. 4
0
class FixDuplicateMailTestCase(TestCase):
    def test_delete_only_duplicated(self):
        case = CaseFactory()
        in1 = IncomingLetterFactory(record__case=case)
        in2 = IncomingLetterFactory(record__case=case)
        ou1 = OutgoingLetterFactory(record__case=case)
        in_static_id = IncomingLetterFactory(
            record__case=case, eml__msg_id="*****@*****.**"
        )
        in_dupe_id = IncomingLetterFactory(
            record__case=case, eml__msg_id="*****@*****.**"
        )
        stdout = StringIO()
        call_command(
            "fix_duplicate_mail",
            "--monitoring-pk={}".format(case.monitoring.pk),
            "--delete",
            stdout=stdout,
        )
        self.assertTrue(Letter.objects.filter(pk=in1.id).exists())
        self.assertTrue(Letter.objects.filter(pk=in2.id).exists())
        self.assertTrue(Letter.objects.filter(pk=ou1.id).exists())
        self.assertTrue(Letter.objects.filter(pk=in_static_id.id).exists())
        self.assertFalse(Letter.objects.filter(pk=in_dupe_id.id).exists())
Esempio n. 5
0
    def test_hide_draft(self):
        outgoing_letter = OutgoingLetterFactory(
            record__case__monitoring=self.monitoring)
        incoming_letter = IncomingLetterFactory(
            record__case__monitoring=self.monitoring)
        draft_letter = DraftLetterFactory(
            record__case__monitoring=self.monitoring)
        response = self.client.get(self.get_url())
        self.assertNotContains(
            response,
            outgoing_letter.body,
            msg_prefix="Response contains outgoing letter. ",
        )
        self.assertNotContains(
            response,
            incoming_letter.body,
            msg_prefix="Response contains incoming letter. ",
        )

        self.assertContains(response, draft_letter.body)
        self.assertContains(response, draft_letter.note)
Esempio n. 6
0
 def test_display_letter(self):
     letter = IncomingLetterFactory(
         record__case__monitoring=self.monitoring)
     response = self.client.get(self.get_url())
     self.assertContains(response, letter.body)
     self.assertContains(response, letter.note)
Esempio n. 7
0
 def test_contains_letter(self):
     letter = IncomingLetterFactory(record__case=self.case)
     response = self.client.get(self.get_url())
     self.assertContains(response, letter.body)
Esempio n. 8
0
 def test_not_contains_spam_letter(self):
     letter = IncomingLetterFactory(record__case=self.case, is_spam=Letter.SPAM.spam)
     response = self.client.get(self.get_url())
     self.assertNotContains(response, letter.body)
Esempio n. 9
0
        stdout = StringIO()
        call_command(
            "fix_duplicate_mail",
            "--monitoring-pk={}".format(case.monitoring.pk),
            "--delete",
            stdout=stdout,
        )
        self.assertTrue(Letter.objects.filter(pk=in1.id).exists())
        self.assertTrue(Letter.objects.filter(pk=in2.id).exists())
        self.assertTrue(Letter.objects.filter(pk=ou1.id).exists())
        self.assertTrue(Letter.objects.filter(pk=in_static_id.id).exists())
        self.assertFalse(Letter.objects.filter(pk=in_dupe_id.id).exists())

    def test_delete_only_when_force_delete(self):
        case = CaseFactory()
        IncomingLetterFactory(record__case=case, eml__msg_id="*****@*****.**")
        in_dupe_id = IncomingLetterFactory(
            record__case=case, eml__msg_id="*****@*****.**"
        )
        stdout = StringIO()
        call_command(
            "fix_duplicate_mail",
            "--monitoring-pk={}".format(case.monitoring.pk),
            stdout=stdout,
        )
        self.assertTrue(Letter.objects.filter(pk=in_dupe_id.id).exists())
        call_command(
            "fix_duplicate_mail",
            "--monitoring-pk={}".format(case.monitoring.pk),
            "--delete",
            stdout=stdout,
Esempio n. 10
0
 def setUp(self):
     self.registry = record_type_registry
     self.object = IncomingLetterFactory()
Esempio n. 11
0
 def test_content_template(self):
     letter = IncomingLetterFactory()
     self.assertEqual(letter.record.content_template,
                      "letters/_letter_content_item.html")