Commits

Mikhail Korobov committed e484568

Tests for fab_deploy.crontab

Comments (0)

Files changed (3)

fab_deploy_tests/runtests.py

         sys.exit(1)
 
     FabDeployTest.vm_name = sys.argv[1]
-    common_tests = load([BasicTest, SshTest, MysqlTest])
+    common_tests = load([BasicTest, SshTest, MysqlTest, CrontabTest])
     suites = {
         'fast': TestSuite(common_tests + load([FastPrepareServerTest])),
         'slow': TestSuite(common_tests + load([PrepareServerTest])),

fab_deploy_tests/tests/__init__.py

 from .mysql import *
 from .system_tests import *
 from .utils_tests import *
+from .crontab import *

fab_deploy_tests/tests/crontab.py

+from __future__ import absolute_import
+from fabric.api import *
+from fabtest import fab
+from fab_deploy.crontab import crontab_add, crontab_remove, _get_current, crontab_update, crontab_show
+from fab_deploy_tests.utils import setup_ssh
+from .base import FabDeployTest
+
+class CrontabTest(FabDeployTest):
+    snapshot = 'fabtest-prepared-server'
+
+    def current(self):
+        return fab(_get_current)[0]
+
+    def add(self, content, marker):
+        return fab(crontab_add, content, marker)[0]
+
+    def remove(self, marker):
+        return fab(crontab_remove, marker)[0]
+
+    def update(self, content, marker):
+        return fab(crontab_update, content, marker)[0]
+
+    def test_crontab(self):
+        line1 = '@reboot echo 123'
+        line2 = '@reboot echo 345'
+        new_line2 = '@reboot echo 567'
+
+        self.add(line1, 'line1')
+        self.add(line2, 'line2')
+        current = self.current()
+
+        self.assertTrue(line1 in current)
+        self.assertTrue(line2 in current)
+        self.assertFalse(new_line2 in current)
+
+        self.update(new_line2, 'line2')
+        current = self.current()
+
+        self.assertTrue(line1 in current)
+        self.assertFalse(line2 in current)
+        self.assertTrue(new_line2 in current)
+
+        self.remove('line1')
+        current = self.current()
+
+        self.assertFalse(line1 in current)
+        self.assertFalse(line2 in current)
+        self.assertTrue(new_line2 in current)
+
+        fab(crontab_show)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.