0.5: Django 3.2 support, drop Django<1.11, Python<3.6, remove some compatibility...
[fnpdjango.git] / tests / tests / test_storage.py
1 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
3 #
4 from tempfile import NamedTemporaryFile
5 from django.core.files.base import ContentFile
6 from django.test import TestCase
7 from tests.models import SomeModel
8
9
10 class StorageTestCase(TestCase):
11     def test_save(self):
12         obj = SomeModel.objects.create()
13         obj.attachment.save("text.txt", ContentFile(b"A"))
14         path = obj.attachment.path
15         self.assertEqual(open(path, 'rb').read(), b"A")
16         # Now save again under the same filename.
17         obj.attachment.save("text.txt", ContentFile(b"B"))
18         self.assertEqual(open(path, 'rb').read(), b"B")