test_exceptions.py 758 B

123456789101112131415161718192021222324252627282930313233
  1. from pydantic import ValidationError
  2. from clean_python import BadRequest
  3. from clean_python import DoesNotExist
  4. from clean_python import ValueObject
  5. def test_bad_request_short_str():
  6. e = BadRequest("bla bla bla")
  7. assert str(e) == "validation error: bla bla bla"
  8. def test_does_not_exist_str():
  9. e = DoesNotExist("raster", id=12)
  10. assert str(e) == "does not exist: raster with id=12"
  11. def test_does_not_exist_no_id_str():
  12. e = DoesNotExist("raster")
  13. assert str(e) == "does not exist: raster"
  14. class Book(ValueObject):
  15. title: str
  16. def test_bad_request_from_validation_error():
  17. try:
  18. Book()
  19. except ValidationError as e:
  20. err = BadRequest(e)
  21. assert str(err) == "validation error: 'title' Field required"