Skip to content

Commit

Permalink
Merge 317db82 into 6d1b038
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpeak committed Oct 23, 2018
2 parents 6d1b038 + 317db82 commit ce1624c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion repokid/__init__.py
Expand Up @@ -19,7 +19,7 @@

import import_string

__version__ = '0.9.0'
__version__ = '0.9.1'


def init_config():
Expand Down
2 changes: 2 additions & 0 deletions repokid/cli/repokid_cli.py
Expand Up @@ -972,6 +972,8 @@ def repo_all_roles(account_number, dynamo_table, config, hooks, commit=False, sc
account_number,
', '.join([role.role_name for role in roles])))

repokid.hooks.call_hooks(hooks, 'BEFORE_REPO_ROLES', {'account_number': account_number, 'roles': roles})

for role in roles:
error = repo_role(account_number, role.role_name, dynamo_table, config, hooks, commit=commit,
scheduled=scheduled)
Expand Down
8 changes: 8 additions & 0 deletions repokid/hooks/loggers/__init__.py
Expand Up @@ -2,6 +2,14 @@
import repokid.hooks as hooks


@hooks.implements_hook('BEFORE_REPO_ROLES', 1)
def log_before_repo_roles(input_dict):
LOGGER.debug("Calling DURING_REPOABLE_CALCULATION hooks")
if not all(required in input_dict for required in ['account_number', 'roles']):
raise hooks.MissingHookParamaeter("Did not get all required parameters for BEFORE_REPO_ROLES hook")
return input_dict


@hooks.implements_hook('DURING_REPOABLE_CALCULATION', 1)
def log_during_repoable_calculation_hooks(input_dict):
LOGGER.debug("Calling DURING_REPOABLE_CALCULATION hooks")
Expand Down
24 changes: 17 additions & 7 deletions repokid/tests/test_repokid_cli.py
Expand Up @@ -286,11 +286,14 @@ def test_schedule_repo(self, mock_time, mock_role_ids_for_account, mock_set_role
assert mock_call_hooks.mock_calls == [call(hooks, 'AFTER_SCHEDULE_REPO',
{'roles': [Role(ROLES_FOR_DISPLAY[1])]})]

@patch('repokid.hooks.call_hooks')
@patch('repokid.cli.repokid_cli.get_role_data')
@patch('repokid.cli.repokid_cli.role_ids_for_account')
@patch('repokid.cli.repokid_cli.repo_role')
@patch('time.time')
def test_repo_all_roles(self, mock_time, mock_repo_role, mock_role_ids_for_account, mock_get_role_data):
def test_repo_all_roles(self, mock_time, mock_repo_role, mock_role_ids_for_account, mock_get_role_data,
mock_call_hooks):
hooks = {}
mock_role_ids_for_account.return_value = ['AROAABCDEFGHIJKLMNOPA', 'AROAABCDEFGHIJKLMNOPB',
'AROAABCDEFGHIJKLMNOPC']
roles = [{'RoleId': 'AROAABCDEFGHIJKLMNOPA', 'Active': True, 'RoleName': 'ROLE_A', 'RepoScheduled': 100},
Expand All @@ -305,14 +308,21 @@ def test_repo_all_roles(self, mock_time, mock_repo_role, mock_role_ids_for_accou
mock_repo_role.return_value = None

# repo all roles in the account, should call repo with all roles
repokid.cli.repokid_cli.repo_all_roles(None, None, None, None, scheduled=False)
repokid.cli.repokid_cli.repo_all_roles(None, None, None, hooks, scheduled=False)
# repo only scheduled, should only call repo role with role C
repokid.cli.repokid_cli.repo_all_roles(None, None, None, None, scheduled=True)
repokid.cli.repokid_cli.repo_all_roles(None, None, None, hooks, scheduled=True)

assert mock_repo_role.mock_calls == [call(None, 'ROLE_A', None, None, hooks, commit=False, scheduled=False),
call(None, 'ROLE_B', None, None, hooks, commit=False, scheduled=False),
call(None, 'ROLE_C', None, None, hooks, commit=False, scheduled=False),
call(None, 'ROLE_C', None, None, hooks, commit=False, scheduled=True)]

roles_items = [Role(roles[0]), Role(roles[1]), Role(roles[2])]

assert mock_repo_role.mock_calls == [call(None, 'ROLE_A', None, None, None, commit=False, scheduled=False),
call(None, 'ROLE_B', None, None, None, commit=False, scheduled=False),
call(None, 'ROLE_C', None, None, None, commit=False, scheduled=False),
call(None, 'ROLE_C', None, None, None, commit=False, scheduled=True)]
assert mock_call_hooks.mock_calls == [
call(hooks, 'BEFORE_REPO_ROLES', {'account_number': None, 'roles': roles_items}),
call(hooks, 'BEFORE_REPO_ROLES', {'account_number': None, 'roles': [roles_items[2]]}),
]

@patch('repokid.cli.repokid_cli.find_role_in_cache')
@patch('repokid.cli.repokid_cli.get_role_data')
Expand Down

0 comments on commit ce1624c

Please sign in to comment.