Python 3, Django 1.7+ compatilibity, some tests.
[fnpdjango.git] / tests / tests / test_storage.py
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.
4 #
5 from __future__ import unicode_literals
6
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
11
12
13 class StorageTestCase(TestCase):
14     def test_save(self):
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")