Fakultas Ilmu Komputer UI

Commit 4be501ca authored by Ami's avatar Ami
Browse files

Merge branch 'staging' of...

Merge branch 'staging' of https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/DD/pt-gizi-sehat-dietela/dietela-backend into sorting-client-and-adding-search
parents e00addf7 45b294be
......@@ -189,6 +189,21 @@ web: gunicorn dietela_backend.wsgi --log-file -
Clients can perform payment using a third party payment gateway (Midtrans)
- PBI 9: Diet Questionnaire
Clients can access advanced questionnaire to continue the process of personalizing their diet
- PBI 10: Profile Dietku Nutritionist
Nutritionists can process the data from the questionnaire filled out by the clients and send it back to related clients
- PBI 11: Profile Dietku Client
Clients can receive information provided by nutritionists on the Profile Dietku page
- PBI 12: Profile Dietku Tim Dietela/Admin
Dietela's team can see the recap of client answers to the questionnaire and export the recap of the data in the form of a CSV file
### Developers
......
......@@ -65,8 +65,16 @@ class DietQuestionnaireTests(APITestCase):
def test_string_representation(self):
self.assertEqual(str(self.diet_questionnaire), 'email@email.com')
def test_create_diet_questionnaire(self):
def test_get_all_diet_questionnaire(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
response = self.client.get(self.BASE_URL)
json_response = json.loads(response.content)
self.assertEqual(len(json_response), 1)
self.assertEqual(json_response[0].get('user'), CustomUserDetailsSerializer(self.custom_user_1).data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_create_diet_questionnaire_succeed(self):
login_data = {
'email': 'email2@email.com',
'password': 'abc',
......@@ -81,19 +89,28 @@ class DietQuestionnaireTests(APITestCase):
json_response = json.loads(response.content)
self.assertEqual(DietQuestionnaire.objects.count(), 2)
self.assertEqual(json_response.get('user'), CustomUserDetailsSerializer(self.custom_user_2).data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_get_all_diet_questionnaire(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
response = self.client.get(self.BASE_URL)
json_response = json.loads(response.content)
self.assertEqual(len(json_response), 1)
self.assertEqual(json_response[0].get('user'), CustomUserDetailsSerializer(self.custom_user_1).data)
def test_create_diet_questionnaire_failed(self):
login_data = {
'email': 'email2@email.com',
'password': 'abc',
'role': 'client'
}
login_response = self.client.post('/auth/user-login/', login_data, format='json')
json_login_response = json.loads(login_response.content)
login_credentials = "Bearer " + json_login_response['access_token']
self.client.credentials(HTTP_AUTHORIZATION=login_credentials)
response = self.client.post(self.BASE_URL, {"date_of_birth":"30-12-1995"}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_get_single_diet_questionnaire_succeed(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
response = self.client.get(f"{self.BASE_URL}{self.diet_questionnaire.id}/")
json_response = json.loads(response.content)
self.assertEqual(json_response.get('user'), CustomUserDetailsSerializer(self.custom_user_1).data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_single_diet_questionnaire_failed(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
......@@ -144,3 +161,12 @@ class DietQuestionnaireTests(APITestCase):
format='json'
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_update_diet_questionnaire_invalid_failed(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
response = self.client.patch(
self.SPECIFIC_URL,
{"date_of_birth":"30-12-1995"},
format='json'
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
......@@ -169,6 +169,8 @@ class CartTests(APITestCase):
response = self.client.get(url, request_params)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.cart_3.transaction_status = 'pending'
self.assertEqual(response.data, CartSerializer(self.cart_3).data)
self.assertEqual(DietQuestionnaire.objects.count(), 1)
self.assertEqual(DietQuestionnaire.objects.last().user, self.cart_3.user)
self.assertEqual(DietRecommendation.objects.count(), 1)
......
......@@ -127,4 +127,4 @@ class MidtransRedirectionViewSet(viewsets.ViewSet):
nutritionist=cart.user.nutritionist
)
return Response(status=status.HTTP_200_OK)
return Response(CartSerializer(cart).data, status=status.HTTP_200_OK)
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