示例#1
0
    def test_repr(self):
        date_repr, to_date_repr = t.Date(), t.ToDate()
        assert repr(date_repr) == '<Date %Y-%m-%d>'
        assert repr(to_date_repr) == '<ToDate %Y-%m-%d>'

        date_repr, to_date_repr = t.Date('%y-%m-%d'), t.ToDate('%y-%m-%d')
        assert repr(date_repr) == '<Date %y-%m-%d>'
        assert repr(to_date_repr) == '<ToDate %y-%m-%d>'
示例#2
0
 def test_date(self):
     res = t.Date().check(date.today())
     assert res == date.today()
     now = datetime.now()
     res = t.Date().check(now)
     assert res == now
     res = t.Date().check("2019-07-25")
     assert res == '2019-07-25'
     res = extract_error(t.Date(), "25-07-2019")
     assert res == 'value does not match format %Y-%m-%d'
     res = extract_error(t.Date(), 1564077758)
     assert res == 'value cannot be converted to date'
示例#3
0
import trafaret as t
from trafaret.contrib.object_id import MongoId

car = t.Dict({
    t.Key('_id'): MongoId(),
    t.Key('vin_code'): t.String(),
    t.Key('manufacturer'): t.String(),
    t.Key('model'): t.String(),
    t.Key('year_created'): t.Date(format='%Y'),
    t.Key('colour'): t.String(),
})


async def get_car_by_vin_code(car_collection, vin_code):
    car_detail = await car_collection.find_one({'vin_code': vin_code})
    return car_detail


async def delete_car_by_vin_code(car_collection, vin_code):
    car_detail = await car_collection.delete_one({'vin_code': vin_code})
    return car_detail