Esempio n. 1
0
    def test_get_users_by_user_type_method_should_filter_queryset_by_user_type(self):
        queryset = UserList()._get_users_by_user_type(CustomUser.UserType.EMPLOYEE.name, self.queryset_active)

        self.assertEqual(len(queryset), 1)
        self.assertTrue(self.user_employee in queryset)
        self.assertFalse(self.user_admin in queryset)
        self.assertFalse(self.user_manager in queryset)
Esempio n. 2
0
    def test_get_ordered_list_of_users_should_order_users_by_hierarchy(self):
        ordered_list = UserList()._get_ordered_list_of_users(self.queryset_active)

        self.assertEqual(len(ordered_list), 3)
        self.assertEqual(ordered_list[0], self.user_admin)
        self.assertEqual(ordered_list[1], self.user_manager)
        self.assertEqual(ordered_list[2], self.user_employee)
Esempio n. 3
0
    def test_post_valid_user_with_invalid_email(self):
        self.assertTrue(User.objects.all().count() == 0)
        post_data = {
            'username': '******',
            'password': 123456789,
            'email': 'testgmail.com',
        }

        request = self.request_factory.post(reverse('users:user-list'), post_data, format='json')
        view = UserList.as_view()
        response = view(request)
        response.render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertTrue(User.objects.all().count() == 0)
Esempio n. 4
0
    def test_get_all_users_without_proper_authentication(self):
        user1 = User(username='******')
        user1.set_password('12345')
        user1.save()
        user2 = User(username='******')
        user2.set_password('12345')
        user2.save()

        request = self.request_factory.get(reverse('users:user-list'), format='json')
        force_authenticate(request, user=user1)
        view = UserList.as_view()
        response = view(request)
        response.render()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Esempio n. 5
0
    def test_post_user_with_username_and_password_and_email(self):
        self.assertTrue(User.objects.all().count() == 0)
        post_data = {
            'username': '******',
            'password': 123456789,
            'email': '*****@*****.**',
        }

        request = self.request_factory.post(reverse('users:user-list'), post_data, format='json')
        view = UserList.as_view()
        response = view(request)
        response.render()
        serializer = UserSerializer(User.objects.get(pk=1), context={'request': request})

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data, serializer.data)
        self.assertTrue(User.objects.all().count() == 1)
Esempio n. 6
0
    def test_get_all_users_with_manual_authentication(self):
        user1 = User(username='******')
        user1.set_password('12345')
        user1.is_superuser = True
        user1.save()
        user2 = User(username='******')
        user2.set_password('12345')
        user2.save()
        post_data = {
            'username': user1.get_username(),
            'password': '******'
        }

        # 'Logging in' and getting the JSON web token
        request = self.request_factory.post(
            reverse('auth:token'), post_data, format='json'
        )
        view = ObtainJSONWebToken.as_view()
        response = view(request)
        response.render()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data.get('token'))

        # Performing a 'SuperUser' action

        # With APIClient
        # self.client.credentials(HTTP_AUTHORIZATION='JWT {}'.format(response.data.get('token')))
        # response = self.client.get(
        #     reverse('users:user-list'), format='json'
        # )

        # With APIRequestFactory (more explicit)
        request = self.request_factory.get(
            reverse('users:user-list'), format='json', HTTP_AUTHORIZATION='JWT {}'.format(response.data.get('token'))
        )
        view = UserList.as_view()
        response = view(request)
        response.render()
        serializer = UserSerializer(User.objects.all(), many=True, context={'request': request})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
Esempio n. 7
0
    def test_get_all_users(self):
        user1 = User(username='******')
        user1.set_password('12345')
        user1.is_superuser = True
        user1.save()
        user2 = User(username='******')
        user2.set_password('12345')
        user2.save()
        post_data = {
            'username': user1.get_username(),
            'password': '******'
        }

        request = self.request_factory.get(
            reverse('users:user-list'), format='json'
        )
        force_authenticate(request, user=user1)
        view = UserList.as_view()
        response = view(request)
        response.render()
        serializer = UserSerializer(User.objects.all(), many=True, context={'request': request})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
Esempio n. 8
0
"""Users URL Configuration."""
from django.urls import path

from users.views import UserDetail, UserList

app_name = "users"
urlpatterns = [

    path("users/", UserList.as_view(), name="user_list"),
    path("users/<slug:pk>/", UserDetail.as_view(), name="user_detail"),

]
Esempio n. 9
0
from rest_framework import urlpatterns
from rest_framework.routers import SimpleRouter
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)

from courses.views import CourseViewSet, EnrollmentViewSet
from users.views import create_auth, UserList, profile
from resources.views import ResourceViewSet
from assignments.views import AssignmentViewSet, SubmitAssignmentViewSet

