Merge "Get auth token when checking deployment"
[functest-xtesting.git] / functest / tests / unit / ci / test_check_deployment.py
index 1f44d07..fc6368e 100644 (file)
@@ -41,7 +41,7 @@ class CheckDeploymentTesting(unittest.TestCase):
     def test_check_rc(self):
         with mock.patch('functest.ci.check_deployment.os.path.isfile',
                         returns=True) as m, \
-                mock.patch('__builtin__.open',
+                mock.patch('six.moves.builtins.open',
                            mock.mock_open(read_data='OS_AUTH_URL')):
             self.deployment.check_rc()
             self.assertTrue(m.called)
@@ -55,7 +55,7 @@ class CheckDeploymentTesting(unittest.TestCase):
             self.assertTrue(msg in context)
 
     def test_check_rc_missing_os_auth(self):
-        with mock.patch('__builtin__.open',
+        with mock.patch('six.moves.builtins.open',
                         mock.mock_open(read_data='test')), \
                 self.assertRaises(Exception) as context:
             msg = 'OS_AUTH_URL not defined in {}.'.format(self.rc_file)
@@ -63,9 +63,12 @@ class CheckDeploymentTesting(unittest.TestCase):
 
     def test_check_auth_endpoint(self):
         with mock.patch('functest.ci.check_deployment.verify_connectivity',
-                        return_value=True) as m:
+                        return_value=True) as m,\
+                mock.patch('functest.ci.check_deployment.get_auth_token',
+                           return_value='gAAAAABaOhXGS') as mock_token:
             self.deployment.check_auth_endpoint()
             self.assertTrue(m.called)
+            self.assertTrue(mock_token.called)
 
     def test_check_auth_endpoint_not_reachable(self):
         with mock.patch('functest.ci.check_deployment.verify_connectivity',
@@ -170,6 +173,26 @@ class CheckDeploymentTesting(unittest.TestCase):
             self.assertRaises(Exception)
             self.assertTrue(m.called)
 
+    @mock.patch('functest.ci.check_deployment.LOGGER.info')
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_ext_net_name')
+    def test_check_extnet(self, mock_getext, mock_loginfo):
+        test_network = 'ext-net'
+        mock_getext.return_value = test_network
+        self.deployment.check_ext_net()
+        self.assertTrue(mock_getext.called)
+        mock_loginfo.assert_called_once_with(
+            "External network found: %s", test_network)
+
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_ext_net_name', return_value='')
+    def test_check_extnet_None(self, mock_getext):
+        with self.assertRaises(Exception) as context:
+            self.deployment.check_ext_net()
+            self.assertTrue(mock_getext.called)
+            msg = 'ERROR: No external networks in the deployment.'
+            self.assertTrue(msg in context)
+
 
 if __name__ == "__main__":
     logging.disable(logging.CRITICAL)