Example #1
0
    def test_write_success(self, size, filename, content):
        file_storage = FileStorage(size)
        file = File(filename, content)
        prev_size = file_storage.get_available_size()
        res = file_storage.write(file)

        assert file in file_storage.get_files() \
               and file_storage.get_available_size() == prev_size - file.get_size() \
               and res \
               and file.get_size() <= prev_size or \
               not res and file not in file_storage.get_files() \
               and file_storage.get_available_size() == prev_size, "Invalid write "
Example #2
0
 def test_get_available_size_after_any_write(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     assert file_storage.get_available_size() == file_storage.get_max_size() - file.get_size(), \
         "Invalid get_available_size"
Example #3
0
 def test_get_max_size_before_any_write(self, storage_size_data):
     (size) = storage_size_data
     file_storage = FileStorage(size)
     assert file_storage.get_max_size() == size, "Invalid get_max_size"
Example #4
0
 def test_get_files_after_any_write(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     assert file in file_storage.get_files(), "Invalid get_files"
Example #5
0
 def test_get_files_before_any_write(self, storage_size_data):
     (size) = storage_size_data
     file_storage = FileStorage(size)
     assert file_storage.get_files() == [], "Invalid get_files"
Example #6
0
 def test_init(self, size):
     FileStorage(size)
Example #7
0
 def test_delete_success(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     assert file_storage.delete(file.get_filename()) and file not in file_storage.get_files()
Example #8
0
 def test_delete_failed(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     assert not file_storage.delete(filename)
Example #9
0
 def test_get_file_return_none(self, size_and_filename_data):
     (size, filename) = size_and_filename_data
     file_storage = FileStorage(size)
     assert file_storage.get_file(filename) is None
Example #10
0
 def test_get_file_return_file(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     assert file_storage.get_file(file.get_filename()) == file
Example #11
0
 def test_is_exists_return_false(self, size_and_filename_data):
     (size, filename) = size_and_filename_data
     file_storage = FileStorage(size)
     assert not file_storage.is_exists(filename)
Example #12
0
 def test_is_exists_return_true(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     assert file_storage.is_exists(file.get_filename())
Example #13
0
 def test_write_with_existing_file(self, size_filename_content_data):
     (size, filename, content) = size_filename_content_data
     file_storage = FileStorage(size)
     file = File(filename, content)
     file_storage.write(file)
     file_storage.write(file)