1 # -*- coding: utf-8 -*-
2 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
5 from __future__ import unicode_literals
7 from tempfile import NamedTemporaryFile
8 from django.core.files.base import ContentFile
9 from django.test import TestCase
10 from tests.models import SomeModel
13 class StorageTestCase(TestCase):
15 obj = SomeModel.objects.create()
16 obj.attachment.save("text.txt", ContentFile(b"A"))
17 path = obj.attachment.path
18 self.assertEqual(open(path, 'rb').read(), b"A")
19 # Now save again under the same filename.
20 obj.attachment.save("text.txt", ContentFile(b"B"))
21 self.assertEqual(open(path, 'rb').read(), b"B")