Commits

Crispin Wellington  committed 563f66f

RemoteCache tests

  • Participants
  • Parent commits 4132571
  • Branches virtualenv-caching

Comments (0)

Files changed (1)

File tests/test_cache.py

 import tempfile
 import shutil
 
-from parcel.cache import FileCache
+from parcel.cache import FileCache, RemoteCache
 from mixins import WebServerMixin
 from mock import MagicMock, patch
-
+from parcel_mocks import mock_local, run
 
 ## Some functions to help building and clearing a directory
 def mkdir():
 ## Test Suite
 ##
 class CacheTestSuite(unittest.TestCase, WebServerMixin):
-    """Versions test cases."""
+    """Test that the cache actually caches."""
     def setUp(self):
         self.path = None  # use this in tests for a directory that will always be deleted
     
             cache = FileCache(self.path)
         mock_makedirs.assert_called_once(self.path)
 
+mocks_to_reset = [ run ]
+
+class RemoteCacheTestSuite(unittest.TestCase):
+    """Remote cache tests"""
+    def setUp(self):
+        # make the directory locally, cause we will reroute run to local
+        if os.path.exists("/tmp/test-remote-cache/"):
+            shutil.rmtree("/tmp/test-remote-cache/")
+        os.makedirs("/tmp/test-remote-cache/")
+        self.cache = RemoteCache("/tmp/test-remote-cache/", makedir=False)
+    
+    def tearDown(self):
+        shutil.rmtree("/tmp/test-remote-cache/")
+        for m in mocks_to_reset:
+            m.reset_mock()
+
+    def test_location(self):
+        loc = self.cache.location("abcdef")
+        self.assertTrue(loc.endswith("/abcdef"))
+        self.assertTrue(loc.startswith(self.cache.remote_path))
+
+    @patch('parcel.cache.run', run)
+    def test_delete(self):
+        self.cache.delete("abcdef")
+        statement = run.call_args[0][0]
+        self.assertTrue(statement.startswith('rm -rf'))
+        self.assertTrue('abcdef' in statement)
+
+    @patch('parcel.cache.run', run)
+    def test_purge(self):
+        self.cache.purge()
+        statement = run.call_args[0][0]
+        self.assertTrue(statement.startswith('rm -rf'))
+        
+    @patch('parcel.cache.run', mock_local())
+    @patch('fabric.contrib.files.exists', os.path.exists)   #used in is_cached
+    def test_store(self):
+        self.cache.store(".","abcdef")
+        self.assertTrue(os.path.exists("/tmp/test-remote-cache/abcdef"))
+        self.assertTrue(self.cache.is_cached("abcdef"))
+        
+    @patch('parcel.cache.run', mock_local())
+    @patch('fabric.contrib.files.exists', os.path.exists)   #used in is_cached
+    def test_get(self):
+        self.cache.store(".","abcdef")
+        self.cache.get("abcdef","/tmp/test-remote-cache-get")
+        self.assertTrue(os.path.exists("/tmp/test-remote-cache-get"))
+        
+