def test_view_list_and_retrieve_users(self, new_user_info, json_user_no_details): # Populate the database new_user = User.objects.create_user( first_name=new_user_info['first_name'], last_name=new_user_info['last_name'], email=new_user_info['email'], country=new_user_info['country'], mobile_number=new_user_info['mobile_number'], goal=new_user_info['goal'], password=new_user_info['password']) # Create another user via posting data post_view = UserViewSet.as_view({'post': 'create'}) post_request = factory.post(USERS_URI, data=json.dumps(json_user_no_details), content_type='application/json') post_response = post_view(post_request) # Assert it was created assert post_response.status_code == 201 assert post_response.data.get('id') assert post_response.data.get('email') == json_user_no_details['email'] assert post_response.data.get('details') # FIX WHEN USERS GROUPS AND PERMISSIONS ADDED # # List all users and make sure there are 2, one populated by the db and one from posted data # get_view = UserViewSet.as_view({'get': 'list'}) # get_request = factory.get(USERS_URI) # get_response = get_view(get_request) # assert get_response.status_code == 200 # assert len(get_response.data) == 2 # # Make sure they are users with id's and the same emails # assert get_response.data[0].get('id') # assert get_response.data[0].get('email') == new_user_info['email'] # assert get_response.data[1].get('id') # assert get_response.data[1].get('email') == json_user_no_details['email'] # Retrieve the user populated from teh database retrieve_view = UserViewSet.as_view({'get': 'retrieve'}) retrieve_request = factory.get(USERS_URI + '/{}'.format(new_user.id), HTTP_AUTHORIZATION=get_jwt_header( new_user_info['email'], new_user_info['password'])) retrieve_response = retrieve_view(retrieve_request, pk=new_user.id) assert retrieve_response.status_code == 200 assert retrieve_response.data.get('id') == new_user.id assert retrieve_response.data.get('email') == new_user.email
def test_jwt_return_on_login(self, json_user_with_details): register_view = UserViewSet.as_view({'post': 'create'}) register_request = factory.post( USERS_URI, data=json.dumps(json_user_with_details), content_type='application/json') register_response = register_view(register_request) assert register_response.status_code == 201 assert register_response.data.get('id') login_view = LoginAPIView.as_view() login_data = { 'email': json_user_with_details['email'], 'password': json_user_with_details['password'] } login_request = factory.post(LOGIN_URI, data=json.dumps(json_user_with_details), content_type='application/json') login_response = login_view(login_request) assert login_response.status_code == 200 assert login_response.data.get( 'user_id') == register_response.data.get('id') assert login_response.data.get('email') == register_response.data.get( 'email') assert login_response.data.get('token')
def test_user_register_with_details(self, json_user_with_details): view = UserViewSet.as_view({'post': 'create'}) request = factory.post(USERS_URI, data=json.dumps(json_user_with_details), content_type='application/json') response = view(request) json_user_first_name = json_user_with_details['first_name'] json_user_last_name = json_user_with_details['last_name'] json_user_email = json_user_with_details['email'] json_user_country = json_user_with_details['details']['country'] json_user_mobile_number = json_user_with_details['details'][ 'mobile_number'] assert response.status_code == 201 assert response.data.get('id') assert not response.data.get('password') assert response.data.get('email') == json_user_email assert response.data.get('first_name') == json_user_first_name assert response.data.get('last_name') == json_user_last_name assert response.data.get('username') == '{}{}-{}'.format( json_user_first_name, json_user_last_name, response.data.get('id')) assert response.data.get('details', {}).get('country') == json_user_country assert response.data.get( 'details', {}).get('mobile_number') == json_user_mobile_number
def test_user_update_other_user(self, json_user_with_details, other_json_user_with_details): user = User.objects.create_user( first_name=json_user_with_details['first_name'], last_name=json_user_with_details['last_name'], email=json_user_with_details['email'], country=json_user_with_details['details']['country'], mobile_number=json_user_with_details['details']['mobile_number'], password=json_user_with_details['password']) other_user = User.objects.create_user( first_name=other_json_user_with_details['first_name'], last_name=other_json_user_with_details['last_name'], email=other_json_user_with_details['email'], country=other_json_user_with_details['details']['country'], mobile_number=other_json_user_with_details['details'] ['mobile_number'], password=other_json_user_with_details['password']) view = UserViewSet.as_view({'put': 'update'}) request = factory.put(USERS_URI, data=json.dumps({ 'email': '*****@*****.**', 'password': '******', 'details': {} }), content_type='application/json', HTTP_AUTHORIZATION=get_jwt_header( other_user.email)) response = view(request, pk=user.id) assert response.status_code == 403
def test_view_bad_permissions(self, new_user_info): u1 = User.objects.create_user( first_name=new_user_info['first_name'], last_name=new_user_info['last_name'], email=new_user_info['email'], country=new_user_info['country'], mobile_number=new_user_info['mobile_number'], goal=new_user_info['goal'], password=new_user_info['password']) onui = other_new_user_info() u2 = User.objects.create_user(first_name=onui['first_name'], last_name=onui['last_name'], email=onui['email'], country=onui['country'], mobile_number=onui['mobile_number'], goal=onui['goal'], password=onui['password']) retrieve_view = UserViewSet.as_view({'get': 'retrieve'}) retrieve_request = factory.get(USERS_URI + '/{}'.format(u1.id), HTTP_AUTHORIZATION=get_jwt_header( onui['email'], onui['password'])) retrieve_response = retrieve_view(retrieve_request, pk=u1.id) assert retrieve_response.status_code == 403 edited_user_info = new_user_info edited_user_info['first_name'] = 'Jack' put_view = UserViewSet.as_view({'put': 'update'}) put_request = factory.put(USERS_URI + '/{}'.format(u1.id), data=json.dumps(edited_user_info), content_type='application/json', HTTP_AUTHORIZATION=get_jwt_header( onui['email'], onui['password'])) put_response = put_view(put_request, pk=u1.id) assert put_response.status_code == 403 delete_view = UserViewSet.as_view({'delete': 'destroy'}) delete_request = factory.get(USERS_URI + '/{}'.format(u1.id), HTTP_AUTHORIZATION=get_jwt_header( onui['email'], onui['password'])) delete_response = delete_view(delete_request, pk=u1.id) assert delete_response.status_code == 405
def test_destroy_user_with_unauthorized_user(self): request = self.factory.delete(self.url) force_authenticate(request, user=self.user) view = UserViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=self.users[0].id) users_count = len(User.objects.all()) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(users_count, 3)
def test_user_get_other_user(self, new_user, other_user): view = UserViewSet.as_view({'get': 'retrieve'}) request = factory.get(USERS_URI, HTTP_AUTHORIZATION=get_jwt_header( new_user.email)) response = view(request, pk=other_user.id) assert response.status_code == 403
def test_destroy_user_with_admin_user(self): request = self.factory.delete(self.url) force_authenticate(request, user=self.admin_user) view = UserViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=self.users[0].id) users_count = len(User.objects.all()) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(users_count, 2)
def test_edit_user_with_admin_user(self): phone_before = self.user.profile.phone request = self.factory.patch(self.url, self.user_data, format='json') force_authenticate(request, user=self.admin_user) view = UserViewSet.as_view({'patch': 'partial_update'}) response = view(request, pk=self.user.id) phone_after = User.objects.filter(id=self.user.id)[0].profile.phone self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertNotEqual(phone_before, phone_after)
def test_user_get_self(self, new_user): view = UserViewSet.as_view({'get': 'retrieve'}) request = factory.get(USERS_URI, HTTP_AUTHORIZATION=get_jwt_header( new_user.email)) response = view(request, pk=new_user.id) assert response.status_code == 200 assert response.data.get('id') == new_user.id assert response.data.get('email') == new_user.email assert response.data.get('username') == new_user.username
def test_user_get_all_users(self, new_user): user_list_view = UserViewSet.as_view({'get': 'list'}) unauthenticated_request = factory.get(USERS_URI) unauthenticated_response = user_list_view(unauthenticated_request) assert unauthenticated_response.status_code == 401 authenticated_request = factory.get(USERS_URI, HTTP_AUTHORIZATION=get_jwt_header( new_user.email)) authenticated_response = user_list_view(unauthenticated_request) assert authenticated_response.status_code == 401
def test_user_register_without_details(self, json_user_with_details): json_user_with_details['details']['country'] = None json_user_with_details['details']['mobile_number'] = None view = UserViewSet.as_view({'post': 'create'}) request = factory.post(USERS_URI, data=json.dumps(json_user_with_details), content_type='application/json') response = view(request) assert response.status_code == 201 assert response.data.get('id') assert response.data.get('details') assert response.data.get('details', {}).get('user_id') == response.data.get('id') assert not response.data.get('details', {}).get('country') assert not response.data.get('details', {}).get('mobile_number')
def test_user_update_self(self, json_user_with_details, other_json_user_with_details): user = User.objects.create_user( first_name=json_user_with_details['first_name'], last_name=json_user_with_details['last_name'], email=json_user_with_details['email'], country=json_user_with_details['details']['country'], mobile_number=json_user_with_details['details']['mobile_number'], password=json_user_with_details['password']) assert user.id assert user.email == json_user_with_details['email'] assert user.username == '{}{}-{}'.format( json_user_with_details['first_name'], json_user_with_details['last_name'], user.id) other_json_user_with_details['password'] = json_user_with_details[ 'password'] view = UserViewSet.as_view({'put': 'update'}) request = factory.put(USERS_URI, data=json.dumps(other_json_user_with_details), content_type='application/json', HTTP_AUTHORIZATION=get_jwt_header(user.email)) response = view(request, pk=user.id) assert response.status_code == 200 assert response.data.get('id') == user.id assert User.objects.get( id=response.data.get('id')) == User.objects.get(id=user.id) assert response.data.get( 'first_name') == other_json_user_with_details['first_name'] assert response.data.get( 'last_name') == other_json_user_with_details['last_name'] assert response.data.get( 'email') == other_json_user_with_details['email'] assert response.data.get('username') == '{}{}-{}'.format( other_json_user_with_details['first_name'], other_json_user_with_details['last_name'], response.data.get('id')) assert response.data.get('details', {}).get( 'country') == other_json_user_with_details['details']['country'] assert response.data.get( 'details', {}).get('mobile_number') == other_json_user_with_details[ 'details']['mobile_number']
def test_create(self): data = self.data username = data.get('username') password = data.get('password') request = APIRequestFactory().post('', data) force_authenticate(request, user=self.superuser) user_create = UserViewSet.as_view({'post': 'create'}) response = user_create(request) self.assertEqual(response.status_code, 201, 'failed to create the user') new_user = User.objects.filter(pk=response.data.get('id')).first() self.assertIsNotNone(new_user, 'no user created') self.assertEqual(new_user.username, username, 'username is not the same') self.assertTrue(check_password(password, new_user.password), 'authentication failed')
def test_get_user_by_admin(self): """admin user(s) can get a complete list of users""" # prepare user test data administrator = UserFactory(email="*****@*****.**", nickname="tester", is_active=True, is_admin=True) dummy_user = UserFactory() dummy_user = UserFactory() dummy_user = UserFactory() # ready for the request factory = APIRequestFactory() # https://www.django-rest-framework.org/api-guide/routers/#simplerouter user_list = UserViewSet.as_view({'get': 'list'}) url = "".join([reverse('users-list')]) request = factory.get(url) force_authenticate(request, user=administrator) response = user_list(request) response_data = response.data print(response_data) assert response.status_code == 200, "HTTP status code 200" assert response_data[ 'count'] == 4, "whole user data including dummy users" # test fields must exist assert 'email' in response_data['results'][0].keys( ), "email field test." assert 'nickname' in response_data['results'][0].keys( ), "nickname field test." # test fields key check assert 'date_joined' not in response_data['results'][0].keys( ), "date_joined field test." assert 'is_active' not in response_data['results'][0].keys( ), "is_active field test." assert 'is_admin' not in response_data['results'][0].keys( ), "is_admin field test."
def test_view_delete_user(self, new_user_info): new_user = User.objects.create_user( first_name=new_user_info['first_name'], last_name=new_user_info['last_name'], email=new_user_info['email'], country=new_user_info['country'], mobile_number=new_user_info['mobile_number'], goal=new_user_info['goal'], password=new_user_info['password']) # Delete the user with new_user.id view = UserViewSet.as_view({'delete': 'destroy'}) request = factory.delete(USERS_URI + '/{}'.format(new_user.id), HTTP_AUTHORIZATION=get_jwt_header( new_user_info['email'], new_user_info['password'])) response = view(request, pk=new_user.id) assert response.status_code == 204 assert User.objects.filter(id=new_user.id).count() == 0 assert Details.objects.filter(user=new_user).count() == 0
def test_retrieve_logged_in_user_information(self): request = self.factory.get(self.url) force_authenticate(request, user=self.user) view = UserViewSet.as_view({'get': 'retrieve'}) response = view(request, pk=self.user.id) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_retrieve_user_with_non_admin_user(self): request = self.factory.get(self.url) force_authenticate(request, user=self.user) view = UserViewSet.as_view({'get': 'retrieve'}) response = view(request, pk=self.users[0].id) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_get_users_with_authenticated_adim_user(self): request = self.factory.get(self.url) force_authenticate(request, user=self.admin_user) view = UserViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_users_with_unauthorized_user(self): request = self.factory.get(self.url) force_authenticate(request, user=self.user) view = UserViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_get_users_without_authenticated_user(self): request = self.factory.get(self.url) view = UserViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_user_view(self): view = UserViewSet.as_view({'get': 'list'}) request = factory.get(USERS_URI) response = view(request) assert response.status_code == 401
url(r'^me/$', Me.as_view({'get': 'retrieve'}), name="me"), url(r'^me/favorites$', MyFavorites.as_view({'get': 'retrieve'}), name="myFavorties"), url(r'^me/motions$', MyMotions.as_view({'get': 'retrieve'}), name="myMotions"), url(r'^me/votes$', MyVotes.as_view({'get': 'retrieve'}), name="myVotes"), url(r'^(?P<user_pk>\d+)/favorites/$', UserFavoriteMotionsViewSet.as_view({ 'get': 'retrieve', 'post': 'create', 'delete': 'destroy' }), name="user_favorites"), url( r'^oauth/', include(('oauth2_provider.urls', 'oauth'), namespace='oauth2_provider')), url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', UserViewSet.as_view({'get': 'activate'}), name='activate'), url(r'^forgot-password/$', UserViewSet.as_view({'post': 'forgot'}), name='activate'), url(r'^change-password/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', UserViewSet.as_view({'put': 'changePassword'}), name='activate'), ] urlpatterns += router.urls
from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns from users.views import UserListViewSet, UserViewSet, activate_user user_list = UserListViewSet.as_view({ 'get': 'list', 'post': 'create', }) user_detail = UserViewSet.as_view({ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' }) urlpatterns = format_suffix_patterns([ path('users/', user_list, name='user-list'), path('user/<int:id>', user_detail, name='user-detail'), path('activate_email/<int:id>/<str:activate>', activate_user, name='user-activate'), ])
def test_view_create_user_with_details( self, json_user_with_details, json_user_with_details_with_one_null_detail, json_user_no_details): # Create user with json details view = UserViewSet.as_view({'post': 'create'}) request = factory.post(USERS_URI, data=json.dumps(json_user_with_details), content_type='application/json') response = view(request) # Check if all the attributes match and if password doesn't show assert response.status_code == 201 assert response.data.get('id') assert not response.data.get('password') assert response.data.get( 'first_name') == json_user_with_details['first_name'] assert response.data.get( 'last_name') == json_user_with_details['last_name'] assert response.data.get('email') == json_user_with_details['email'] assert response.data.get( 'first_name') == json_user_with_details['first_name'] instances = User.objects.filter( first_name=json_user_with_details['first_name'], last_name=json_user_with_details['last_name']).count() # Check if username is correct if instances != 1: assert response.data.get('username') == '{}{}-{}'.format( json_user_with_details['first_name'], json_user_with_details['last_name'], instances) else: assert response.data.get('username') == '{}{}'.format( json_user_with_details['first_name'], json_user_with_details['last_name']) # Check details assert response.data.get( 'details', {}).get('country') == json_user_with_details['details']['country'] assert response.data.get( 'details', {}).get('goal') == json_user_with_details['details']['goal'] assert response.data.get( 'details', {}).get('mobile_number' ) == json_user_with_details['details']['mobile_number'] # Create another user with one detail as null request = factory.post( USERS_URI, data=json.dumps(json_user_with_details_with_one_null_detail), content_type='application/json') response = view(request) # Assert new user exists but it goal is empty while other details are the same assert response.status_code == 201 assert response.data.get('id') assert not response.data.get('details', {}).get('goal') assert response.data.get( 'details', {}).get('country') == json_user_with_details_with_one_null_detail[ 'details']['country'] assert response.data.get('details', {}).get( 'mobile_number') == json_user_with_details_with_one_null_detail[ 'details']['mobile_number'] # Create another user with no details request = factory.post(USERS_URI, data=json.dumps(json_user_no_details), content_type='application/json') response = view(request) # Assert it exists and has no details assert response.status_code == 201 assert response.data.get('id') assert response.data.get('details')
def test_view_update_user(self, new_user_info, json_user_with_details, json_user_no_details): # Populate the database new_user = User.objects.create_user( first_name=new_user_info['first_name'], last_name=new_user_info['last_name'], email=new_user_info['email'], country=new_user_info['country'], mobile_number=new_user_info['mobile_number'], goal=new_user_info['goal'], password=new_user_info['password']) user_password = new_user_info['password'] # Assert user was created with same fields assert new_user.id assert new_user.first_name == new_user_info['first_name'] assert new_user.last_name == new_user_info['last_name'] assert new_user.email == new_user_info['email'] assert new_user.password != user_password assert new_user.details.country == new_user_info['country'] assert new_user.details.mobile_number == new_user_info['mobile_number'] assert new_user.details.goal == new_user_info['goal'] # Update the user with new_user.id view = UserViewSet.as_view({'put': 'update'}) request = factory.put(USERS_URI + '/{}'.format(new_user.id), data=json.dumps(json_user_with_details), content_type='application/json', HTTP_AUTHORIZATION=get_jwt_header( new_user_info['email'], user_password)) response = view(request, pk=new_user.id) # Get User with the same new_user.id edited_user = User.objects.get(id=new_user.id) # Assert response is the same as the fixture value which is also # the same with the newly created and edited user assert response.data.get('id') == edited_user.id assert response.data.get('first_name') == json_user_with_details[ 'first_name'] == edited_user.first_name assert response.data.get('last_name') == json_user_with_details[ 'last_name'] == edited_user.last_name assert response.data.get( 'email') == json_user_with_details['email'] == edited_user.email assert response.data.get( 'details', {}).get('country') == json_user_with_details['details'][ 'country'] == edited_user.details.country assert response.data.get( 'details', {}).get('mobile_number') == json_user_with_details['details'][ 'mobile_number'] == edited_user.details.mobile_number assert response.data.get( 'details', {}).get('goal') == json_user_with_details['details'][ 'goal'] == edited_user.details.goal # Edit the same user again but this time removing the details view = UserViewSet.as_view({'put': 'update'}) request = factory.put(USERS_URI + '/{}'.format(new_user.id), data=json.dumps(json_user_no_details), content_type='application/json', HTTP_AUTHORIZATION=get_jwt_header( json_user_with_details['email'], user_password)) response = view(request, pk=new_user.id) edited_user = User.objects.get(id=new_user.id) # Assert response is the same as the fixture value which is also # the same with the newly created and edited user but having no details assert response.data.get('id') == edited_user.id assert response.data.get('first_name') == json_user_no_details[ 'first_name'] == edited_user.first_name assert response.data.get('last_name') == json_user_no_details[ 'last_name'] == edited_user.last_name assert response.data.get( 'email') == json_user_no_details['email'] == edited_user.email assert response.data.get('details') assert not response.data.get('details', {}).get('country') assert not response.data.get('details', {}).get('goal') assert not response.data.get('details', {}).get('mobile_number')
from django.urls import path # from rest_framework_jwt.views import obtain_jwt_token from users.views import RegisterViewSet, ProfileViewSet, UserViewSet from rest_framework import routers from rest_framework_jwt.views import obtain_jwt_token urlpatterns = [ path('login/', obtain_jwt_token), path('profile/', ProfileViewSet.as_view({ 'get': 'retrieve', 'put': 'update' }), name='profile-detail'), path('delete/', UserViewSet.as_view({'delete': 'destroy'}), name='delete-user'), ] router = routers.DefaultRouter() router.register('register', RegisterViewSet, base_name='users') urlpatterns += router.urls
from django.urls import path, include from rest_framework.routers import DefaultRouter from rest_framework_simplejwt.views import ( TokenRefreshView, TokenVerifyView ) from users.views import UserViewSet, CustomTokenObtainViewSet router = DefaultRouter() router.register('', UserViewSet, basename='users') token_patterns = [ path('', CustomTokenObtainViewSet.as_view(), name='token_obtain_pair'), path('refresh/', TokenRefreshView.as_view(), name='token_refresh'), path('verify/', TokenVerifyView.as_view(), name='token_verify'), ] urlpatterns = [ path('analytics/', UserViewSet.as_view({'get': 'analytics'})), path('token/', include(token_patterns)), path(route='api-auth/', view=include('rest_framework.urls', namespace='rest_framework')), ] urlpatterns += router.urls
from rest_framework import renderers status_list = StatusViewSet.as_view({ 'get': 'list', 'post': 'create' }) status_detail = StatusViewSet.as_view({ 'get': 'retrieve', 'put': 'update', 'patch': 'partial_update', 'delete': 'destroy' }) user_list = UserViewSet.as_view({ 'get': 'list', 'post': 'create' }) user_detail = UserViewSet.as_view({ 'get': 'retrieve', 'put': 'update', 'patch': 'partial_update' }) cur_user = CurUser.as_view({ 'get': 'retrieve' }) urlpatterns = format_suffix_patterns([ url(r'^api/$', api_root),
from django.conf.urls import url, include from rest_framework.routers import DefaultRouter from users import views from users.views import UserViewSet # Create a router and register our viewsets with it. router = DefaultRouter() router.register(r'users', views.UserViewSet, base_name="user") user_list = UserViewSet.as_view({ 'get': 'list' }) user_detail = UserViewSet.as_view({ 'get': 'retrieve' }) urlpatterns = [ url(r'^register_verification/', views.register_verification, name='register_verification'), url(r'^register/', views.register, name='register'), url(r'^login/', views.login, name='login'), url(r'^logout/$', views.logout, name='logout'), url(r'^register_login_success/', views.register_login_success, name='register_login_success'), url(r'^my_info/$', views.my_info, name='my_info'), url(r'^update_user_info/$', views.update_user_info, name='update_user_info'), url(r'^headimg_setting/$', views.headimg_setting, name='headimg_setting'), #url(r'^permission/$', views.show_permission, name='show_permission'), #url(r'^(?P<user_id>[0-9]+)/follow/$', views.follow, name='follow'), #url(r'^(?P<user_id>[0-9]+)/unfollow/$', views.unfollow, name='unfollow'),
# -*- coding: utf-8 -*- from django.conf.urls import url, include from utils.func import SelfRouter, SimpleRouter from users.views import (UserViewSet, forget_password, user_login, check_user, LogoutView, UploadAvatarView, UploadImageView, send_code, google_login) from users.vertify_backend import VerifyViewSet self_router = SelfRouter() router = SimpleRouter() router.register('auth_verify', VerifyViewSet, base_name='auth_verify') self_router.register('', UserViewSet, base_name='users') urlpatterns = [ url(r'^login/?$', user_login, name='login'), url(r'^google_login/?$', google_login, name='google_login'), url(r'^check_user/?$', check_user, name='check_user'), url(r'^send_code/?$', send_code, name='send_code'), url(r'^forget_password/?$', forget_password, name='forget_password'), url(r'^upload_avatar/?$', UploadAvatarView.as_view(), name='upload_avatar'), url(r'^upload_image/?$', UploadImageView.as_view(), name='upload_image'), url(r'^logout/?$', LogoutView.as_view(), name='logout'), url(r'^reset_password/?$', UserViewSet.as_view({'put': 'reset_password'})), url(r'^help_center/?$', UserViewSet.as_view({'get': 'help_center'})), url(r'^', include(self_router.urls)), url(r'^', include(router.urls)), ]