Exemplo n.º 1
0
 def test_create_user_returns_username_and_email(self):
     view = UserCreate.as_view()
     factory = APIRequestFactory()
     request = factory.post("/users/create", self.test_data, format='json')
     response = view(request)
     self.assertEqual(response.data['username'], self.test_data['username'])
     self.assertEqual(response.data['email'], self.test_data['email'])
Exemplo n.º 2
0
 def test_create_user_works(self):
     view = UserCreate.as_view()
     factory = APIRequestFactory()
     request = factory.post("/users/create", self.test_data, format='json')
     view(request)
     new_user = User.objects.filter(username='******')
     self.assertEqual(new_user.count(), 1)
Exemplo n.º 3
0
    def test_create_user_creates_auth_token_for_new_user(self):
        view = UserCreate.as_view()
        factory = APIRequestFactory()
        request = factory.post("/users/create", self.test_data, format='json')
        view(request)
        new_user = User.objects.get(username='******')

        try:
            Token.objects.get(user_id=new_user.id)
        except ObjectDoesNotExist:
            self.fail("No token was created on user creation.")
Exemplo n.º 4
0
    def test_create_user_fails_with_no_email(self):
        view = UserCreate.as_view()
        factory = APIRequestFactory()
        request = factory.post("/users/create", {
            "username": "******",
            "password": "******"
        },
                               format='json')
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn("email", response.data)
Exemplo n.º 5
0
    def test_create_user_fails_with_similar_password_and_username(self):
        view = UserCreate.as_view()
        factory = APIRequestFactory()
        request = factory.post("/users/create", {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        },
                               format='json')
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn("password", response.data)
Exemplo n.º 6
0
    def test_create_user_fails_with_duplicate_user_name(self):
        view = UserCreate.as_view()
        factory = APIRequestFactory()
        existing_user = User.objects.first()
        request = factory.post("/users/create", {
            "username": existing_user.username,
            "email": "*****@*****.**",
            "password": "******"
        },
                               format='json')
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn("username", response.data)
Exemplo n.º 7
0
from django.urls import path, include

from accounts.views import MyTokenObtainPairView, UserCreate, ProfileView, profile_detail_view, get_profile_view, \
    user_follow_view

urlpatterns = [
    path('token', MyTokenObtainPairView.as_view(), name="token"),
    path('register', UserCreate.as_view(), name="register"),
    path('profile', get_profile_view, name="get-profile"),
    path('profile/update', ProfileView.as_view(), name="profile-update"),
    path('profile/<str:username>',
         profile_detail_view,
         name="profile-detail-view"),
    path('profile/<str:username>/follow',
         user_follow_view,
         name="profile-follow"),
]
Exemplo n.º 8
0
 def test_create_user_does_not_return_password(self):
     view = UserCreate.as_view()
     factory = APIRequestFactory()
     request = factory.post("/users/create", self.test_data, format='json')
     response = view(request)
     self.assertNotIn('password', response.data)
Exemplo n.º 9
0
 def test_create_user_returns_201(self):
     view = UserCreate.as_view()
     factory = APIRequestFactory()
     request = factory.post("/users/create", self.test_data, format='json')
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 10
0
from django.conf.urls import url, include
from rest_framework import routers
from calories.views import MealViewSet, SettingsViewSet, update_settings
from accounts.views import UserViewSet, UserCreate, current_user
from django.contrib import admin
from django.urls import path, include
from rest_framework_jwt.views import obtain_jwt_token

api_router = routers.DefaultRouter()
api_router.register(r'users', UserViewSet)
api_router.register(r'meals', MealViewSet, base_name='meals',)
api_router.register(r'settings', SettingsViewSet, base_name='settings',)

urlpatterns = [
    url(r'^api/', include(api_router.urls)),
    path('api/admin/', admin.site.urls),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^api/register', UserCreate.as_view(), name='account-create'),
    path('api/token-auth/', obtain_jwt_token),
    path('api/current_user/', current_user),
    path('api/update_settings/', update_settings),
]
Exemplo n.º 11
0
router.register(r'locations', LocationViewSet, base_name='locations')
router.register(r'witdraw', WitdrawalViewSet, base_name='witdraw')
router.register(r'trending', TrendingViewSet, base_name='trending')
router.register(r'ads', AdViewSet, base_name='ads')
router.register(r'site-settings',
                SiteSettingsViewSet,
                base_name='site-settings')
from django.views.generic import TemplateView
from django.views.static import serve

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('api/', include(router.urls)),
    path('api/generate-cupon/', GenerateCupon.as_view()),
    path('api/account/reset-password/', ForgotPassword.as_view()),
    path('api/account/login/', UserLoginAPIView.as_view()),
    path('api/account/read/', ReadPost.as_view()),
    path('api/account/create/', UserCreate.as_view()),
    path('admin/', admin.site.urls),
    path('api/account/comment/', CommentPost.as_view()),
    path('api-token-auth/', obtain_jwt_token),
    re_path(r'^media/(?P<path>.*)$', serve,
            {'document_root': settings.MEDIA_ROOT}),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += re_path(r'^.*',
                       TemplateView.as_view(template_name='index.html')),