def test_password_empty_accounts(self): data = { "email": self.email, "first_name": self.first_name, "last_name": self.last_name, "username": self.username, } request = self.factory.get(self.signin_url) request.user = AnonymousUser() response = SignIn.as_view()(request) self.assertEqual(response.status_code, 200) responseBody = json.loads(response.content) self.assertIsNotNone(responseBody.get("csrftoken", None)) headers = {"X-CSRFToken": responseBody.get("csrftoken")} request = self.factory.post( self.signin_url, content_type="application/json", data=json.dumps(data), **headers, ) signinResponse = SignIn.as_view()(request) # signinResponseBody = json.loads(signinResponse.content) # print(signinResponseBody) self.assertEqual(signinResponse.status_code, status.HTTP_400_BAD_REQUEST)
def test_signin_negative_invalid_username(self): request = self.factory.get(self.signin_url) response = SignIn.as_view()(request) self.assertEqual(response.status_code, 200) body = json.loads(response.content) self.assertIsNotNone(body.get("csrftoken", None))
from django.urls import path, reverse_lazy from django.contrib.auth import views as auth_views from django.views.generic import TemplateView from accounts.views import SignIn, user_picture, user_profile app_name = 'accounts' urlpatterns = [ # sign in path('sign-in/', SignIn.as_view(), name='sign_in'), # sign out path('sign-out/', auth_views.LogoutView.as_view(next_page='/'), name='sign_out'), # forgort path('forget/', TemplateView.as_view(template_name="forget.html"), name='forget'), path('profile', user_profile, name='profile' ), path('picture', user_picture, name='picture' ), path('changepassword', auth_views.PasswordChangeView.as_view( template_name="changepassword.html", success_url=reverse_lazy('accounts:change-password'), ), name='change-password'