Ejemplo n.º 1
0
    def test_soft_delete(self):
        """Test the soft delete method"""
        foia = FOIARequestFactory(status="processed")
        FOIAFileFactory.create_batch(size=3, comm__foia=foia)
        user = UserFactory(is_superuser=True)

        nose.tools.eq_(foia.get_files().count(), 3)
        nose.tools.eq_(
            RawEmail.objects.filter(email__communication__foia=foia).count(),
            3)

        foia.soft_delete(user, "final message", "note")
        foia.refresh_from_db()
        self.run_commit_hooks()

        # final communication we send out is not cleared
        for comm in list(foia.communications.all())[:-1]:
            nose.tools.eq_(comm.communication, "")
        nose.tools.eq_(foia.get_files().count(), 0)
        # one raw email left on the final outgoing message
        nose.tools.eq_(
            RawEmail.objects.filter(email__communication__foia=foia).count(),
            1)
        nose.tools.eq_(foia.last_request().communication, "final message")
        nose.tools.eq_(foia.notes.first().note, "note")

        nose.tools.ok_(foia.deleted)
        nose.tools.ok_(foia.embargo)
        nose.tools.ok_(foia.permanent_embargo)
        nose.tools.eq_(foia.status, "abandoned")
Ejemplo n.º 2
0
 def test_attachments(self):
     """Test a message with an attachment"""
     try:
         foia = FOIARequestFactory()
         to_ = foia.get_request_email()
         attachments = [StringIO("Good file"), StringIO("Ignore File")]
         attachments[0].name = "data.pdf"
         attachments[1].name = "ignore.p7s"
         self.mailgun_route(to_=to_, attachments=attachments)
         foia.refresh_from_db()
         file_path = date.today().strftime("foia_files/%Y/%m/%d/data.pdf")
         nose.tools.eq_(foia.get_files().count(), 1)
         nose.tools.eq_(foia.get_files().first().ffile.name, file_path)
     finally:
         foia.communications.first().files.first().delete()
         file_path = os.path.join(settings.SITE_ROOT, "static/media/", file_path)
         if os.path.exists(file_path):
             os.remove(file_path)