-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/typescript' into td/dependencies-upgrade
- Loading branch information
Showing
13 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .views import UserViewSet | ||
|
||
|
||
routes = [ | ||
{"regex": r"users", "viewset": UserViewSet, "basename": "user"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import User | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = [ # noqa: RUF012 | ||
"id", | ||
"email", | ||
"is_active", | ||
"is_staff", | ||
"is_superuser", | ||
"created", | ||
"modified", | ||
"last_login", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from django.urls import reverse | ||
|
||
from common.utils.tests import TestCaseUtils | ||
from model_bakery import baker | ||
from rest_framework.test import APITestCase | ||
|
||
from ..models import User | ||
|
||
|
||
class UserViewSetTest(TestCaseUtils, APITestCase): | ||
def test_list_users(self): | ||
baker.make(User, _fill_optional=True, _quantity=5) | ||
|
||
response = self.auth_client.get(reverse("user-list")) | ||
|
||
self.assertResponse200(response) | ||
# Note: One user is already created in the setUp method of TestCaseUtils | ||
self.assertEqual(response.data.get("count"), 6) | ||
self.assertEqual(len(response.data.get("results")), 6) | ||
|
||
def test_create_user(self): | ||
data = { | ||
"email": "[email protected]", | ||
"password": "12345678", | ||
} | ||
|
||
response = self.auth_client.post(reverse("user-list"), data=data) | ||
|
||
self.assertResponse201(response) | ||
user = User.objects.get(id=response.data["id"]) | ||
self.assertEqual(user.email, data["email"]) | ||
|
||
def test_retrieve_user(self): | ||
user = baker.make(User, _fill_optional=True) | ||
|
||
response = self.auth_client.get(reverse("user-detail", args=[user.id])) | ||
|
||
self.assertResponse200(response) | ||
self.assertEqual(response.data["id"], user.id) | ||
self.assertEqual(response.data["email"], user.email) | ||
|
||
def test_put_update_user(self): | ||
user = baker.make(User, email="[email protected]", _fill_optional=True) | ||
data = { | ||
"email": "[email protected]", | ||
"password": "87654321", | ||
} | ||
|
||
response = self.auth_client.put( | ||
reverse("user-detail", args=[user.id]), data=data | ||
) | ||
|
||
self.assertResponse200(response) | ||
user.refresh_from_db() | ||
self.assertEqual(user.email, data["email"]) | ||
|
||
def test_patch_update_user(self): | ||
user = baker.make(User, email="[email protected]", _fill_optional=True) | ||
data = { | ||
"email": "[email protected]", | ||
} | ||
|
||
response = self.auth_client.patch( | ||
reverse("user-detail", args=[user.id]), data=data | ||
) | ||
|
||
self.assertResponse200(response) | ||
user.refresh_from_db() | ||
self.assertEqual(user.email, data["email"]) | ||
|
||
def test_delete_user(self): | ||
user = baker.make(User, _fill_optional=True) | ||
|
||
response = self.auth_client.delete(reverse("user-detail", args=[user.id])) | ||
|
||
self.assertResponse204(response) | ||
self.assertFalse(User.objects.filter(id=user.id).exists()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
from django.shortcuts import render # noqa | ||
from rest_framework import viewsets | ||
|
||
from .models import User | ||
from .serializers import UserSerializer | ||
|
||
# Create your views here. | ||
|
||
class UserViewSet(viewsets.ModelViewSet): | ||
queryset = User.objects.all() | ||
serializer_class = UserSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters