示例#1
0
def test_crud(resource):
    body = DC(
        id=uuid4(),
        str="string",
        dict={"a": 1},
        list=[1, 2, 3],
        _set={"foo", "bar"},
        int=1,
        float=2.3,
        bool=True,
        bytes=b"12345",
        date=s.date().str_decode("2019-01-01"),
        datetime=s.datetime().str_decode("2019-01-01T01:01:01Z"),
    )
    resource.create(body.id, body)
    assert resource.read(body.id) == body
    body.dict = {"a": 2}
    body.list = [2, 3, 4]
    body._set = None
    body.int = 2
    body.float = 1.0
    body.bool = False
    body.bytes = None
    body.date = None
    body.datetime = None
    resource.update(body.id, body)
    assert resource.read(body.id) == body
    resource.patch(body.id, {"str": "bacon"})
    body = resource.read(body.id)
    assert body.str == "bacon"
    resource.delete(body.id)
    with pytest.raises(r.NotFound):
        resource.read(body.id)
示例#2
0
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)
示例#3
0
 def test_date_json_decode_z(self):
     self.assertEqual(s.date().json_decode("2018-08-09"), date(2018, 8, 9))
示例#4
0
 def test_date_json_encode_error(self):
     self._error(s.date().json_encode, "definitely_not_a_date")
示例#5
0
 def test_date_json_encode_success_aware(self):
     self.assertEqual(s.date().json_encode(date(2017, 6, 7)), "2017-06-07")
示例#6
0
def test_date_json_encode_success_naive():
    assert s.date().json_encode(date(2016, 7, 8)) == "2016-07-08"
示例#7
0
 def test_date_disallow_none(self):
     self._error(s.date().json_encode, None)
示例#8
0
 def test_date_json_decode_error(self):
     self._error(s.date().json_decode, "14256910")
示例#9
0
def test_date_disallow_none():
    _error(s.date().json_encode, None)
示例#10
0
def test_date_str_decode_error():
    _error(s.date().str_decode, "14256910")
示例#11
0
def test_date_json_decode_error():
    _error(s.date().json_decode, "14256910")
示例#12
0
def test_date_json_decode_missing_tz():
    assert s.date().json_decode("2020-10-11") == date(2020, 10, 11)
示例#13
0
def test_date_json_decode_offset():
    assert s.date().json_decode("2019-09-10") == date(2019, 9, 10)
示例#14
0
def test_date_json_decode_z():
    assert s.date().json_decode("2018-08-09") == date(2018, 8, 9)
示例#15
0
def test_date_json_encode_success_aware():
    assert s.date().json_encode(date(2017, 6, 7)) == "2017-06-07"
示例#16
0
 def test_date_json_decode_offset(self):
     self.assertEqual(s.date().json_decode("2019-09-10"), date(2019, 9, 10))
示例#17
0
 def test_date_json_decode_missing_tz(self):
     self.assertEqual(s.date().json_decode("2020-10-11"),
                      date(2020, 10, 11))
示例#18
0
def test_date_allow_none():
    assert s.date(nullable=True).json_encode(None) == None
示例#19
0
 def test_date_str_decode_error(self):
     self._error(s.date().str_decode, "14256910")
示例#20
0
 def test_date_validate_type_success(self):
     s.date().validate(date(2015, 6, 7))
示例#21
0
 def test_date_allow_none(self):
     self.assertEqual(s.date(nullable=True).json_encode(None), None)
示例#22
0
 def test_date_validate_type_error(self):
     self._error(s.date().validate, "this_is_not_a_date")
示例#23
0
 def test_date_json_encode_success_naive(self):
     self.assertEqual(s.date().json_encode(date(2016, 7, 8)), "2016-07-08")
示例#24
0
def test_date_validate_type_error():
    _error(s.date().validate, "this_is_not_a_date")