import unittest from vault_options import parse_vault_options, read_switch_bundle class _FakeVaultV2(object): def __init__(self): self.calls = [] def read_secret_version(self, **kwargs): self.calls.append(kwargs) return {'data': {'data': {'switchBundle': '1'}}} class _FakeClient(object): def __init__(self): self.v2 = _FakeVaultV2() self.secrets = self self.kv = self class ParseVaultOptionsTests(unittest.TestCase): def test_uses_default_path_and_mount_point(self): options = parse_vault_options(['switchBundle.py', 'project', '123!@#']) self.assertEqual(options, ('default', 'aws')) def test_reads_path_and_mount_point_after_existing_arguments(self): options = parse_vault_options( ['switchBundle.py', 'project', '123!@#', 'release', 'production'] ) self.assertEqual(options, ('release', 'production')) def test_uses_default_mount_point_when_only_path_is_provided(self): options = parse_vault_options( ['switchBundle.py', 'project', '123!@#', 'release'] ) self.assertEqual(options, ('release', 'aws')) def test_passes_path_and_mount_point_to_vault(self): client = _FakeClient() read_switch_bundle(client, 'release', 'production') self.assertEqual( client.v2.calls, [{ 'path': 'release', 'mount_point': 'production', 'raise_on_deleted_version': True, }], ) def test_uses_default_vault_settings_when_not_provided(self): client = _FakeClient() read_switch_bundle(client) self.assertEqual(client.v2.calls[0]['path'], 'default') self.assertEqual(client.v2.calls[0]['mount_point'], 'aws') if __name__ == '__main__': unittest.main()