Merge "Unittest Case for get_user"

This commit is contained in:
Jenkins 2013-12-06 19:47:25 +00:00 committed by Gerrit Code Review
commit 5eede25ae4
2 changed files with 28 additions and 0 deletions

View File

@ -448,6 +448,25 @@ class MySqlAdminTest(testtools.TestCase):
self.assertTrue("AND Marker >= '" + marker + "'" in args[0].text) self.assertTrue("AND Marker >= '" + marker + "'" in args[0].text)
def test_get_user(self):
"""
Unit tests for mySqlAdmin.get_user.
This test case checks if the sql query formed by the get_user method
is correct or not by checking with expected query.
"""
username = "user1"
hostname = "host"
self.mySqlAdmin.get_user(username, hostname)
args, _ = dbaas.LocalSqlClient.execute.call_args
expected = ["SELECT User, Host",
"FROM mysql.user",
"WHERE Host != 'localhost' AND User = 'user1'",
"ORDER BY User, Host",
]
for text in expected:
self.assertTrue(text in args[0].text, "%s not in query." % text)
class MySqlAppTest(testtools.TestCase): class MySqlAppTest(testtools.TestCase):

View File

@ -100,6 +100,15 @@ class GuestAgentManagerTest(testtools.TestCase):
self.assertThat(users, Equals(['user1'])) self.assertThat(users, Equals(['user1']))
verify(dbaas.MySqlAdmin).list_users(None, None, False) verify(dbaas.MySqlAdmin).list_users(None, None, False)
def test_get_users(self):
username = ['user1']
hostname = ['host']
when(dbaas.MySqlAdmin).get_user(username,
hostname).thenReturn(['user1'])
users = self.manager.get_user(self.context, username, hostname)
self.assertThat(users, Equals(['user1']))
verify(dbaas.MySqlAdmin).get_user(username, hostname)
def test_enable_root(self): def test_enable_root(self):
when(dbaas.MySqlAdmin).enable_root().thenReturn('user_id_stuff') when(dbaas.MySqlAdmin).enable_root().thenReturn('user_id_stuff')
user_id = self.manager.enable_root(self.context) user_id = self.manager.enable_root(self.context)