def test_oneof_blob(): """ This tests: oneof field is correctly represented as `anyOf` """ doc = PROTO_TO_PYDANTIC_MODELS.DocumentProto( blob=PROTO_TO_PYDANTIC_MODELS.NdArrayProto()) assert doc.blob == PROTO_TO_PYDANTIC_MODELS.NdArrayProto() assert 'text' not in doc.dict() assert 'buffer' not in doc.dict()
def test_oneof_validation_error(): """ This tests validation error for invalid fields """ with pytest.raises(pydantic.error_wrappers.ValidationError) as error: doc = PROTO_TO_PYDANTIC_MODELS.DocumentProto(text='abc', buffer=b'abc') assert "only one field among ['buffer', 'blob', 'text']" in str(error.value) with pytest.raises(pydantic.error_wrappers.ValidationError) as error: doc = PROTO_TO_PYDANTIC_MODELS.DocumentProto( text='abc', buffer=b'abc', blob=PROTO_TO_PYDANTIC_MODELS.NdArrayProto() ) assert "only one field among ['buffer', 'blob', 'text']" in str(error.value)