Only remove contents of directory when clicking 'clear cache'
[mevemon] / package / src / tests / test_util.py
index 24ca9ec..e7f05a7 100644 (file)
@@ -1,5 +1,8 @@
 """ this module tests the util.py module """
 import unittest
+import tempfile
+import shutil
+import os
 
 import util
 
@@ -10,5 +13,21 @@ class TestUtil(unittest.TestCase):
         for number in NUMBERS.keys():
             self.assertEqual(util.comma(number), NUMBERS[number])
 
+    def test_clean_dir(self):
+        self._setup_files()
+        try: 
+            self.assertEqual(len(os.listdir(self.basedir)), 3)
+            util.clean_dir(self.basedir)
+            self.assertTrue(os.path.exists(self.basedir))
+            self.assertEqual(len(os.listdir(self.basedir)), 0)
+        finally:
+            if os.path.exists(self.basedir):
+                shutil.rmtree(self.basedir)
 
+    def _setup_files(self):
+        self.basedir = os.path.join(tempfile.gettempdir(), "mevemontest")
+        os.mkdir(self.basedir)
+        os.mkdir(os.path.join(self.basedir, "testdir"))
+        os.system("touch %s" % os.path.join(self.basedir, "testfile1"))
+        os.system("touch %s" % os.path.join(self.basedir, "testfile2"))