app_name = "api"
router = SimpleRouter()
router.register(r"courses", CourseViewSet)
router.register(r"enroll", EnrollmentViewSet)
router.register(r"resources", ResourceViewSet)
router.register(r"assignments", AssignmentViewSet)
router.register(r"submit", SubmitAssignmentViewSet)

urlpatterns = [
    url('', include(router.urls)),
    url(r'^users/$', UserList.as_view()),
    url(r'^users/profile', profile, name="profile"),
    url(r'^users/register', create_auth, name="register"),
    # url(r'^users/login', login_view, name="login"),
    # url(r'^users/login', login, name="login"),
    # url(r'^users/logout/', LogoutView.as_view(), name="logout"),
    url(r'^token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    url(r'^token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]
Esempio n. 10
0
#from goods.view_base import GoodsListView
from goods.views import GoosListViewSet, CategroyViewSet, BannerViewset
from users.views import UserList
from rest_framework.routers import DefaultRouter
from rest_framework_jwt import views

router = DefaultRouter()  #实例化 DefaultRouter
router.register("goods", GoosListViewSet, base_name="goods-list")
router.register("categorys", CategroyViewSet, base_name="goods-list")
router.register(r'banners', BannerViewset, base_name="banners")

urlpatterns = [
    #xadmin 配置
    path('xadmin/', xadmin.site.urls),
    #
    path('ueditor/', include('DjangoUeditor.urls')),
    path('media/<path:path>', serve, {'document_root': MEDIA_ROOT}),
    #drf文档路由,title为标题
    path('docs/', include_docs_urls(title='练习生鲜系统')),
    #配置drf的urls
    path('api-auth/', include_docs_urls('rest_framework.urls')),

    #个人接口配置
    path('', include(router.urls)),
    #path('goods/',GoosListView.as_view(),name='goods-list'),
    path('users/', UserList.as_view(), name='users-list'),

    #使用jwt配置token验证接口
    path('login/', views.obtain_jwt_token)
]
Esempio n. 11
0
from django.urls import path, include
from users.views import UserList, details, uploadImage, search

urlpatterns = [
    path('all', UserList.as_view()),
    path('details', details),
    path('image', uploadImage),
    path('search', search),
]
Esempio n. 12
0
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns

from .views import RentalDetailView, RentalListView, RentalCreateView, RentalDetailAPI, RentalListAPI
from users.views import UserDetail, UserList

urlpatterns = [
    # path('', RentalListView.as_view(), name='rental-list'),
    # path('<int:pk>/', RentalDetailView.as_view(), name='rental-detail'),
    path('', RentalListAPI.as_view(), name='rental-list'),
    path('<int:pk>', RentalDetailAPI.as_view(), name='rental-detail'),
    path('new/<int:pk>', RentalCreateView.as_view(), name='rental-create'),
    path('users/', UserList.as_view(), name='user-list'),
    path('users/<int:pk>/', UserList.as_view(), name='user-detail')
]

urlpatterns = format_suffix_patterns(urlpatterns)
Esempio n. 13
0
from django.urls import path
from users.views import current_user, UserList, FriendList, AddFriend, SearchUser

urlpatterns = [
    path('current_user/', current_user),
    path('users/', UserList.as_view()),
    path('friends/', FriendList.as_view()),
    path('search-user/', SearchUser.as_view()),
    path('add-friend/', AddFriend.as_view()),
]
Esempio n. 14
0
from django.urls import path
from . import views as user_views
from django.contrib.auth import views as auth_views
from users.views import NewUser, UpdateUser, DeleteUser, UserList

urlpatterns = [
    path('signup/', user_views.signup, name='signup'),
    path('login/', auth_views.LoginView.as_view(), name='login'),
    path('profile/', user_views.profile, name='profile'),
    path('create/', NewUser.as_view(), name='new_user'),
    path('lista/', UserList.as_view(), name='users_list'),
    path('edit/<int:pk>/', UpdateUser.as_view(), name='edit_user'),
    path('delete/<int:pk>/', DeleteUser.as_view(), name='delete_user'),
]
Esempio n. 15
0
from django.urls import path

from users.views import UserList, UserAdd, UserDelete, UserUpdate

app_name = 'users'

urlpatterns = [
    path('', UserList.as_view(), name='list'),
    path('add/', UserAdd.as_view(), name='add'),
    path('edit/<int:pk>/', UserUpdate.as_view(), name='update'),
    path('delete/<int:pk>/', UserDelete.as_view(), name='delete'),
]
Esempio n. 16
0
#-*- coding: utf-8 -*-

from django.conf.urls.defaults import patterns, include, url

from users.views import UserDetail, UserList


urlpatterns = patterns('users.views',
    url(r'^$', UserList.as_view()),
    url(r'^page/(?P<page>\d+)$', UserList.as_view()),
    url(r'^(?P<pk>\d+)$', UserDetail.as_view()),
    url(r'^activate/(?P<pk>\d+)(?P<key>[a-f0-9]{40})$', 'activate_profile'),
    #url(r'^requestpassword$', ''),
)

Esempio n. 17
0
    UserDetail,
    UserList,
    Login,
    GoogleLogin,
    FacebookLogin,
    Logout,
    Signup,
    ActivateUser,
    ResetPassword,
    FollowUserToggle,
    ProfileImage,
)

