Example #1
0
    def setUp(self):
        self.client = Client(REMOTE_ADDR='localhost')
        self.bob = User(username="******")
        self.bob.save()

        self.tm = TestModel(name="Test1")
        self.tm.save()
        self.tm2 = TestModel(name="Test2")
        self.tm2.save()

        self.test_file1 = NamedTemporaryFile('w+')
        self.test_file1.write("some test text")
        self.test_file1.flush()
        self.test_file1.seek(0)

        self.test_file2 = NamedTemporaryFile('w+')
        self.test_file2.write("some test text")
        self.test_file2.flush()
        self.test_file2.seek(0)
Example #2
0
class TestAttachmentCopying(TestCase):
    def setUp(self):
        self.client = Client(REMOTE_ADDR='localhost')
        self.bob = User(username="******")
        self.bob.save()

        self.tm = TestModel(name="Test1")
        self.tm.save()
        self.tm2 = TestModel(name="Test2")
        self.tm2.save()

        self.test_file1 = NamedTemporaryFile('w+')
        self.test_file1.write("some test text")
        self.test_file1.flush()
        self.test_file1.seek(0)

        self.test_file2 = NamedTemporaryFile('w+')
        self.test_file2.write("some test text")
        self.test_file2.flush()
        self.test_file2.seek(0)

    def testDeepCopying(self):
        """
        Test that doing a deep copy of a file actually attempt to create a
        second version of a file.
        """
        att1 = Attachment.objects.create_for_object(
            self.tm, file=self.test_file1, attached_by=self.bob,
            title="Something", summary="Something")
        f = File(self.test_file1)
        att1.file.save('models.py', f)

        att2 = att1.copy(self.tm2, deepcopy=True)

        # Ensure the saved_copy uses its proper file path
        attachments = Attachment.objects.attachments_for_object(self.tm2)
        for attachment in attachments:
            self.assertEqual(
                attachment.file.name,
                Attachment.get_attachment_dir(attachment,
                                              attachment.file_name())
            )