def test_one_of_json_codec(self): for value in [ 123, UUID("06b959d0-65e0-11e7-866d-6be08781d5cb"), False ]: schema = s.one_of([s.int(), s.uuid(), s.bool()]) self.assertEqual(schema.json_decode(schema.json_encode(value)), value)
def test_dict_json_encode_optional_success(): _equal( s.dict({ "ejc": s.float(), "ejd": s.bool() }, {"ejc"}).json_encode, {"ejc": 123.45}, )
def test_dict_json_decode_success(self): self._equal( s.dict({ "dja": s.float(), "djb": s.bool() }, {"dja", "djb"}).json_decode, { "dja": 802.11, "djb": True })
class DC: id: s.uuid() str: s.str(nullable=True) dict: s.dict({"a": s.int()}, nullable=True) list: s.list(s.int(), nullable=True) _set: s.set(s.str(), nullable=True) int: s.int(nullable=True) float: s.float(nullable=True) bool: s.bool(nullable=True) bytes: s.bytes(format="byte", nullable=True) date: s.date(nullable=True) datetime: s.datetime(nullable=True)
def test( self, a: s.list(s.str()), b: s.set(s.str()), c: s.int(), d: s.float(), e: s.bool(), f: s.bytes(), g: s.datetime(), h: s.uuid(), ): pass
def test_bool_str_decode_false(self): self.assertEqual(s.bool().str_decode("false"), False)
def test_bool_str_decode_true(self): self.assertEqual(s.bool().str_decode("true"), True)
def test_dict_json_encode_optional_success(self): self._equal( s.dict({ "ejc": s.float(), "ejd": s.bool(required=False) }).json_encode, {"ejc": 123.45})
"scheme": self.scheme, "realm": self.realm, "user_id": user_id, "role": "god", } _scheme = _TestBasicSecurityScheme("WallyWorld") http1 = _TestBasicSecurityRequirement(_scheme) _r1_schema = s.dict( { "id": s.str(), "foo": s.int(), "bar": s.bool(), "dt": s.datetime() }, "id foo bar") class _BasicResource1(Resource): schema = _r1_schema @operation(security=[]) def create(self, id: _r1_schema.props["id"], _body: _r1_schema) -> s.dict({"id": _r1_schema.props["id"]}): return {"id": id} @operation(security=[]) def update(self, id: _r1_schema.props["id"], _body: _r1_schema):
def test_bool_allow_none(): assert s.bool(nullable=True).json_encode(None) == None
def test_dict_json_encode_optional_absent(self): self._equal(s.dict({"eje": s.bool()}).json_encode, {})
def test_bool_allow_none(self): self.assertEqual(s.bool(nullable=True).json_encode(None), None)
def test_bool_validate_type_false(self): s.bool().validate(False)
def test_bool_validate_type_true(self): s.bool().validate(True)
def test_set_validate_type_error(self): self._error(s.set(items=s.bool()).validate, "this_is_not_a_set")
class User: """A user associated with a channel.""" nick: vs.nick() voice: s.bool() = True op: s.bool() = False
class Phone: """A phone number associated with a channel.""" number: vs.e164() nick: vs.nick() mute: s.bool() = False
class Index: """Represents a database index.""" name: s.str() columns: s.list(s.str()) unique: s.bool() = False
def test_bool_str_decode_error(self): self._error(s.bool().str_decode, "123")
def test_bool_validate_type_error(self): self._error(s.bool().validate, "foo")
def test_bool_disallow_none(self): self._error(s.bool().json_encode, None)
def test_bool_json_encode_error(self): self._error(s.bool().json_encode, "bar")
def test_dict_json_encode_default_success(self): self.assertEqual( s.dict({ "eje": s.bool(default=False) }).json_encode({}), {"eje": False})
def test_bool_str_decode_error(): _error(s.bool().str_decode, "123")
def test_any_of_json_codec(self): for value in [123.45, False]: schema = s.any_of([s.float(), s.bool()]) self.assertEqual(schema.json_decode(schema.json_encode(value)), value)
def test_bool_json_decode_false(self): self._equal(s.bool().json_decode, False)
def test_bool_disallow_none(): _error(s.bool().json_encode, None)
def test_bool_json_decode_error(self): self._error(s.bool().json_decode, "baz")
def test_bool_json_decode_true(self): self._equal(s.bool().json_decode, True)
def test_any_of_json_codec(): for value in [123.45, False]: schema = s.any_of([s.float(), s.bool()]) assert schema.json_decode(schema.json_encode(value)) == value