diff --git a/trove/tests/unittests/guestagent/test_dbaas.py b/trove/tests/unittests/guestagent/test_dbaas.py index 3802cb4313..c2cb0b0105 100644 --- a/trove/tests/unittests/guestagent/test_dbaas.py +++ b/trove/tests/unittests/guestagent/test_dbaas.py @@ -448,6 +448,25 @@ class MySqlAdminTest(testtools.TestCase): 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): diff --git a/trove/tests/unittests/guestagent/test_manager.py b/trove/tests/unittests/guestagent/test_manager.py index 0bf0af5269..2368bf98a6 100644 --- a/trove/tests/unittests/guestagent/test_manager.py +++ b/trove/tests/unittests/guestagent/test_manager.py @@ -100,6 +100,15 @@ class GuestAgentManagerTest(testtools.TestCase): self.assertThat(users, Equals(['user1'])) 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): when(dbaas.MySqlAdmin).enable_root().thenReturn('user_id_stuff') user_id = self.manager.enable_root(self.context)