def test_keep_view_informanion():
    """Generated view should point to the `Injector` subclass."""

    from django_project.views import (
        DispatchView,
        QuestionTemplateView,
        QuestionFormView,
    )

    view = DispatchView.as_view()

    assert view.__name__ == "DispatchView"
    assert view.__module__ == "django_project.views"
    assert view.__doc__ == "Intentionally left blank."

    template_view = QuestionTemplateView.as_view()

    assert template_view.__name__ == "QuestionTemplateView"
    assert template_view.__module__ == "django_project.views"
    assert template_view.__doc__ == "Intentionally left blank."

    form_view = QuestionFormView.as_view()

    assert form_view.__name__ == "QuestionFormView"
    assert form_view.__module__ == "django_project.views"
    assert form_view.__doc__ == "Intentionally left blank."
def test_form_view_attributes():
    """Access attributes of generated FormView."""

    from django_project.views import QuestionFormView

    view = QuestionFormView.as_view().view_class()
    assert view.success_url == "/thanks/"
    assert view.template_name == "question.html"
    assert view.template_engine == "default"
    assert view.response_class.__name__ == "TestTemplateResponse"
    assert view.content_type == "text/html"
    assert view.initial == {"is_testing": True}
示例#3
0
from django.conf.urls import include
from django.conf.urls import url

from django_project.views import DispatchView
from django_project.views import DynamicQuestionTemplateView
from django_project.views import EmptyFormView
from django_project.views import EmptyView
from django_project.views import KwargsView
from django_project.views import QuestionFormView
from django_project.views import QuestionTemplateView
from django_project.views import SelfView
from django_project.views import UserView

urlpatterns = [
    url(r"^test_dispatch_request/(\d+)/(\w+)/$", DispatchView.as_view()),
    url(r"^test_empty_request/(\d+)/(\w+)/$", EmptyView.as_view()),
    url(r"^test_inject_user/(?P<pk>\d+)/(?P<slug>\w+)/$", UserView.as_view()),
    url(r"^test_inject_kwargs/(?P<pk>\d+)/(?P<slug>\w+)/$",
        KwargsView.as_view()),
    url(r"^test_inject_self/(?P<pk>\d+)/(?P<slug>\w+)/$", SelfView.as_view()),
    url(r"^test_template_view/(?P<pk>\d+)/$", QuestionTemplateView.as_view()),
    url(
        r"^test_template_view_dynamic/(?P<pk>\d+)/$",
        DynamicQuestionTemplateView.as_view(),
    ),
    url(r"^test_form_view/(?P<pk>\d+)/$", QuestionFormView.as_view()),
    url(r"^empty_form_view/$", EmptyFormView.as_view()),
    url(r"^api/", include("django_project.api.urls")),
]