def test_create_user_shell_bash(self, *args): set_module_args(dict( username_credential='someuser', password_credential='testpass', partition_access=['all:admin'], update_password='******', shell='bash', provider=dict( server='localhost', password='******', user='******' ) )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode ) # Override methods to force specific logic in the module to happen upm = UnpartitionedManager(module=module, params=module.params) upm.create_on_device = Mock(return_value=True) upm.exists = Mock(return_value=False) mm = ModuleManager(module=module) mm.is_version_less_than_13 = Mock(return_value=True) mm.get_manager = Mock(return_value=upm) results = mm.exec_module() assert results['changed'] is True assert results['partition_access'] == ['all:admin']
def test_create_user_shell_not_permitted_raises(self, *args): set_module_args(dict( username_credential='someuser', password_credential='testpass', partition_access=['Common:guest'], update_password='******', shell='bash', provider=dict( server='localhost', password='******', user='******' ) )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode ) # Override methods to force specific logic in the module to happen upm = UnpartitionedManager(module=module, params=module.params) upm.create_on_device = Mock(return_value=True) upm.exists = Mock(return_value=False) mm = ModuleManager(module=module) mm.is_version_less_than_13 = Mock(return_value=True) mm.get_manager = Mock(return_value=upm) msg = "Shell access is only available to 'admin' or " \ "'resource-admin' roles." with pytest.raises(F5ModuleError) as ex: mm.exec_module() assert str(ex.value) == msg
def test_create_user_partition_access_raises(self, *args): set_module_args(dict( username_credential='someuser', provider=dict( server='localhost', password='******', user='******' ) )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode ) # Override methods to force specific logic in the module to happen upm = UnpartitionedManager(module=module, params=module.params) upm.create_on_device = Mock(return_value=True) upm.exists = Mock(return_value=False) mm = ModuleManager(module=module) mm.is_version_less_than_13 = Mock(return_value=True) mm.get_manager = Mock(return_value=upm) msg = "The 'partition_access' option " \ "is required when creating a resource." with pytest.raises(F5ModuleError) as ex: mm.exec_module() assert str(ex.value) == msg