urlpatterns = [
    # User Object
    url(r'^$', UserList.as_view(), name='list'),
    url(r'^(?P<pk>\d+)/$', UserDetail.as_view(), name='detail'),

    # User Follow
    url(r'^(?P<pk>\d+)/follow/$', FollowUserToggle.as_view(), name='follow'),

    # User profile image
    url(r'^(?P<pk>\d+)/profile-img/$',
        ProfileImage.as_view(),
        name='profile-img'),

    # User Login/Signup
    url(r'^login/$', Login.as_view(), name='login'),
    url(r'^logout/$', Logout.as_view(), name='logout'),
    url(r'^signup/$', Signup.as_view(), name='signup'),
    url(r'^activate/$', ActivateUser.as_view(), name='activate'),
Esempio n. 18
0
from django.urls import path
from rest_framework.authtoken.views import obtain_auth_token

from users.views import UserList
from users.views import CurrentUserRetrieveUpdateView

urlpatterns_users = [
    path('auth/register/', UserList.as_view(),
         name='UserList'),  # local item url created
    path('auth/login/', obtain_auth_token),
    path('current/',
         CurrentUserRetrieveUpdateView.as_view(),
         name='CurrentUser'),
]
Esempio n. 19
0
     ProductStockList.as_view(),
     name="All_product_stocks"),
 url(r'^api/product-stock/(?P<pk>[0-9]+)',
     UpdateProductStock.as_view(),
     name="Update_product_stock"),
 url(r'^api/mystyle', MyStyleList.as_view(), name="My_Style"),
 url(r'^api/mystyle/(?P<pk>[0-9]+)',
     UpdateMerchant.as_view(),
     name="Edit_Style"),
 url(r'^api/photos', PhotosList.as_view(), name="Store_photos"),
 url(r'^api/photos/(?P<pk>[0-9]+)',
     UpdatePhotos.as_view(),
     name="Edit_photos"),
 url(r'^api/feed', FeedList.as_view(), name="Show_feed"),
 url(r'^api/feed/(?P<pk>[0-9]+)', UpdateFeed.as_view(), name="Edit_Feed"),
 url(r'^api/users', UserList.as_view(), name="Users"),
 #url(r'^api/registration', CreateUserView.as_view(), name="Register"),
 #url(r'^api/users/(?P<pk>[0-9]+)', UpdateUser.as_view(), name="Edit_User"),
 url(r'^api/orders', OrderList.as_view(), name="Orders"),
 url(r'^api/orders/(?P<pk>[0-9]+)',
     UpdateOrder.as_view(),
     name="Edit_orders"),
 url(r'^api/payment', PaymentList.as_view(), name="Payment"),
 url(r'^api/payment/(?P<pk>[0-9]+)',
     PaymentList.as_view(),
     name="Edit_payment"),
 url(r'^api/orderered-products',
     OrderedProductsList.as_view(),
     name="orderered_products"),
 url(r'^api/orderered-products/(?P<pk>[0-9]+)',
     UpdateOrderedProducts.as_view(),
Esempio n. 20
0
from django.urls import path 
from users.views import UserList,UserDetail

app_name = 'users'

urlpatterns = [
    path('' ,UserList.as_view() ),
    path('details',UserDetail )
]
Esempio n. 21
0
from registration.backends.default.views import RegistrationView
from rest_framework.urlpatterns import format_suffix_patterns

from users.forms import UserRegistrationForm
from users import views
from users.views import UserList


urlpatterns = patterns('',
                       url(r'^login/$', views.web_login, {'template_name': 'registration/login.html'},
                           name='auth_login'),
                       url(r'^register/$', RegistrationView.as_view(form_class=UserRegistrationForm,
                                                                    template_name='registration/registration_form.html')),
                       url(r'^logout/$', views.logout, name='logout'),

                       url(r'^set-company/(?P<id>[0-9]+)/$', views.set_company, name='set_company'),

                       url(r'^roles/$', views.roles, name='roles'),
                       url(r'^role/delete/(?P<id>[0-9]+)/$', views.delete_role, name='delete_role'),


                       url(r'^list$', UserList.as_view(), name='user-list'),
                       # url(r'^$', 'users.views.profile'),
                       # url(r'^edit/$', 'users.views.edit_profile'),
                       # url(r'^auth-error/$', 'users.views.auth_error'),
                       (r'^', include('registration.backends.default.urls')),
                       # url(r'^(?P<username>[a-zA-Z0-9_.-]+)/$', 'users.views.profile', name='user-detail'),
)

# Format suffixes
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'api'])