Exemple #1
0
    def test_be_able_to_get_attachments_for_model_instance(self):
        second = Second.objects.create(third_field="xyz")
        Attachment.objects.create(file_name="x.doc", attach_to=second,
                                  attachment="first bunch of something")
        Attachment.objects.create(file_name="x.doc", attach_to=second,
                                  attachment="second bunch of something")

        first = First.objects.create(first_field="asdf", second_field="xyz")
        Attachment.objects.create(file_name="x.doc", attach_to=first, attachment_type=Attachment.DOCUMENT,
                                  attachment="Hi there, i'm a bunch of bytes")

        for attachment in Attachment.get_attachments_for(second):
            self.assertEqual(attachment.attach_to, second)

        self.assertEqual(Attachment.get_attachments_for(second).count(), 2)
Exemple #2
0
 def test_store_attachment_description(self):
     second = Second.objects.create(third_field="xyz")
     Attachment.objects.create(file_name="x.doc", attach_to=second, attachment="xxx",
                               attachment_type=Attachment.DOCUMENT, description="Three x's")
     self.assertEqual(Attachment.get_attachments_for(second).count(), 1)