Fakultas Ilmu Komputer UI

Commit 208c3737 authored by Usman Sidiq's avatar Usman Sidiq
Browse files

[GREEN] Done implementing email verification

parent c0ae075c
Pipeline #45277 passed with stages
in 39 minutes and 53 seconds
......@@ -81,12 +81,15 @@ class UserTests(APITestCase):
self.assertEqual(json_response['response'], 'User is already exist')
def test_invalid_request(self):
url = reverse('create-user')
response = self.client.get(url)
url = reverse('user-list')
data = {'name': 'Astraykai',
'email':'astraykai@gmail.com',
'phone_number':'089892218567',
'password':'chingchenghanji',
'is_active': True}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
json_response = json.loads(response.content)
print(json_response)
self.assertEqual(json_response['response'], 'get post request instead')
def test_account_login(self):
pass
......
from http import HTTPStatus
from django.contrib.auth.models import User
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
......@@ -44,9 +43,9 @@ def user_list(request):
"name": user.user.last_name,
"email": user.user.email,
"phone_number": user.phone_number})
return JsonResponse(json_return, safe=False, status=HTTPStatus.OK)
return JsonResponse(json_return, safe=False, status=status.OK)
else:
return JsonResponse({'response' : request_error_message("get")}, status=HTTPStatus.METHOD_NOT_ALLOWED)
return JsonResponse({'response' : request_error_message("get")}, status=status.METHOD_NOT_ALLOWED)
@api_view(['GET'])
@authentication_classes([])
......@@ -59,7 +58,7 @@ def user_details(request, email):
"name": user.last_name,
"email": user.email,
"phone_number": bisa_go_user.phone_number}
return JsonResponse(json_return, safe=False, status=HTTPStatus.OK)
return JsonResponse(json_return, safe=False, status=status.OK)
@api_view(['POST'])
......@@ -85,13 +84,13 @@ def register_user(request):
mail = EmailMessage(mail_subject, message, to=[email])
mail.send()
BisaGoUser.objects.create(user= user, phone_number=phone_number)
return JsonResponse({'response' : 'User created', 'email':email, 'name':name}, status = 201)
return JsonResponse({'response' : 'User created', 'email':email, 'name':name}, status = status.CREATED)
except KeyError as e:
return JsonResponse({'response':missing_key_message(str(e))}, status = 500)
return JsonResponse({'response' : missing_key_message(str(e))}, status = status.INTERNAL_SERVER_ERROR)
except IntegrityError as e:
return JsonResponse({'response':'User is already exist'}, status = 500)
return JsonResponse({'response' : 'User is already exist'}, status = status.INTERNAL_SERVER_ERROR)
except MethodNotAllowed :
return JsonResponse({'response' : request_error_message("post")}, status=status.METHOD_NOT_ALLOWED)
@api_view(['GET'])
@authentication_classes([])
......@@ -113,4 +112,4 @@ def activate(request, uidb64, token):
else:
return JsonResponse({'response' : request_error_message('get')}, status = status.BAD_REQUEST)
else :
return JsonResponse({'response' : request_error_message("get")}, status = 400)
return JsonResponse({'response' : request_error_message("get")}, status = BAD_REQUEST)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment