def test_error_with_empty_args(self): with self.assertRaises(SystemExit) as cm: args = ormcli.main([]) self.assertEqual(cm.exception.code, 2) sys.stderr.seek(0) output = sys.stderr.read() self.assertIn('too few arguments', output)
def test_list_customers(self, mock_get, mock_post, mock_get_keystone_ep): mock_post.return_value = self.respond(TJ, 200) mock_get.return_value = self.mock_response args = ormcli.main('orm cms list_customers t'.split()) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn(json.dumps(TJ), output)
def test_list_flavors_errors(self, mock_globals, mock_get_token, mock_get, mock_post, mock_get_keystone_ep): mock_post.return_value = self.respond(TJ, 200) mock_get.return_value = self.respond(TJ, 204, oy=True) with self.assertRaises(SystemExit) as cm: args = ormcli.main('orm fms list_flavors t'.split()) self.assertEqual(cm.exception.code, 0) sys.stdout.seek(0) output = sys.stdout.read() self.assertEqual('', output) mock_get.return_value = self.respond(TJ, 404, oy=True) with self.assertRaises(SystemExit) as cm: args = ormcli.main('orm fms --faceless list_flavors t'.split()) self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('API error:', output)
def test_list_flavors_e(self, mock_get, mock_post, mock_get_keystone_ep): mock_post.return_value = self.respond(TJ, 200) mock_get.side_effect = Exception('e') with self.assertRaises(SystemExit) as cm: args = ormcli.main('orm fms list_flavors t'.split()) self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('e', output)
def test_list_flavors_a(self, mock_globals, mock_get_token, mock_get, mock_post, mock_get_keystone_ep): mock_post.return_value = self.respond(TJ, 200) mock_get.return_value = self.mock_response mock_get.__name__ = 'a' args = ormcli.main('orm fms --verbose list_flavors t'.split()) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn(json.dumps(TJ), output)
def test_ims_help_command(self): with self.assertRaises(SystemExit) as cm: args = ormcli.main('orm ims --help'.split()) self.assertEqual(cm.exception.code, 0) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('usage:', output) self.assertIn('timeout', output) self.assertIn('optional arguments:', output) self.assertIn('orm ims', output)