Merge "Remaining cases of MappingEngineTester"

This commit is contained in:
Zuul 2018-10-19 20:20:24 +00:00 committed by Gerrit Code Review
commit 7835b57d87
1 changed files with 57 additions and 2 deletions

View File

@ -1646,7 +1646,7 @@ class TestTrustFlush(unit.SQLDriverOverrides, unit.BaseTestCase):
self.useFixture(database.Database())
self.config_fixture = self.useFixture(oslo_config.fixture.Config(CONF))
self.config_fixture.register_cli_opt(cli.command_opt)
# For unit tests that should not throw any erorrs,
# For unit tests that should not throw any errors,
# Use the argument parser to test that the combinations work
parser_test = argparse.ArgumentParser()
subparsers = parser_test.add_subparsers()
@ -1708,6 +1708,38 @@ class TestMappingEngineTester(unit.BaseTestCase):
config_files.append(unit.dirs.tests_conf('backend_sql.conf'))
return config_files
def test_mapping_engine_tester_with_invalid_rules_file(self):
tempfilejson = self.useFixture(temporaryfile.SecureTempFile())
tmpinvalidfile = tempfilejson.file_name
# Here the data required for rules should be in JSON format
# whereas the file contains text.
with open(tmpinvalidfile, 'w') as f:
f.write("This is an invalid data")
self.command_rules = tmpinvalidfile
self.command_input = tmpinvalidfile
self.command_prefix = None
self.command_engine_debug = True
self.useFixture(fixtures.MockPatchObject(
CONF, 'command', self.FakeConfCommand(self)))
mapping_engine = cli.MappingEngineTester()
self.assertRaises(SystemExit, mapping_engine.main)
def test_mapping_engine_tester_with_invalid_input_file(self):
tempfilejson = self.useFixture(temporaryfile.SecureTempFile())
tmpfilejsonname = tempfilejson.file_name
updated_mapping = copy.deepcopy(mapping_fixtures.MAPPING_SMALL)
with open(tmpfilejsonname, 'w') as f:
f.write(jsonutils.dumps(updated_mapping))
self.command_rules = tmpfilejsonname
# Here invalid.csv does not exist
self.command_input = "invalid.csv"
self.command_prefix = None
self.command_engine_debug = True
self.useFixture(fixtures.MockPatchObject(
CONF, 'command', self.FakeConfCommand(self)))
mapping_engine = cli.MappingEngineTester()
self.assertRaises(SystemExit, mapping_engine.main)
def test_mapping_engine_tester(self):
tempfilejson = self.useFixture(temporaryfile.SecureTempFile())
tmpfilejsonname = tempfilejson.file_name
@ -1729,7 +1761,30 @@ class TestMappingEngineTester(unit.BaseTestCase):
self.useFixture(fixtures.MockPatchObject(
CONF, 'command', self.FakeConfCommand(self)))
mapping_engine = cli.MappingEngineTester()
mapping_engine.main()
with mock.patch('six.moves.builtins.print') as mock_print:
mapping_engine.main()
self.assertEqual(mock_print.call_count, 3)
call = mock_print.call_args_list[0]
args, kwargs = call
self.assertTrue(args[0].startswith('Using Rules:'))
call = mock_print.call_args_list[1]
args, kwargs = call
self.assertTrue(args[0].startswith('Using Assertion:'))
call = mock_print.call_args_list[2]
args, kwargs = call
expected = {
"group_names": [],
"user": {
"type": "ephemeral",
"domain": {
"id": "Federated"
},
"name": "me"
},
"projects": [],
"group_ids": ["0cd5e9"]
}
self.assertEqual(jsonutils.loads(args[0]), expected)
def test_mapping_engine_tester_with_invalid_data(self):
tempfilejson = self.useFixture(temporaryfile.SecureTempFile())