def mocked_testbot_allow_resource_false(self, testbot): config = create_config() config['ALLOW_RESOURCE_TAG'] = 'allow-resource' resources = [ DummyResource("Bbb", {}), DummyResource("Aaa", {'allow-resource': False}) ] return inject_mocks(testbot, config, resources)
def mocked_testbot_conceal_resource_false(self, testbot): config = create_config() config['CONCEAL_RESOURCE_TAG'] = 'conceal-resource' resources = [ DummyResource("Bbb", {}), DummyResource("Aaa", {'conceal-resource': False}) ] return inject_mocks(testbot, config, resources)
def mocked_testbot_hide_resource_false(self, testbot): config = create_config() config['HIDE_RESOURCE_TAG'] = 'hide-resource' resources = [ DummyResource("Bbb", {}), DummyResource("Aaa", {'hide-resource': False}) ] return inject_mocks(testbot, config, resources)
def mocked_testbot(self, testbot): config = create_config() config['CONTROL_RESOURCES_ROLE_NAME'] = 'myrole' resources_by_role = [ DummyResource("Bbb in role", {}), DummyResource("Aaa in role", {}) ] return inject_mocks(testbot, config, resources_by_role=resources_by_role)
def create_sdm_service_mock(): mock = MagicMock() mock.get_account_by_email = MagicMock(return_value=create_account_mock( account_tags={})) mock.account_grant_exists = MagicMock(return_value=False) mock.get_all_resources = MagicMock( return_value=[DummyResource("Aaa", {}), DummyResource("Bbb", {})]) mock.get_all_roles = MagicMock(return_value=[DummyRole(role_name, {})]) return mock
def test_dont_get_channel_when_sdm_object_has_tag_but_flag_is_disabled( self): config = {'APPROVERS_CHANNEL_TAG': None} sdm_object = DummyResource( 'resource', {self.approvers_channel_tag: self.approvers_channel}) approvers_channel = get_approvers_channel(config, sdm_object) assert approvers_channel is None
def test_show_resources_command_with_filters(self, mocked_testbot, mocked_sdm_service): mocked_sdm_service.get_all_resources.return_value = [ DummyResource("Aaa", {}) ] mocked_testbot.push_message( "show available resources --filter name:Aaa") message = mocked_testbot.pop_message() mocked_sdm_service.get_all_resources.assert_called_with( filter='name:Aaa') assert "Aaa (type: DummyResource)" in message assert "Bbb (type: DummyResource)" not in message
def test_send_stale_message_to_approvers_channel(self, mocked_testbot): accessbot = mocked_testbot.bot.plugin_manager.plugins['AccessBot'] sender_id = accessbot.build_identifier( accessbot.config['SENDER_EMAIL_OVERRIDE']) sender_id.room = create_room_mock(self.regular_channel_name) accessbot.enter_grant_request( access_request_id, Message(frm=sender_id), DummyResource('resource', {'approvers-channel': self.approvers_channel_name}), MagicMock(), MagicMock()) assert access_request_id in accessbot.get_grant_request_ids() assert "timed out" in mocked_testbot.pop_message() assert "not approved" in mocked_testbot.pop_message() assert self.raw_messages[ 0].to.person == f"#{self.approvers_channel_name}" assert self.raw_messages[ 1].to.person == f"#{self.regular_channel_name}"
def test_dont_get_channel_when_flag_is_disabled_and_sdm_object_doesnt_have_tag( self): config = {'APPROVERS_CHANNEL_TAG': None} sdm_object = DummyResource('resource', {}) approvers_channel = get_approvers_channel(config, sdm_object) assert approvers_channel is None
def test_get_channel_when_flag_is_enable_and_sdm_object_has_tag(self): config = {'APPROVERS_CHANNEL_TAG': self.approvers_channel_tag} sdm_object = DummyResource( 'resource', {self.approvers_channel_tag: self.approvers_channel}) approvers_channel = get_approvers_channel(config, sdm_object) assert approvers_channel == self.approvers_channel
def default_dummy_resources(): return [DummyResource("Bbb", {}), DummyResource("Aaa", {})]
def dummy_resources_with_auto_approve_groups(): return [ DummyResource("Bbb", {'auto-approve-groups': group}), DummyResource("Aaa", {}) ]