class TestUserUpdateView(BaseUserTestCase): def setUp(self): # call BaseUserTestCase.setUp() super(TestUserUpdateView, self).setUp() # Instantiate the view directly. Never do this outside a test! self.view = UserUpdateView() # Generate a fake request request = self.factory.get('/fake-url') # Attach the user to the request request.user = self.user # Attach the request to the view self.view.request = request def test_get_success_url(self): # Expect: '/users/testuser/', as that is the default username for # self.make_user() self.assertEqual( self.view.get_success_url(), '/users/testuser/' ) def test_get_object(self): # Expect: self.user, as that is the request's user object self.assertEqual( self.view.get_object(), self.user )
def test_get_object(self, user: User, rf: RequestFactory): view = UserUpdateView() request = rf.get("/fake-url/") request.user = user view.request = request assert view.get_object() == user
def test_get_success_url(self, user: User, rf: RequestFactory): view = UserUpdateView() request = rf.get("/fake-url/") request.user = user view.request = request assert view.get_success_url() == f"/users/{user.username}/"
def test_get_success_url( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request
def test_get_object(self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_object() == user
def setUp(self): # call BaseUserTestCase.setUp() super(TestUserUpdateView, self).setUp() # Instantiate the view directly. Never do this outside a test! self.view = UserUpdateView() # Generate a fake request request = self.factory.get('/fake-url') # Attach the user to the request request.user = self.user # Attach the request to the view self.view.request = request
# -*- coding:utf-8 -*- # author: lyl from django.conf.urls import url from apps.users.views import UserMangerView, UserUpdateView, RoleListView, GroupListView urlpatterns = [ url(r'^user_list/$', UserMangerView.as_view(), name='user_list'), url(r'^update_center/$', UserUpdateView.as_view(), name='update_center'), url(r'^role_list/$', RoleListView.as_view(), name='role_list'), url(r'^group_list/$', GroupListView.as_view(), name='group_list'), ]
from django.urls import path from django.contrib.auth import views as auth_views from apps.users import views from apps.users.views import UserListView, UserUpdateView urlpatterns = [ path('register/', views.user_register, name='users-register'), path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'), path('accounts/', UserListView.as_view(), name='accounts'), path('profile/', UserUpdateView.as_view(), name='profile'), path('password-reset/', auth_views.PasswordResetView.as_view( template_name='users/password_reset.html'), name='password_reset'), path('password-reset/done/', auth_views.PasswordResetDoneView.as_view( template_name='users/password_reset_done.html'), name='password_reset_done'), path('password-reset-confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view( template_name='users/password_reset_confirm.html'), name='password_reset_confirm'), path('password-reset-complete/', auth_views.PasswordResetCompleteView.as_view( template_name='users/password_reset_complete.html'),
from apps.users.views import UserCreateView, UserUpdateView urlpatterns = patterns( '', url( r'^password-reset/$', 'django.contrib.auth.views.password_reset', name='password_reset' ), url( r'^login/$', 'django.contrib.auth.views.login', {'authentication_form': EmailAuthenticateForm}, name='login' ), url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'), url(r'^register/$', UserCreateView.as_view(), name='register'), url(r'^edit/$', login_required(UserUpdateView.as_view()), name='user-edit'), url(r'^(?P<pk>\d+)/$', DetailView.as_view(model=get_user_model()), name='user-detail'), url(r'^register/success/', TemplateView.as_view( template_name='registration/register_success.html'), name='register-success'), url(r'^', include('django.contrib.auth.urls')), url(r'^edit/', UserUpdateView.as_view(), name='user_update'), )
urlpatterns = [ # Regular Views url(regex=r'^dashboard/$', view=DashboardView.as_view(), name='view-dashboard'), url(regex=r'^profile/$', view=ProfileView.as_view(), name='view-profile'), url(regex=r'^settings/$', view=SettingsView.as_view(), name='view-settings'), url(regex=r'^account/(?P<username>[\w.@+-]+)/$', view=UserDetailView.as_view(), name='view-detail'), url(regex=r'^account/update/$', view=UserUpdateView.as_view(), name='view-update'), url( regex=r'^account/change-email/(?P<token>.*)/$', view=change_email, name="view-change-email", ), url( regex=r'^account/cancel-account/(?P<token>.*)/$', view=cancel_account, name="view-cancel-account", ), url(regex=r'^profile/sessions/$', view=ProfileSessionsView.as_view(), name='view-profile-sessions'), ]
from django.urls import path from .views import * from apps.users.views import UserListView, UserCreateView, UserUpdateView, UserDeleteView, UserDetailView app_name = 'users' urlpatterns = [ path('', UserListView.as_view(), name='users'), path('create/', UserCreateView.as_view(), name='create'), path('<int:pk>', UserDetailView.as_view(), name='detail'), path('edit/<int:pk>', UserUpdateView.as_view(), name='edit'), path('delete/<int:pk>', UserDeleteView.as_view(), name='delete') ]