Updated Branches: refs/heads/trunk 06ee3b3fc -> 9823d5786
AMBARI-3465. unit test failure - test_check_web_ui. (swagle) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/9823d578 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/9823d578 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/9823d578 Branch: refs/heads/trunk Commit: 9823d5786589907280301aeb30a77244e1ef173f Parents: 06ee3b3 Author: Siddharth Wagle <[email protected]> Authored: Fri Oct 4 19:08:46 2013 -0700 Committer: Siddharth Wagle <[email protected]> Committed: Fri Oct 4 19:08:46 2013 -0700 ---------------------------------------------------------------------- .../modules/hdp-hadoop/files/checkWebUI.py | 4 +-- ambari-agent/src/test/python/TestCheckWebUI.py | 27 ++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/9823d578/ambari-agent/src/main/puppet/modules/hdp-hadoop/files/checkWebUI.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/puppet/modules/hdp-hadoop/files/checkWebUI.py b/ambari-agent/src/main/puppet/modules/hdp-hadoop/files/checkWebUI.py index faa11e3..e24e7b5 100644 --- a/ambari-agent/src/main/puppet/modules/hdp-hadoop/files/checkWebUI.py +++ b/ambari-agent/src/main/puppet/modules/hdp-hadoop/files/checkWebUI.py @@ -38,14 +38,14 @@ def main(): try: conn = httplib.HTTPConnection(host, port) # This can be modified to get a partial url part to be sent with request - response = conn.request("GET", "/") + conn.request("GET", "/") httpCode = conn.getresponse().status conn.close() except Exception: httpCode = 404 if httpCode != 200: - print "Cannot access WEB UI on: " + url + print "Cannot access WEB UI on: http://" + host + ":" + port exit(1) http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/9823d578/ambari-agent/src/test/python/TestCheckWebUI.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/TestCheckWebUI.py b/ambari-agent/src/test/python/TestCheckWebUI.py index ea45400..c7d4ac4 100644 --- a/ambari-agent/src/test/python/TestCheckWebUI.py +++ b/ambari-agent/src/test/python/TestCheckWebUI.py @@ -39,33 +39,38 @@ class TestMain(unittest.TestCase): sys.stdout = sys.__stdout__ @patch("optparse.OptionParser.parse_args") - @patch('urllib.urlopen') - def test_check_web_ui(self, urlopen_mock, parse_args_mock): + @patch('httplib.HTTPConnection') + def test_check_web_ui(self, http_mock, parse_args_mock): #Positive scenario options = MagicMock() options.hosts = 'host1,host2' options.port = '10000' - get_code_mock = MagicMock() - get_code_mock.getcode.return_value = 200 - urlopen_mock.return_value = get_code_mock - parse_args_mock.return_value = (options, MagicMock) + http_conn = http_mock.return_value + http_conn.getresponse.return_value = MagicMock(status=200) + checkWebUI.main() + + self.assertTrue(http_conn.request.called) + self.assertTrue(http_conn.getresponse.called) + self.assertTrue(http_conn.close.called) #Negative scenario options = MagicMock() options.hosts = 'host1,host2' - options.port = '10000' - get_code_mock = MagicMock() - get_code_mock.getcode.return_value = 404 - urlopen_mock.return_value = get_code_mock - + options.port = '10000' parse_args_mock.return_value = (options, MagicMock) + http_conn.getresponse.return_value = MagicMock(status=404) + try: checkWebUI.main() except SystemExit, e: self.assertEqual(e.code, 1) + self.assertTrue(http_conn.request.called) + self.assertTrue(http_conn.getresponse.called) + self.assertTrue(http_conn.close.called) + if __name__ == "__main__": unittest.main()
