Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
6bfaf484
Commit
6bfaf484
authored
Apr 07, 2020
by
Jonathan Christopher Jakub
Browse files
[REFACTOR] Fix stylings
parent
1525dc85
Pipeline
#39134
passed with stages
in 19 minutes and 35 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/accounts/tests/test_units/test_accounts.py
View file @
6bfaf484
...
...
@@ -5,8 +5,8 @@ from rest_framework import status
from
rest_framework.authtoken.models
import
Token
from
rest_framework.test
import
APITestCase
,
APIClient
from
apps.accounts.models
import
Account
from
apps.accounts.tests.factories.accounts
import
AccountFactory
,
UserFactory
from
apps.accounts.models
import
Account
from
apps.constants
import
(
HEADER_PREFIX
,
ACTIVITY_TYPE_CREATE
,
...
...
@@ -51,7 +51,6 @@ class AccountViewTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"detail":"Invalid page."'
,
response_string
)
def
test_list_all_accounts_filter_success
(
self
):
...
...
@@ -61,7 +60,6 @@ class AccountViewTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"count":1'
,
response_string
)
def
test_list_all_accounts_filter_failed
(
self
):
...
...
@@ -71,7 +69,6 @@ class AccountViewTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"count":0'
,
response_string
)
def
test_retrieve_account_success
(
self
):
...
...
@@ -240,7 +237,7 @@ class AccountViewTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertJSONEqual
(
json
.
dumps
(
response
.
data
),
data
)
def
test_retrieve_current_profile_fails_without_login
(
self
):
url
=
self
.
PROFILE_URL
self
.
client
=
APIClient
()
...
...
apps/accounts/views.py
View file @
6bfaf484
from
django.contrib.auth.models
import
User
from
django.shortcuts
import
get_object_or_404
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework
import
status
,
viewsets
from
rest_framework.decorators
import
action
from
rest_framework.response
import
Response
from
rest_framework.pagination
import
PageNumberPagination
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.response
import
Response
from
apps.accounts.filters
import
AccountFilter
from
apps.accounts.models
import
Account
from
apps.accounts.serializers
import
(
AccountSerializer
,
AccountRegisterSerializer
,
)
from
apps.accounts.filters
import
AccountFilter
from
apps.commons.permissions
import
(
IsSelfOrAdministrator
,
CreateOnly
,
)
from
apps.logs.models
import
Log
from
apps.constants
import
(
MODEL_NAME_ACCOUNT
,
ACTIVITY_TYPE_CREATE
,
ACTIVITY_TYPE_EDIT
,
ACTIVITY_TYPE_DELETE
,
)
from
apps.logs.models
import
Log
class
AccountViewSet
(
viewsets
.
ViewSet
):
...
...
@@ -37,12 +37,14 @@ class AccountViewSet(viewsets.ViewSet):
filtered_set
=
AccountFilter
(
request
.
GET
,
queryset
=
self
.
queryset
).
qs
context
=
paginator
.
paginate_queryset
(
filtered_set
,
request
)
serializer
=
AccountSerializer
(
context
,
many
=
True
)
return
paginator
.
get_paginated_response
(
serializer
.
data
)
def
retrieve
(
self
,
request
,
pk
=
None
):
instance
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
self
.
check_object_permissions
(
request
,
instance
)
serializer
=
AccountSerializer
(
instance
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
def
create
(
self
,
request
):
...
...
@@ -53,7 +55,6 @@ class AccountViewSet(viewsets.ViewSet):
password
=
serializer
.
validated_data
.
pop
(
"password"
)
user
=
User
.
objects
.
create_user
(
username
=
username
,
password
=
password
)
account
=
Account
.
objects
.
create
(
user
=
user
,
**
serializer
.
validated_data
)
# Add account creation log
...
...
@@ -97,8 +98,8 @@ class AccountViewSet(viewsets.ViewSet):
action_type
=
ACTIVITY_TYPE_DELETE
,
author
=
request
.
user
.
account
,
)
serializer
=
AccountSerializer
(
instance
=
instance
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
@
action
(
detail
=
False
,
methods
=
[
"get"
],
url_path
=
"me"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment