Esempio n. 1
0
 def test_init(self):
     StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
     with patch(settings, RANDOM_FILENAME_LENGTH=NotImplemented):
         storage = StorageClass()
         self.assertFilename(storage.get_available_name(''), '')
         storage = StorageClass(randomfilename_length=10)
         self.assertFilename(storage.get_available_name(''), '', length=10)
     with patch(settings, RANDOM_FILENAME_LENGTH=5):
         storage = StorageClass()
         self.assertFilename(storage.get_available_name(''), '', length=5)
         storage = StorageClass(randomfilename_length=20)
         self.assertFilename(storage.get_available_name(''), '', length=20)
Esempio n. 2
0
 def test_get_available_name(self):
     with media_root():
         storage = RandomFilenameFileSystemStorage(
             randomfilename_length=DEFAULT_LENGTH)
         self.assertFilename(storage.get_available_name(''), '')
         self.assertFilename(storage.get_available_name('foo'), 'foo')
         self.assertFilename(storage.get_available_name('foo.txt'),
                             'foo.txt')
         self.assertFilename(storage.get_available_name('foo/bar'),
                             'foo/bar')
         self.assertFilename(storage.get_available_name('foo/bar.txt'),
                             'foo/bar.txt')
 def test_init(self):
     StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
     with patch(settings, RANDOM_FILENAME_LENGTH=NotImplemented):
         storage = StorageClass()
         self.assertFilename(storage.get_available_name(''), '')
         storage = StorageClass(randomfilename_length=10)
         self.assertFilename(storage.get_available_name(''), '', length=10)
     with patch(settings, RANDOM_FILENAME_LENGTH=5):
         storage = StorageClass()
         self.assertFilename(storage.get_available_name(''), '', length=5)
         storage = StorageClass(randomfilename_length=20)
         self.assertFilename(storage.get_available_name(''), '', length=20)
 def test_get_available_name(self):
     with media_root():
         storage = RandomFilenameFileSystemStorage(
             randomfilename_length=DEFAULT_LENGTH
         )
         self.assertFilename(storage.get_available_name(''), '')
         self.assertFilename(storage.get_available_name('foo'), 'foo')
         self.assertFilename(storage.get_available_name('foo.txt'),
                             'foo.txt')
         self.assertFilename(storage.get_available_name('foo/bar'),
                             'foo/bar')
         self.assertFilename(storage.get_available_name('foo/bar.txt'),
                             'foo/bar.txt')
Esempio n. 5
0
    def test_get_available_name_retry(self):
        # With retries
        StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
        storage = StorageClass(tries=2)
        stub_random_string.count = 0
        with patch(django_randomfilenamestorage.storage,
                   random_string=stub_random_string):
            self.assertEqual(storage.get_available_name('name.txt'), '2.txt')

        # Without retries
        StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
        storage = StorageClass(tries=2)
        stub_random_string.count = 0
        with patch(django_randomfilenamestorage.storage,
                   random_string=stub_random_string):
            self.assertEqual(
                storage.get_available_name('name.txt', retry=False), '1.txt')
    def test_get_available_name_retry(self):
        # With retries
        StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
        storage = StorageClass(tries=2)
        stub_random_string.count = 0
        with patch(django_randomfilenamestorage.storage,
                   random_string=stub_random_string):
            self.assertEqual(storage.get_available_name('name.txt'), '2.txt')

        # Without retries
        StorageClass = RandomFilenameMetaStorage(storage_class=StubStorage)
        storage = StorageClass(tries=2)
        stub_random_string.count = 0
        with patch(django_randomfilenamestorage.storage,
                   random_string=stub_random_string):
            self.assertEqual(storage.get_available_name('name.txt',
                                                        retry=False),
                             '1.txt')