Commits

Mikhail Korobov committed 46b0fdd

More tests for new mysql features. See #20.

Comments (0)

Files changed (2)

fab_deploy_tests/runtests.py

     atexit.register(beep)
     FabDeployTest.vm_name = sys.argv[1]
 
-    common = [SshTest, MysqlTest, BasicTest]
+    common = [SshTest, MysqlTest, MysqlNonRootTest, BasicTest]
 
     suites = {
         'misc': TestSuite(load(common + [

fab_deploy_tests/tests/mysql.py

 from __future__ import absolute_import
 from fabric.api import *
 from fabtest import fab
-from fab_deploy.mysql import mysql_install, _mysql_is_installed, mysql_create_db, mysql_execute
+from fab_deploy.mysql import (mysql_install, _mysql_is_installed, mysqldump,
+                              mysql_create_db, mysql_execute, mysql_create_user)
 from ..utils import setup_sudo
 from .base import FabDeployTest
 
     return fab(_mysql_is_installed)[0]
 
 def database_exists(db_name):
-    databases = fab(mysql_execute, 'show databases;')[0].splitlines()
+    databases = fab(mysql_execute, 'show databases;', 'root')[0].splitlines()
     return db_name in databases
 
 class MysqlTest(FabDeployTest):
         fab(mysql_create_db)
         self.assertTrue(database_exists('new_database'))
 
+
+class MysqlNonRootTest(FabDeployTest):
+    host = 'root@127.0.0.1:2222'
+
+    def setup_conf(self):
+        super(MysqlNonRootTest, self).setup_conf()
+        env.conf['DB_ROOT_PASSWORD'] = '123'
+        env.conf['DB_PASSWORD'] = 'foo123'
+        env.conf['DB_NAME'] = 'new_database'
+        env.conf['DB_USER'] = 'foo'
+
+    def test_mysql(self):
+        setup_sudo()
+
+        self.assertFalse(mysql_is_installed())
+
+        fab(mysql_install)
+        self.assertTrue(mysql_is_installed())
+
+        self.assertFalse(database_exists('new_database'))
+        fab(mysql_create_db)
+        self.assertTrue(database_exists('new_database'))
+
+        # re-creating user shouldn't break anything
+        fab(mysql_create_user)
+
+        # this will fail if permissions are not set correctly
+        output = fab(mysql_execute, 'use new_database; create table baz (id int); show tables;')[0]
+        tables = output.splitlines()[1:]
+        self.assertEqual(tables[0], 'baz')
+
+        # mysqldump should work
+        fab(mysqldump, env.conf.HOME_DIR)
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.