Add test for redirect_to in combination with reverse_lazy
from django.core.exceptions import FieldError
from django.http.response import HttpResponseBase
from django.test import override_settings
+from django.urls import reverse_lazy
from iommi.struct import (
merged,
Struct,
@@ -2739,7 +2740,36 @@ def __init__(self, **kwargs):
self.kwargs = kwargs
assert (
- create_or_edit_object_redirect(**merged(expected, is_create=sentinel1, redirect=lambda **kwargs: FakeHttpResponse(**kwargs))).kwargs
+ create_or_edit_object_redirect(
+ **merged(
+ expected,
+ is_create=sentinel1,
+ redirect_to=sentinel2,
+ redirect=lambda **kwargs: FakeHttpResponse(**kwargs),
+ )
+ ).kwargs
+ == expected
+ )
+
+
+def test_redirect_to_with_reverse_lazy():
+ sentinel1, sentinel2, sentinel3, sentinel4 = object(), '/dummy/', object(), object()
+ expected = dict(redirect_to=sentinel2, request=sentinel3, form=sentinel4)
+
+ class FakeHttpResponse(HttpResponseBase):
+ # noinspection PyMissingConstructor
+ def __init__(self, **kwargs):
+ self.kwargs = kwargs
+
+ assert (
+ create_or_edit_object_redirect(
+ **merged(
+ expected,
+ is_create=sentinel1,
+ redirect_to=reverse_lazy('dummy_view'),
+ redirect=lambda **kwargs: FakeHttpResponse(**kwargs),
+ )
+ ).kwargs
== expected
)
