def test_cost_per_hour_validation_fail(self, cls_name): drv = Driver(id='3', start_lat=3, start_lng=4, end_lat=4, end_lng=5) drv.work_shifts = [WorkShift(start_work=dtime, end_work=dtime)] drv.skills = ['calm', 'angry'] drv.cost_per_hour = '50' with pytest.raises(TypeError) as excinfo: drv.validate() err_msg = TYPE_ERR_MSG.format(cls_name, 'cost_per_hour', Number, str) assert err_msg == str(excinfo.value)
def test_is_valid(self): drv = Driver(id='3', start_lat=3, start_lng=4, end_lat=4, end_lng=5) drv.work_shifts = [WorkShift(start_work=dtime, end_work=dtime)] drv.skills = ['calm', 'angry'] drv.speed_factor = 1.5 drv.cost_per_hour = 50 drv.cost_per_hour_for_overtime = 100 drv.cost_per_km = 60 drv.fixed_cost = 20 assert drv.validate() is None assert jsonify(drv) == ( '{"fixedCost": 20, "workShifts": [{"workTimeFrom": "2014-12-05T08:00", ' '"workTimeTo": "2014-12-05T08:00"}], "startLat": 3, "costPerHourForOvertime": 100, ' '"costPerHour": 50, "serviceRegions": [], "costPerKm": 60, "id": "3", "endLon": 5, ' '"skills": ["calm", "angry"], "endLat": 4, "speedFactor": 1.5, "startLon": 4}') assert DriverValidator.validate(dictify(drv)) is None
def test_is_valid(self): drv = Driver(id='3', start_lat=3, start_lng=4, end_lat=4, end_lng=5) drv.work_shifts = [WorkShift(start_work=dtime, end_work=dtime)] drv.skills = ['calm', 'angry'] drv.speed_factor = 1.5 drv.cost_per_hour = 50 drv.cost_per_hour_for_overtime = 100 drv.cost_per_km = 60 drv.fixed_cost = 20 assert drv.validate() is None assert jsonify(drv) == ( '{"fixedCost": 20, "workShifts": [{"workTimeFrom": "2014-12-05T08:00", ' '"workTimeTo": "2014-12-05T08:00"}], "startLat": 3, "costPerHourForOvertime": 100, ' '"costPerHour": 50, "serviceRegions": [], "costPerKm": 60, "id": "3", "endLon": 5, ' '"skills": ["calm", "angry"], "endLat": 4, "speedFactor": 1.5, "startLon": 4}' ) assert DriverValidator.validate(dictify(drv)) is None