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 test_get_success_url(self, user, request_factory): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_success_url() == f"/users/dashboard/"
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_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_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: settings.AUTH_USER_MODEL, request_factory: RequestFactory): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_success_url() == f"/users/dashboard/"
def test__user_update_view__get_success_url(user): """Tests the get_success_url method of UserUpdateView.""" # Create view and request for testing request = RequestFactory() request.user = user view = UserUpdateView() view.request = request assert view.get_success_url() == f'/users/{user.username}/'
def test__user_update_view__get_object(user): """Tests the get_object method of UserUpdateView.""" # Create view and request for testing request = RequestFactory() request.user = user view = UserUpdateView() 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
class TestUserUpdateView(BaseUserTestCase): def setUp(self): super(TestUserUpdateView, self).setUp() self.view = UserUpdateView() request = self.factory.get('/fake-url') request.user = self.user self.view.request = request def test_get_success_url(self): self.assertEqual(self.view.get_success_url(), '/users/testuser/') def test_get_object(self): self.assertEqual(self.view.get_object(), self.user)
def test_form_valid(self, user: User, rf: RequestFactory): view = UserUpdateView() request = rf.get("/fake-url/") # Add the session/message middleware to the request SessionMiddleware().process_request(request) MessageMiddleware().process_request(request) request.user = user view.request = request # Initialize the form form = UserChangeForm() form.cleaned_data = [] view.form_valid(form) messages_sent = [m.message for m in messages.get_messages(request)] assert messages_sent == ["Information successfully updated"]
name='password_change'), url(r'^password/change/done/$', auth_views.password_change_done, kwargs={'template_name': 'users/password_change_done.html'}, name='password_change_done'), url(r'^password/reset/$', auth_views.password_reset, kwargs={ 'template_name': 'users/password_reset_form.html', 'email_template_name': 'users/_email_reset_pass.html', 'subject_template_name': 'users/_email_reset_pass_subj.txt' }, name='password_reset_request'), url(r'^password/reset/sent/$', auth_views.password_reset_done, kwargs={'template_name': 'users/password_reset_sent.html'}, name='password_reset_done'), url( r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.password_reset_confirm, name='password_reset_confirm', kwargs={'template_name': 'users/password_reset_confirm.html'}, ), url(r'^password/reset/done/$', auth_views.password_reset_complete, kwargs={'template_name': 'users/password_reset_done.html'}, name='password_reset_complete'), url(r'^private/$', UserDetailView.as_view(), name='user_detail'), url(r'^edit/$', UserUpdateView.as_view(), name='user_edit'), ]
## CORE USER - are these used at all? # URL pattern for the UserListView url(r'^$', UserListView.as_view(), name='list'), # URL pattern for the UserRedirectView url(r'^~redirect/$', UserRedirectView.as_view(), name='redirect'), # URL pattern for the UserDetailView url(r'^(?P<username>[\w@\.\+\-_]+)/$', UserDetailView.as_view(), name='detail'), # URL pattern for the UserUpdateView url(r'^update/(?P<username>[\w@\.\+\-_]+)/$', UserUpdateView.as_view(), name='update'), ## SELFISH URLs # NOTE: Placed at the end so that reserved words aren't incorrectly treated like mnemonics # /users/:user/sources/:source/:version/ - points to 'source-details' url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<source_version>[a-zA-Z0-9\-\.]+)/$', # pylint: disable=C0301 SourceDetailsView.as_view(), name='source-version-home'), )
## CORE USER - are these used at all? # URL pattern for the UserListView url(r'^$', UserListView.as_view(), name='list'), # URL pattern for the UserRedirectView url(r'^~redirect/$', UserRedirectView.as_view(), name='redirect'), # URL pattern for the UserDetailView url(r'^(?P<username>[\w@\.\+\-_]+)/$', UserDetailView.as_view(), name='detail'), # URL pattern for the UserUpdateView url(r'^update/(?P<username>[\w@\.\+\-_]+)/$', UserUpdateView.as_view(), name='update'), ## SELFISH URLs # NOTE: Placed at the end so that reserved words aren't incorrectly treated like mnemonics # /users/:user/sources/:source/:version/ - points to 'source-details' url( r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<source_version>[a-zA-Z0-9\-\.]+)/$', # pylint: disable=C0301 SourceDetailsView.as_view(), name='source-version-home'), ## Collection CORE # /users/:user/collections/new/ url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/collections/new/$',
# URL pattern for the UserListView url(r'^$', UserListView.as_view(), name='list'), # URL pattern for the UserRedirectView url(r'^~redirect/$', UserRedirectView.as_view(), name='redirect'), # URL pattern for the UserDetailView url(r'^(?P<username>[\w@\.\+\-_]+)/$', UserDetailView.as_view(), name='detail'), # URL pattern for the UserUpdateView url(r'^update/(?P<username>[\w@\.\+\-_]+)/$', UserUpdateView.as_view(), name='update'), ## SELFISH URLs # NOTE: Placed at the end so that reserved words aren't incorrectly treated like mnemonics # /users/:user/sources/:source/:version/ - points to 'source-details' url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/(?P<source_version>[a-zA-Z0-9\-\.]+)/$', # pylint: disable=C0301 SourceDetailsView.as_view(), name='source-version-home'), ## Collection CORE # /users/:user/collections/new/ url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/collections/new/$', CollectionCreateView.as_view(), name='collection-new'),
Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import path from users.views import CustomPasswordChangeView, CustomPasswordResetView, UsersCreateView, UserUpdateView, \ UserDetailView, UserDeleteView, UsersListView, UsersCreateNewView, UserUpdateClientView app_name = 'users' urlpatterns = [ path('change-password/', CustomPasswordChangeView.as_view(), name='change_password'), path('password-reset/', CustomPasswordResetView.as_view(), name='reset_password'), path('', UsersListView.as_view(), name='index'), path('create', UsersCreateView.as_view(), name='create'), path('createuser', UsersCreateNewView.as_view(), name='createuser'), path('edit', UserUpdateClientView.as_view(), name='edit'), path('update/<int:pk>/', UserUpdateView.as_view(), name='update'), path('detail/<int:pk>/', UserDetailView.as_view(), name='detail'), path('delete/<int:pk>/', UserDeleteView.as_view(), name='delete'), ]
from django.conf.urls import patterns, include, url from django.views.generic import TemplateView from users.views import UserUpdateView,UserDetailView,UserCreateView,ActivationView from users import views urlpatterns = patterns('', url(r'^update-profile/(?P<pk>\d+)/$',UserUpdateView.as_view(), name='update-profile'), url(r'^ajax_check_auth/', views.ajax_check_auth, name='ajax'), url(r'^profile/$', 'users.views.userprofile', name='profile'), url(r"^my-profile/(?P<pk>\d+)/$", UserDetailView.as_view(), name="user_detail"), url(r"^create-account/$", UserCreateView.as_view(), name="register"), url(r'^activate/(?P<activation_key>\w+)/$',ActivationView.as_view(),name='registration_activate'), url(r'^logout/(?P<next_page>.*)/$', 'django.contrib.auth.views.logout', name='logout'), url(r"^accounts/login/$", views.login_user, name = "login"), )
from django.conf.urls import url from users.views import UserListView,logoutview,LoginView,UserCreateView, \ UserDeleteView,UserHistoryView,UserDeatilView,UserUpdateView,UserDelView,UpdateUserView app_name = 'users' urlpatterns = [ #登录 url(r'login/$', LoginView.as_view(), name='login'), #创建用户 url(r'create_user/$', UserCreateView.as_view(), name='create_user'), #删除用户 # url(r'user_delete/(?P<nid_pk>\d+)/$', UserDeleteView.as_view(), name='user_delete'), # 用户删除(ajax) url(r'user_del/$', UserDelView.as_view(), name='user_del'), #用户登出 url(r'logout/$', logoutview, name='logout'), #用户列表 url(r'user_list/$', UserListView.as_view(), name='user_list'), #用户登录平台日志 url(r'user_history/$', UserHistoryView.as_view(), name='user_history'), #用户详情 url(r'user_detail/(?P<pk>\d+)/$', UserDeatilView.as_view(), name='user_detail'), #用户更新 url(r'user_update/(?P<pk>\d+)/$', UserUpdateView.as_view(), name='user_update'), # 用户更新 url(r'pwd_update/$', UpdateUserView.as_view(), name='pwd_update'), ]
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path, re_path, include from django.views.generic import TemplateView from rest_framework import routers from rest_framework_simplejwt.views import (TokenObtainPairView, TokenRefreshView, TokenVerifyView) from users.views import (UserCreateView, UserUpdateView, UserAdminCreateView, UserRetrieveView, UserListView, UserDestroyView, UserTokenView) urlpatterns = [ path('api/users/', UserListView.as_view()), path('api/users/new/', UserCreateView.as_view()), path('api/users/edit/<int:pk>/', UserUpdateView.as_view()), path('api/users/<int:pk>/', UserRetrieveView.as_view()), path('api/users/admin-new/', UserAdminCreateView.as_view()), path('api/users/delete/<int:pk>/', UserDestroyView.as_view()), path('api/admin/', admin.site.urls), path('api/auth/', include('rest_framework.urls', namespace='rest_framework')), path('api/token/', UserTokenView.as_view()), path('api/token/refresh', TokenRefreshView.as_view()), path('api/token/verify', TokenVerifyView.as_view()), re_path('.*', TemplateView.as_view(template_name='index.html')), ]
Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.contrib.auth import views as auth_views from django.urls import path from users.views import (registerView, homeView, UserCreateView, UserUpdateView, UserDeleteView) urlpatterns = [ path('admin/', admin.site.urls), path('login/', auth_views.LoginView.as_view(template_name='login.html'), name='login'), path('logout/', auth_views.LogoutView.as_view(template_name='logout.html'), name='logout'), path('register/', registerView, name='register'), path('', homeView, name='user-home'), path('user/new/', UserCreateView.as_view(), name='user-create'), path('user/<int:pk>/update', UserUpdateView.as_view(), name='user-update'), path('user/<int:pk>/delete', UserDeleteView.as_view(), name='user-delete'), ]
from django.urls import path from users.views import UserList, UserDetailView, UserCreateView, UserUpdateView, UserDeleteView, exportToCSV app_name = 'users' urlpatterns = [ path('', UserList.as_view(), name='user-list'), path('user/<int:pk>/', UserDetailView.as_view(), name='user-detail'), path('user/create', UserCreateView.as_view(), name='user-create'), path('user/update/<int:pk>/', UserUpdateView.as_view(), name='user-update'), path('user/delete/<int:pk>/', UserDeleteView.as_view(), name='user-delete'), path('export', exportToCSV, name='user-export'), ]
from django.conf.urls import patterns, url from users.views import UserDetailView, UserUpdateView urlpatterns = patterns( '', url(r'^(?P<pk>\d+)/$', UserDetailView.as_view(), name='detail'), url(r'^(?P<pk>\d+)/register$', UserUpdateView.as_view(success_url='/'), name='register'), )
1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.contrib.auth import views as auth_views from django.urls import path from django.conf.urls import include, url from users import views as user_views from django.conf import settings from django.conf.urls.static import static from users.views import UserUpdateView, UserDeleteView urlpatterns = [ path('admin/', admin.site.urls), path('', user_views.start, name='start'), path('register/', user_views.register, name='register'), path('profile/', user_views.profile, name='profile'), path('profile/update/', UserUpdateView.as_view(), name='profile-update'), path('profile/delete/', UserDeleteView.as_view(), name='profile-delete'), 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'), url(r'^tree/', include('tree.urls')), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.user_create_confirm, name='signup_confirm'), url(r'^login/$', views.user_login, name='login'), url(r'^logout/$', views.user_logout, name='logout'), url(r'^reset/$', views.user_request_reset_password, name='request_password_reset'), url(r'^reset/(?P<token>\w+)/$', views.user_reset_password, name='password_reset'), url(r'^update-password/$', views.user_password, name='update-password'), url(r'^(?P<pk>\d+)/$', UserProfileView.as_view(), name='profile'), url(r'^(?P<username>[^/]+)/$', views.user_profile_by_username, name='profile_username'), url(r'^(?P<pk>\d+)/edit/$', UserUpdateView.as_view(), name='edit'), url(r'^(?P<pk>\d+)/delete/$', UserDeleteView.as_view(), name='delete'), url(r'^(?P<pk>\d+)/favorites/$', UserFavoriteView.as_view(), name='favorites'), url(r'^notification/(?P<pk>\d+)/see/$', views.see_nofitication, name='see_notification'), url(r'^notification/mark-all/$', views.mark_all_as_read, name='mark_notifications_as_read'), url(r'^notification/show-all/$', views.show_all_notifications, name='show_all_notifications') ]
def setUp(self): super(TestUserUpdateView, self).setUp() self.view = UserUpdateView() request = self.factory.get('/fake-url') request.user = self.user self.view.request = request
path("", HomeView.as_view(), name="home-page"), path("search", SearchView.as_view(), name="search-page"), path("login/", UserLoginView.as_view(), name="login-page"), path("register/", UserRegisterView.as_view(), name="register-page"), re_path( r"^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$", UserActivationEmailView.as_view(), name="activate-email-link", ), path( "re-send-activation-link/<str:username>", UserReSendActivationEmailView.as_view(), name="re-send-activate-email-link", ), path("profile/", UserDetailView.as_view(), name="profile-page"), path("update/", UserUpdateView.as_view(), name="update-page"), path("logout/", UserLogoutView.as_view(), name="logout-page"), path("changepassword/", UserChangePasswordView.as_view(), name="changepassword-page"), path( "reset_password/", UserForgotPasswordView.as_view(), name="send-reset-password-page", ), re_path( r"^reset_password/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$", UserResetForgotPasswordView.as_view(), name="reset-password-page", ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.conf.urls import url from users.views import UserListView, UserCreateView, UserDetailView, UserUpdateView, UserDeleteView, UserCSVListView app_name = 'users' urlpatterns = [ url(r'^$', UserListView.as_view(), name='list'), url(r'^csv/$', UserCSVListView.as_view(), name='csv-list'), url(r'^add/$', UserCreateView.as_view(), name='create'), url(r'^(?P<pk>\d+)/$', UserDetailView.as_view(), name='detail'), url(r'^(?P<pk>\d+)/update/$', UserUpdateView.as_view(), name='update'), url(r'^(?P<pk>\d+)/delete/$', UserDeleteView.as_view(), name='delete'), ]
from django.urls import path from users.views import ( UserUpdateView, UserPasswordChangeView, UserPasswordChangeDoneView, ) app_name = "users" urlpatterns = [ path("<int:pk>", UserUpdateView.as_view(template_name="user.html"), name="user"), path("password_change/", UserPasswordChangeView.as_view(), name="password_change"), path( "password_change_done/", UserPasswordChangeDoneView.as_view(), name="password_change_done", ), ]
""" from django.conf.urls import url from users import views from users.views import ( UserCreateView, UserProfileView, UserUpdateView, UserDeleteView, UserFavoriteView, ) urlpatterns = [ url(r'^search$', views.user_search), url(r'^signup/$', UserCreateView.as_view(), name='signup'), url(r'^signup/confirm/(?P<token>\w+)/$', views.user_create_confirm, name='signup_confirm'), url(r'^login/$', views.user_login, name='login'), url(r'^logout/$', views.user_logout, name='logout'), url(r'^reset/$', views.user_request_reset_password, name='request_password_reset'), url(r'^reset/(?P<token>\w+)/$', views.user_reset_password, name='password_reset'), url(r'^update-password/$', views.user_password, name='update-password'), url(r'^(?P<pk>\d+)/$', UserProfileView.as_view(), name='profile'), url(r'^(?P<username>[^/]+)/$', views.user_profile_by_username, name='profile_username'), url(r'^(?P<pk>\d+)/edit/$', UserUpdateView.as_view(), name='edit'), url(r'^(?P<pk>\d+)/delete/$', UserDeleteView.as_view(), name='delete'), url(r'^(?P<pk>\d+)/favorites/$', UserFavoriteView.as_view(), name='favorites'), url(r'^notification/(?P<pk>\d+)/see/$', views.see_nofitication, name='see_notification'), url(r'^notification/mark-all/$', views.mark_all_as_read, name='mark_notifications_as_read'), url(r'^notification/show-all/$', views.show_all_notifications, name='show_all_notifications') ]
# __author__ = "MaRuiMin" from django.urls import path from users.views import UserDetailView, UserUpdateView app_name = 'users' urlpatterns = [ path(r'update/', UserUpdateView.as_view(), name="update"), path('<str:username>/', UserDetailView.as_view(), name="detail") ]
from chat.views import UserChatRecordView, UserChatRecordViewset router = DefaultRouter() router.register(r'plans', PlanTableViewset, base_name="plans") router.register(r'records', UserRecordViewset, base_name="records") router.register(r'experiences', UserExperienceViewset, base_name="experiences") router.register(r'chats', UserChatRecordViewset, base_name="chats") urlpatterns = [ path('xadmin/', xadmin.site.urls), re_path(r'docs/', include_docs_urls(title='一路考研', authentication_classes=[], permission_classes=[])), re_path(r'^', include(router.urls)), re_path(r'^users/getlist', UserProfileListView.as_view()), re_path(r'^users/login', UserLoginView.as_view()), re_path(r'^users/logout', UserLoginOutView.as_view()), re_path(r'^users/checklogin', UserCheckLoginView.as_view()), re_path(r'^users/register', UserRegisterView.as_view()), re_path(r'^users/update/(?P<update_filed>.*)/$', UserUpdateView.as_view()), re_path(r'^source/book', SourceRecommendBookView.as_view()), re_path(r'^source/video', SourceRecommendVideoView.as_view()), re_path(r'^source/aims_plan', PlanTableView.as_view()), re_path(r'^source/aims_record', UserRecordView.as_view()), re_path(r'^source/aims_experience', UserExperienceView.as_view()), re_path(r'^source/chats', UserChatRecordView.as_view()), # re_path(r'^source/plan/(?P<pk>.*)/$', PlanTableViewset.as_view({"get":"list", "post":"create", "put":"update", "delete":"destroy"})), ]
from django.urls import path from users.views import ( HostReviewsListView, HostActivitiesListView, HostAccountActivitiesListView, HostDetailView, HostUpdateView, UserUpdateView, UserReviewsListView, ) urlpatterns = [ path('hosts/<slug:slug>/reviews/', HostReviewsListView.as_view(), name='host_reviews'), path('hosts/<slug:slug>/activities/', HostActivitiesListView.as_view(), name="host_activities"), path('hosts/<slug:slug>/', HostDetailView.as_view(), name="host_detail"), path('accounts/reviews/', UserReviewsListView.as_view(), name="user_reviews"), path('accounts/host/activities/', HostAccountActivitiesListView.as_view(), name="host_activities_dashboard"), path('accounts/host/', HostUpdateView.as_view(), name="host_update"), path('accounts/', UserUpdateView.as_view(), name='user_update'), ]