I sometimes want to assert that a particular integrity error was raised during a test. At the moment I can do:
import pytest
from django.db.utils import IntegrityError
def test_():
with pytest.raises(IntegrityError):
...
But, if I want to know which integrity error I'm catching, I need to either do some regexp matching on its message, or dig into the internals like this library does.
I'd love to be able to do:
from django_integrity import conversion, testing
def test_():
with testing.raises(
conversion.Unique(model=User, fields=("email",))
):
...
alternatives
I could also wrap the existing conversion code:
from django_integrity import conversion
def test_():
class _MyIntegrityError(Exception):
pass
with (
pytest.raises(_MyIntegrityError),
conversion.refine_integrity_error(
[(conversion.Unique(model=User, fields=("email",)), _MyIntegrityError)]
),
):
...
But that's a bit awkward. A helper for it would be so much easier to use.
I sometimes want to assert that a particular integrity error was raised during a test. At the moment I can do:
But, if I want to know which integrity error I'm catching, I need to either do some regexp matching on its message, or dig into the internals like this library does.
I'd love to be able to do:
alternatives
I could also wrap the existing conversion code:
But that's a bit awkward. A helper for it would be so much easier to use.