def test_login_get_200_and_get_redirect_url_in_input(self): # HTTP_X_REQUESTED_WITH='XMLHttpRequest' request = self.factory.get(self.fake_path) view = LoginView.as_view() response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(self.redirect_url, response.context_data['redirect_url'])
def test_login_ajax_post(self): request = self.factory.post( path=self.fake_path, data={"username": FAKE_USERNAME, "password": FAKE_PASSWORD}, HTTP_X_REQUESTED_WITH='XMLHttpRequest' ) add_session_to_request(request) view = LoginView.as_view() response = view(request) import ipdb; ipdb.set_trace() self.assertEqual(response.status_code, 302) self.assertEqual(response.get('location'), reverse_lazy('cms:admin-main')) self.assertRedirects(response, self.redirect_url, status_code=302)
from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from cms.views import LoginView, LogoutView, AdminView, ProjectView, ProjectAddView, ProjectDeleteView urlpatterns = [ url(r"^login/$", LoginView.as_view(), name="login"), url(r"^logout/$", LogoutView.as_view(), name="logout"), url(r"^main/$", AdminView.as_view(), name="admin-main"), url(r"^projects/$", ProjectView.as_view(), name="projects"), url(r"^projects/add/$", ProjectAddView.as_view(), name="projects-add"), url(r"^projects/(?P<pk>[0-9]+)/delete/$", ProjectDeleteView.as_view(), name="projects-delete"), # url(r'^projects/(?P<pk>[0-9]+)/update/$', ProjectUpdateView.as_view(), name='projects.update'), ]