def test_user_creation_admin(self): view = UserList.as_view() factory = APIRequestFactory() request = factory.get('/users/') force_authenticate(request, user=self.test_admin) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.test_admin.username[0:10], 'test_admin')
def signup_view(self, data=None): if data is None: data = self.TEST_DATA request = APIRequestFactory().post('/api/user', data=data) response = UserList.as_view()(request).render() content = response.content.decode() content = eval(content) return response, content
def test_create_user_fail_by_user_with_read_scope_only(self): factory = APIRequestFactory() view = UserList.as_view() data = {'username': '******', 'password': '******'} request = factory.post('/api/users', data=data) force_authenticate(request, user=self.test_user, token=self.read_access_token) response = view(request) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_user_creation_10_users_list(self): view = UserList.as_view() number_users = 10 DbEntriesCreation().create_user_examples(number_users) user_objects_list = list( User.objects.filter( username__startswith="test_user_").all().values()) factory = APIRequestFactory() request = factory.get('/users/') force_authenticate(request, user=self.test_admin) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK) for i in range(0, number_users): self.assertEqual(user_objects_list[i]['username'][0:9], ('test_user_' + str(i))[0:9])
def test_create_user_fail_because_of_existense(self): user = User.objects.create(id=2, username='******', password='******', email='*****@*****.**') data = {'id': user.id, 'username': '******', 'email': '*****@*****.**'} factory = APIRequestFactory() view = UserList.as_view() request = factory.post('/api/users/', data=data) force_authenticate(request, user=self.test_user, token=self.full_access_token) response = view(request) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_get_users(self): factory = APIRequestFactory() view = UserList.as_view() users = User.objects.bulk_create([ User(id=2, username='******', password='******', email='*****@*****.**'), User(id=3, username='******', password='******', email='*****@*****.**'), User(id=4, username='******', password='******', email='*****@*****.**'), ]) request = factory.get('/api/users') force_authenticate(request, user=self.test_user, token=self.full_access_token) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK) # 4 Because in setUp() one user instantiated. self.assertEqual(len(response.data), 4) users_names = [user['username'] for user in response.data] users_emails = [user['email'] for user in response.data] for user in users: self.assertIn(user.username, users_names) self.assertIn(user.email, users_emails) force_authenticate(request, user=self.test_user, token=self.read_access_token) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 4) users_names = [user['username'] for user in response.data] users_emails = [user['email'] for user in response.data] for user in users: self.assertIn(user.username, users_names) self.assertIn(user.email, users_emails)
def test_create_user(self): factory = APIRequestFactory() view = UserList.as_view() data = { 'username': '******', 'password': '******', 'email': '*****@*****.**' } request = factory.post('/api/users/', data=data) force_authenticate(request, user=self.test_user, token=self.full_access_token) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(data['username'], response.data.get('username')) self.assertEqual(data['email'], response.data.get('email'))
], extra={'model': Entity, 'serializer_class': EntitySerializer}))), url(r'^texts/$', TextList.as_view(), name='text-list'), url(r'^texts/(?P<pk>\d+)/$', TextDetail.as_view()), url(r'^texts/(?P<pk>\d+)/', include(APIView.urlpatterns([ {}, {'func': 'next'}, {'func': 'prev'}, {'func': 'parent'}, {'func': 'has_parts'}, {'func': 'is_text_in', 'serializer_class': DocSerializer}, {'func': 'is_text_of', 'serializer_class': EntitySerializer}, {'func': 'xml', 'serializer_class': None}, {'func': 'get_refsdecls', 'serializer_class': RefsDeclSerializer}, ], extra={'model': Text, 'serializer_class': TextSerializer}))), url(r'^users/$', UserList.as_view(), name='user-list'), url(r'^users/(?P<pk>\d+)/$', UserDetail.as_view(), name='user-detail'), url(r'^users/(?P<pk>\d+)/', include(APIView.urlpatterns([ {'func': 'communities', 'serializer_class': CommunitySerializer}, {'func': 'can_edit', 'func_args': '(?P<doc_pk>\d+)/'}, { 'func': 'memberships', 'serializer_class': MembershipSerializer }, { 'func': 'memberships', 'func_args': '(?P<community_pk>\d+)/', 'serializer_class': MembershipSerializer, }, ], extra={'model': APIUser, 'serializer_class': APIUserSerializer}))), url(r'^tasks/(?P<pk>\d+)/$', TaskDetail.as_view()), url(r'^memberships/$', MembershipList.as_view()),
"""Trello_Clone URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: 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.urls import path, include from api.views import UserList, BoardList, ListsList, CardsList, login urlpatterns = [ path('admin/', admin.site.urls), path('api/user', UserList.as_view()), path('api/board', BoardList.as_view()), path('api/lists', ListsList.as_view()), path('api/cards', CardsList.as_view()), path('api/login', login), ]
from api.views import CategoryDetail, SubcategoryDetail, UserList, UserDetail, \ CityList, CategoryList, SubCategoryList, CityDetail, ListCreateListing, \ DetailUpdateDeleteListing from rest_framework.authtoken import views from django.conf.urls import url, include urlpatterns = [ url(r'^api-token-auth/$', views.obtain_auth_token), url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^users/$', UserList.as_view(), name="list_user"), url(r'^users/(?P<pk>\d+)/$', UserDetail.as_view(), name="detail_user"), url(r'^cities/(?P<pk>\d+)/$', CityDetail.as_view(), name="detail_city"), url(r'^cities/$', CityList.as_view(), name="city_list"), url(r'^categories/$', CategoryList.as_view(), name="list_category"), url(r'^categories/(?P<pk>\d+)/$', CategoryDetail.as_view(), name="detail_category"), url(r'^subcategories/$', SubCategoryList.as_view(), name="subcategory_list"), url(r'^subcategories/(?P<pk>\d+)/$', SubcategoryDetail.as_view(), name="subdetail_category"), url(r'^classifieds/$', ListCreateListing.as_view(), name="list_create_listing"), url(r'^classifieds/(?P<pk>\d+)/$', DetailUpdateDeleteListing.as_view(), name="detail_update_delete_listing") ]
from django.urls import path from api.views import GetSuperUser, UserList, StartupReplyWithIdList, StartupCommentWithIdList, StartupsListAPIView, StartupsCreateAPIView, StartupCommentAPIView, StartupCommentList, StartupReplyAPIView, StartupReplyList, StartupsWithIdAPIView urlpatterns = [ path('startups/list', StartupsListAPIView.as_view(), name='api-startups'), path('startups/create', StartupsCreateAPIView.as_view(), name='api-startups-create'), path('startups/list/<int:id>/', StartupsWithIdAPIView.as_view(), name='api-startup-with-id'), path('comment/create', StartupCommentAPIView.as_view(), name='api-comment'), path('comment/list', StartupCommentList.as_view(), name='api-comment-list'), path('comment/<int:id>/', StartupCommentWithIdList.as_view(), name='api-comment-with-id'), path('reply/create', StartupReplyAPIView.as_view(), name='api-reply'), path('reply/list', StartupReplyList.as_view(), name='api-reply-list'), path('reply/<int:id>/', StartupReplyWithIdList.as_view(), name='api-reply-with-id'), path('users/list/', UserList.as_view(), name='api-users'), path('superuser/list/', GetSuperUser.as_view(), name='api-superusers'), # path('experts/list/', ExpertList.as_view(), name='api-experts-list'), ]
# -*- coding: utf-8 -*- from django.urls import path, re_path from api.views import ProjectList, ProjectInstanceView, UserList, ReportingPeriodList, ReportingPeriodAudit, \ TimecardList, hours_by_quarter, hours_by_quarter_by_user, UserDataView urlpatterns = [ path('projects.json', ProjectList.as_view(), name='ProjectList'), path('projects/<int:pk>.json', ProjectInstanceView.as_view(), name='ProjectInstanceView'), path('reporting_period_audit.json', ReportingPeriodList.as_view(), name='ReportingPeriodList'), re_path( r'^reporting_period_audit/(?P<reporting_period_start_date>[0-9]{4}-[0-9]{2}-[0-9]{2}).json$', ReportingPeriodAudit.as_view(), name='ReportingPeriodAudit' ), path('timecards.json', TimecardList.as_view(), name='TimecardList'), path('hours/by_quarter.json', hours_by_quarter, name='HoursByQuarter'), path('hours/by_quarter_by_user.json', hours_by_quarter_by_user, name='HoursByQuarterByUser'), path('users.json', UserList.as_view(), name='UserList'), path('user_data.json', UserDataView.as_view(), name='UserDataView'), ]
"""sc_user_profiles URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/ Examples: 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.urls import path from api.views import UserList from api import views urlpatterns = [ path('addUser', views.create_user, name='create_user'), path('listUsers', UserList.as_view(), name='list'), path('deleteUser/<int:user_id>', views.delete_user, name='delete_user'), path('updateUserDetails/<int:user_id>', views.updateUserDetails, name='updateUserDetails'), path('listProfiles/<int:user_id>', views.list_profiles, name='list_profiles'), ]
#!/usr/bin/python # -*- coding:utf-8 -*- from django.conf.urls import url from api.views import ApiEndpoint, UserList urlpatterns = [ # OAuth 2 endpoints: url(r'^hello/$', ApiEndpoint.as_view()), # an example resource endpoint url(r'^users/$', UserList.as_view()), url(r'^users/(?P<pk>\d+)/$', UserList.as_view()), url(r'^groups/$', UserList.as_view()), ]
from django.conf.urls import url, include from api.views import UserList, PostDetail, PostList, UserPostList, UserDetail, PostPhotoList, PhotoList, PhotoDetail # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. users_urls = [ url(r'^$', UserList.as_view(), name='user-list'), url(r'^(?P<username>[0-9a-zA-Z_-]+)/$', UserDetail.as_view(), name='user-detail'), url(r'^(?P<username>[0-9a-zA-Z_-]+)/posts/$', UserPostList.as_view(), name='userpost-list'), ] posts_urls = [ url(r'^$', PostList.as_view(), name='post-list'), url(r'^(?P<pk>\d+)/photos/$', PostPhotoList.as_view(), name='postphoto-list'), url(r'^(?P<pk>\d+)/$', PostDetail.as_view(), name='post-detail'), ] photos_urls = [ url(r'^(?P<pk>\d+)/$', PhotoDetail.as_view(), name='photo-detail'), url(r'^$', PhotoList.as_view(), name='photo-list'), ] urlpatterns = [
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from api.views import DatasetList as APIDatasetList from api.views import DatasetShow as APIDatasetShow from api.views import OrganisationList as APIOrganisationList from api.views import OrganisationShow as APIOrganisationShow from api.views import ResourceList as APIResourceList from api.views import ResourceShow as APIResourceShow from api.views import UserList as APIUserList from api.views import UserShow as APIUserShow from django.conf.urls import url urlpatterns = [ url('^user/?$', APIUserList.as_view(), name='user_list'), url('^user/(?P<username>\w+)/?$', APIUserShow.as_view(), name='user_show'), url('^organisation/?$', APIOrganisationList.as_view(), name='organisation_list'), url('^organisation/(?P<organisation_name>[a-z0-9\\-]+)/?$', APIOrganisationShow.as_view(), name='organisation_show'), url('^dataset/?$', APIDatasetList.as_view(), name='dataset_list'), url('^dataset/(?P<dataset_name>[a-z0-9\\-]+)/?$', APIDatasetShow.as_view(), name='dataset_show'), url('^dataset/(?P<dataset_name>[a-z0-9\\-]+)/resource/?$', APIResourceList.as_view(), name='resource_list'), url('^dataset/(?P<dataset_name>[a-z0-9\\-]+)/resource/(?P<resource_id>[a-z0-9\\-]+)/?$',
from allauth.account.views import confirm_email from django.conf.urls import url from django.urls import path, include from api.views import UserList, UserDetail, ProfileDetail urlpatterns = [ path('rest-auth/', include('rest_auth.urls')), url(r'^rest-auth/registration/', include('rest_auth.registration.urls')), url(r'^verify-email/(?P<key>[\w@+-:]+)/$', confirm_email, name="account_confirm_email"), url(r'^user/$', UserList.as_view(), name="users_list"), url(r'^user/(?P<pk>[\w]+)/$', UserDetail.as_view(), name="user_detail"), url(r'^profile/(?P<user>[\w]+)/$', ProfileDetail.as_view(), name="profile_detail"), ]
router = routers.DefaultRouter() router.register(r'users', UserViewSet) #router.register(r'groups', GroupViewSet) #router.register(r'person', PersonViewSet) #router.register(r'data', PersonDetailViewSet) router.register(r'signals', SignalViewSet) router.register(r'news', NewsViewSet) router.register(r'rules', RuleViewSet) router.register(r'questions', QuestionViewSet) router.register(r'petrol-prices', PetrolPricesViewSet) router.register(r'maintenance-activity', MaintenanceViewSet) router.register(r'quiz-list', QuizViewSet) urlpatterns = [ path('admin/', admin.site.urls), path('', include(router.urls)), path('api_auth/', include('rest_framework.urls', namespace='rest_framework')), #path('test/', TestView, name='test'), #path('datatable/', DatatableView, name='datatable'), path('get-token/', rest_auth_view.obtain_auth_token, name='get-token'), #path('token-example/', TokenExample, name='token-example'), path('webhook/', WebHookView.as_view(), name='webhook'), path('list/<int:id>', UserList.as_view(), name='user-list') ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.conf.urls import include, url, patterns from django.contrib import admin from rest_framework import routers from api.views import UserDetail,UserList,AuthView,logoutView,UserSignup from django.conf import settings from django.conf.urls.static import static #router = routers.DefaultRouter() #router.register(r'user', UserView, 'list') urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^user/login/$',AuthView.as_view()), url(r'^user/logout/$',logoutView), url(r'^user/signup/$',UserSignup.as_view()), url(r'^user/$', UserList.as_view()), url(r'^user/(?P<pk>[0-9]+)/$', UserDetail.as_view()), # url(r'^', include(router.urls)), ) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
UpdateView, AreaList, UserList, UpdateSchudel, CreateScheduel, # UserProfileCreateView, UpdateUserProfile, UserProfileList, # UpdateUserProfile ) urlpatterns = [ path('admin/', admin.site.urls), path('login/', obtain_jwt_token, name='login'), path('register/', RegisterAPIView.as_view(), name='register'), path('users/', UserList.as_view(), name='users-list'), path('profile/info/get&update/<int:user_id>', UpdateUserProfile.as_view(), name='user-info'), path('users/profiles', UserProfileList.as_view(), name='users-profiles'), # path('user/profile/<int:profile_id>', UpdateUserProfile.as_view(), name='user-profile'), path('doctor/list', DoctorProfileList.as_view(), name='doctor-list'), path('doctor/schedeul', ScheduelList.as_view(), name='doctor-scheduel'), path('update/schedeul/<int:user_id>', UpdateSchudel.as_view(), name='update-scheduel'), path('create/schedeul/', CreateScheduel.as_view(), name='create-scheduel'), path('make/favourite/<int:doctor_id>', MakeFavourite.as_view(), name='make-favourite'), path('favourite/', FavouriteList.as_view(), name='favourite'),
"""config URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.1/topics/http/urls/ Examples: 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.urls import path from api.views import UserList, LoginView urlpatterns = [ path('admin/', admin.site.urls), path('users/', UserList.as_view()), path('login/', LoginView.as_view()) ]
"""mysite URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: 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.urls import path from django.conf.urls import url from api.views import UserList, UserDetail urlpatterns = [ path('admin/', admin.site.urls), url(r'^api/users/$', UserList.as_view(), name="User_list"), #path('api/users/<str:name>', UserList.as_view(), name="User_list"), url(r'^api/users/(?P<id>\d+)/$', UserDetail.as_view(), name="User_Detail"), ]
from django.conf.urls import url, include from django.contrib import admin from api.views import UserList, UserDetail, ProfileList, ProfileDetail, JobPostingList, \ JobPostingDetail, JobApplicationList, JobApplicationDetail, InviteViaEmail, ProfileRecommendations, \ EducationDescriptionList, EducationDescriptionDetail, EmploymentDescriptionList, EmploymentDescriptionDetail, \ SkillList, SkillDetail, CompanyList, CompanyDetail, ForgottenPasswordEmail, ResetPassword, Search, RegisterConnection, \ ConnectionList, ProfileImageList, ProfileApplicationIDs, ProfileApplicationList, FeedPostList, UserJobPostingsList, \ ChangePassword, DeleteConnection urlpatterns = [ url(r'^users/$', UserList.as_view()), url(r'^users/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/$', UserDetail.as_view()), url(r'^users/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/change-password/$', ChangePassword.as_view()), url(r'^profiles/$', ProfileList.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/$', ProfileDetail.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/recommendations/$', ProfileRecommendations.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/application_ids/$', ProfileApplicationIDs.as_view()), url(r'^jobs/$', JobPostingList.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/$', JobPostingDetail.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/applications/$', JobApplicationList.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/applications/(?P<application_id>[0-9]+)/$', JobApplicationDetail.as_view()), url(r'^send-invite/$', InviteViaEmail.as_view()), url(r'^forgot-password/$', ForgottenPasswordEmail.as_view()), url(r'^reset-password/$', ResetPassword.as_view()),
name="searchlist"), #search shop api url(r'^order_create/$', OrderCreateView.as_view(), name="create"), #create order api url(r'^order_details/(?P<pk>[0-9]+)/$', OrderDeatilsView.as_view(), name="details"), url(r'^order_history/$', OrderHistory.as_view(), name="create"), url(r'^user_registration/$', UserRegistration.as_view(), name="create"), url(r'^change_password/$', UpdatePassword.as_view(), name="create"), #change password api url(r'^reset_password/$', ResetPasswordRequestView.as_view(), name="create"), url(r'^create_wishlist/$', WishListCreate.as_view(), name="create"), url(r'^create_user/$', create_user, name="create"), #this link for usercreation url(r'^login/$', login_user), #user login url(r'^cerate_user_list/$', UserList.as_view(), name="create"), url(r'^create_order/$', CreateOrder), #for test create_user url( r'^user/(?P<pk>[0-9]+)/$', User_detail ), #the given url is using for dispalying user information and updating user information url(r'^product/(?P<pk>[0-9]+)/$', Product_view), # display product details api url(r'^shop/(?P<pk>[0-9]+)/$', Shop_details_view), #display shop details api } urlpatterns = format_suffix_patterns(urlpatterns)