def test_no_keystone(self, mock_globals, mock_get_token, mock_post): mock_post.side_effect = Exception("timeout boom") cli = ormcli.Cli() cli.create_parser() globals()['auth_region'] = 'test' cli.parse('orm ims create_image client1 ' 'orm/tests/unit/ormcli/data/ims-create-image.json'.split()) with self.assertRaises(SystemExit) as cm: cli.logic()
def test_ok(self, mock_post): cli = ormcli.Cli() cli.create_parser() cli.parse('orm cms create_customer client1 ' 'orm/tests/unit/ormcli/data/cms-add-cust.json'.split()) mock_post.return_value = self.respond( {"access": { "token": { "id": 989 } }}, 200)
def test_parsing(self): cli = ormcli.Cli() cli.create_parser() cli.parse( 'orm rms --orm-base-url 12.11.10.9 --port 8832 --timeout 150 ' 'list_regions --type big '.split()) args = cli.args self.assertEqual(args.orm_base_url, '12.11.10.9') self.assertEqual(args.port, 8832) self.assertEqual(args.type, 'big') self.assertEqual(args.timeout, 150)
def test_list_customers(self, mock_post, mock_get): cli = ormcli.Cli() cli.create_parser() cli.parse( 'orm cms list_customers --region 2 --user bob client1'.split()) resp = self.respond('{"Hi, mom"}', 200, {'X-Subject-Token': 989}) mock_post.return_value = self.respond( {"access": { "token": { "id": 989 } }}, 200)
def test_timeout(self, mock_post): mock_post.side_effect = Exception("timeout boom") cli = ormcli.Cli() cli.create_parser() cli.parse('orm cms --faceless add_user client1 customer1 region1 ' 'orm/tests/unit/ormcli/data/cms-add-cust.json'.split()) with self.assertRaises(SystemExit) as cm: cli.logic() self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('timeout boom', output)
def test_parsing(self): cli = ormcli.Cli() cli.create_parser() cli.parse( 'orm cms --orm-base-url 12.11.10.9 --port 8832 --timeout 150 ' 'add_user ' 'client1 customer1 region1 ' 'orm/tests/unit/ormcli/data/cms-add-cust.json'.split()) args = cli.args self.assertEqual(args.orm_base_url, '12.11.10.9') self.assertEqual(args.port, 8832) self.assertEqual(args.timeout, 150)
def test_timeout(self, mock_get): cli = ormcli.Cli() cli.create_parser() cli.parse('orm rms --faceless --orm-base-url 12.11.10.9 --port 8832' ' --timeout 1 get_region x'.split()) mock_get.side_effect = Exception("timeout boom") with self.assertRaises(SystemExit) as cm: cli.logic() self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('timeout boom', output)
def test_timeout(self, mock_globals, mock_get_token, mock_post, mock_put, mock_common): mock_post.side_effect = Exception("timeout boom") cli = ormcli.Cli() cli.create_parser() cli.parse('orm ims create_image client1 ' 'orm/tests/unit/ormcli/data/ims-create-image.json'.split()) with self.assertRaises(SystemExit) as cm: cli.logic() self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('timeout boom', output)
def test_list_images_bad_request(self, mock_get_token, mock_globals, mock_post, mock_get, mock_common): mock_post.return_value = self.respond( {"access": { "token": { "id": 989 } }}, 201) cli = ormcli.Cli() cli.create_parser() cli.parse('orm ims list_images client1 --visibility public --region a ' '--customer b'.split()) resp = self.respond({"access": {"token": {"id": 989}}}, 200) with self.assertRaises(SystemExit) as cm: cli.logic() self.assertEqual(cm.exception.code, 1) sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('API error', output)
def test_one_zone(self, mock_get): cli = ormcli.Cli() cli.create_parser() cli.parse('orm rms --faceless --orm-base-url 12.11.10.9 --port 8832' ' --timeout 150 get_region zoneone'.split()) resp = self.respond( { "clli": "n/a", "name": "SNA 1", "enabled": 1, "state": "functional", "aic_version": "aic3.0", "endpoints": [{ "type": "horizon", "publicurl": "http://horizon1.com" }, { "type": "identity", "publicurl": "http://identity1.com" }, { "type": "ord", "publicurl": "http://ord1.com" }], "id": "SNA1", "metadata": [] }, 200, {'X-Subject-Token': 989}) mock_get.return_value = resp cli.logic() sys.stdout.seek(0) output = sys.stdout.read() self.assertIn('"aic_version": "aic3.0"', output)