From 2cb6e2dd796107e365c661203e790d9e849921ef Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Sun, 21 Aug 2011 20:08:39 +0300 Subject: [PATCH] ppf: Add test suite for TreeTextFileAccess class. --- ppf/new/tests/test_storage.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ppf/new/tests/test_storage.py b/ppf/new/tests/test_storage.py index ff1851f..706bc9e 100644 --- a/ppf/new/tests/test_storage.py +++ b/ppf/new/tests/test_storage.py @@ -127,5 +127,40 @@ class StorageTest(unittest.TestCase): id = storage.find_last_numeric_subfolder(self.path) self.assertEqual(id, 1401) + +class TreeTextFileAccessTest(unittest.TestCase): + """ + Test suite for TreeTextFileAccess class in storage.py. + """ + + # Class specific variables. Initialized in setUp, used throughout tests. + path = "/tmp/ttfa-test" + + def setUp(self): + """Create folder. Initialize object. """ + os.mkdir(self.path) + + def tearDown(self): + """Remove base folder.""" + shutil.rmtree(self.path) + + def test_add_swarm_folder_and_file_are_created(self): + create_numeric_subfolders_sequential(self.path) + expected_swarm_subfolder = 6 + + # Create instance of class and add swarm. + a = storage.TreeTextFileAccess(self.path) + s = storage.Swarm(torrent_filename = "fedora.torrent", + data_size = 102400) + a.add_swarm(s) + + expected_swarm_path = os.path.join(self.path, + str(expected_swarm_subfolder)) + expected_swarm_config = os.path.join(expected_swarm_path, "swarm.conf") + + expected_true = os.path.isdir(expected_swarm_path) and \ + os.path.isfile(expected_swarm_config) + self.assertEqual(expected_true, True) + if __name__ == "__main__": unittest.main() -- 2.20.1