def __init__(self, request, name=None, cache=None): self.name = name if name is not None else request.__name__ self.request = request self.cache = cache self.validate_name() self.annotation = Type.get_type( self.request.__annotations__.get('return'))
def extra_arguments(self): extras = [] args_spec = inspect.getfullargspec(self.request) args = args_spec.args if self.env_arg in args: args.remove(self.env_arg) if self.session_arg in args: args.remove(self.session_arg) defaults = list(args_spec.defaults or []) for argument in args[::-1]: annotation = Type.get_type(args_spec.annotations.get(argument)) if defaults: arg = DefaultValueArgument(argument, annotation, defaults.pop()) else: arg = NoDefaultValueArgument(argument, annotation) extras.append(arg) return extras[::-1]
def testing_casting_to_invalid_type_passes_value_unchanged(value): t = Type.get_type(object) assert t.cast(value) == value
def test_create_sectet_type(): t = Type.get_type(SecretType) assert str(t) == 'secret' assert bool(t) == True assert isinstance(t, SecretType)
def test_create_unsupported_type(cls): t = Type.get_type(cls) assert isinstance(t, Type) assert str(t) == '' assert bool(t) == False
def test_create_datetime_type(): t = Type.get_type(datetime) assert isinstance(t, DatetimeType) assert str(t) == 'datetime' assert bool(t) == True
def test_create_boolean_typ(): t = Type.get_type(bool) assert isinstance(t, BooleanType) assert str(t) == 'bool' assert bool(t) == True
def test_create_primitive_type(cls): t = Type.get_type(cls) assert isinstance(t, PrimitiveType) assert str(t) == cls.__name__ assert bool(t) == True