Commits

Tim Savage committed a97b4a1 Draft

Added tests for webserver.apache and webserver.nginx

Comments (0)

Files changed (6)

denim/django/south.py

     """
     if non_applied_only:
         with settings(hide('warnings'), warn_only=True):
-            result = django.manage('migrate', args='--list | grep -v "(\*)"', revision=revision, use_sudo=False)
+            result = django.manage('migrate', args=['--list | grep -v "(\*)"'], revision=revision, use_sudo=False)
         if result:
             if result.find('( )') != -1:
                 print(colors.red('*'*34))

denim/webserver/apache.py

 # -*- encoding:utf8 -*-
 from fabric.api import sudo
+from denim import utils
 
 
 def upload_config(name_prefix=None):
 
 
 def test_config():
-    sudo('/usr/sbin/apache2ctl configtest')
+    utils.run_as('/usr/sbin/apache2ctl configtest', use_sudo=True)
 
 
 def start():
-    sudo('/etc/init.d/apache2 start')
+    utils.run_as('/etc/init.d/apache2 start', use_sudo=True)
 
 
 def stop():
-    sudo('/etc/init.d/apache2 stop')
+    utils.run_as('/etc/init.d/apache2 stop', use_sudo=True)
 
 
 def restart(check_config=True):
     if check_config:
         test_config()
-    sudo('/etc/init.d/apache2 restart')
+    utils.run_as('/etc/init.d/apache2 restart', use_sudo=True)
 
 
 def reload(check_config=True):
     if check_config:
         test_config()
-    sudo('/etc/init.d/apache2 reload')
+    utils.run_as('/etc/init.d/apache2 reload', use_sudo=True)

denim/webserver/nginx.py

 # -*- encoding:utf8 -*-
-from fabric.api import *
+from fabric.api import put
 from denim import (paths, system, utils)
 
 SERVICE_NAME = 'nginx'
 
 
 def start():
-    sudo('/etc/init.d/nginx start')
+    utils.run_as('/etc/init.d/nginx start', use_sudo=True)
 
 
 def stop():
-    sudo('/etc/init.d/nginx stop')
+    utils.run_as('/etc/init.d/nginx stop', use_sudo=True)
 
 
 def restart(check_config=True):
     if check_config:
         test_config()
-    sudo('/etc/init.d/nginx restart')
+    utils.run_as('/etc/init.d/nginx restart', use_sudo=True)
 
 
 def reload(check_config=True):
     if check_config:
         test_config()
-    sudo('/usr/sbin/nginx -s reload')
+    utils.run_as('/usr/sbin/nginx -s reload', use_sudo=True)
Add a comment to this file

tests/webserver/__init__.py

Empty file added.

tests/webserver/apache.py

+from denim.constants import RootUser
+from tests._utils import ApiTestCase
+from denim.webserver import apache
+
+
+class TestWebserverApache(ApiTestCase):
+    def test_test_config(self):
+        apache.test_config()
+
+        self.assertSudo('/usr/sbin/apache2ctl configtest', user=RootUser)
+
+    def test_start(self):
+        apache.start()
+
+        self.assertSudo('/etc/init.d/apache2 start', user=RootUser)
+
+    def test_stop(self):
+        apache.stop()
+
+        self.assertSudo('/etc/init.d/apache2 stop', user=RootUser)
+
+    def test_restart(self):
+        apache.restart(False)
+
+        self.assertSudo('/etc/init.d/apache2 restart', user=RootUser)
+
+    def test_restart(self):
+        apache.restart(False)
+
+        self.assertSudo('/etc/init.d/apache2 restart', user=RootUser)
+
+    def test_reload(self):
+        apache.reload(False)
+
+        self.assertSudo('/etc/init.d/apache2 reload', user=RootUser)

tests/webserver/nginx.py

+from denim.constants import RootUser
+from tests._utils import ApiTestCase
+from denim.webserver import nginx
+
+
+class TestWebserverNginx(ApiTestCase):
+    def test_test_config(self):
+        nginx.test_config()
+
+        self.assertSudo('/usr/sbin/nginx -t', user=RootUser)
+
+    def test_start(self):
+        nginx.start()
+
+        self.assertSudo('/etc/init.d/nginx start', user=RootUser)
+
+    def test_stop(self):
+        nginx.stop()
+
+        self.assertSudo('/etc/init.d/nginx stop', user=RootUser)
+
+    def test_restart(self):
+        nginx.restart(False)
+
+        self.assertSudo('/etc/init.d/nginx restart', user=RootUser)
+
+    def test_restart(self):
+        nginx.restart(False)
+
+        self.assertSudo('/etc/init.d/nginx restart', user=RootUser)
+
+    def test_reload(self):
+        nginx.reload(False)
+
+        self.assertSudo('/usr/sbin/nginx -s reload', user=RootUser)
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.