Skip to content

Commit

Permalink
Fix methods and tests for newer django versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwoods committed Aug 15, 2017
1 parent 14a1872 commit 2ab654a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import tempfile
from os import path
from datetime import datetime
from packaging import version

import django
from django.core.files.base import File
from django.core.files.storage import FileSystemStorage, Storage
from django.test import TestCase
Expand All @@ -20,6 +22,8 @@

from . import models

DJANGO_VERSION = django.get_version()


class StorageTests(TestCase):

Expand Down Expand Up @@ -140,9 +144,15 @@ def test_storage_celery_save(self):
self.assertEqual(storage.size(subdir_path),
os.stat(self.test_file_path).st_size)
self.assertEqual(storage.url(self.test_file_name), self.test_file_name)
self.assertIsInstance(storage.accessed_time(subdir_path), datetime)
self.assertIsInstance(storage.created_time(subdir_path), datetime)
self.assertIsInstance(storage.modified_time(subdir_path), datetime)

if version.parse(DJANGO_VERSION) <= version.parse('2'):
self.assertIsInstance(storage.accessed_time(subdir_path), datetime)
self.assertIsInstance(storage.created_time(subdir_path), datetime)
self.assertIsInstance(storage.modified_time(subdir_path), datetime)
else:
self.assertIsInstance(storage.get_accessed_time(subdir_path), datetime)
self.assertIsInstance(storage.get_created_time(subdir_path), datetime)
self.assertIsInstance(storage.get_modified_time(subdir_path), datetime)

subdir_name = 'queued_storage_2.txt'
testfile = storage.open(subdir_name, 'w')
Expand Down Expand Up @@ -263,11 +273,9 @@ def test_remote_file_field(self):

field = models.TestModel._meta.get_field('remote')
field.storage = storage

obj = models.TestModel()
obj.testfile.save(self.test_file_name, File(self.test_file))
obj.remote.save(self.test_file_name, File(self.test_file))
obj.save()

self.assertIsNone(getattr(obj.testfile.storage, 'result', None))

result = obj.remote.transfer()
Expand Down

0 comments on commit 2ab654a

Please sign in to comment.