Fakultas Ilmu Komputer UI

Commit 89ababa5 authored by Kefas Satrio Bangkit Solideantyo's avatar Kefas Satrio Bangkit Solideantyo
Browse files

[RED] add tests for get/post api of diet profile

parent 70bb76cc
Pipeline #64217 failed with stage
in 15 minutes and 5 seconds
from django.test import TestCase, Client
import json
from rest_framework.test import APITestCase
from .models import DietProfile
# Create your tests here.
class DietelaQuiz(TestCase):
class DietelaQuizTests(APITestCase):
def setUp(self):
self.c = Client()
def test_diet_profile_saved(self):
DietProfile.objects.create(
self.dietProfile = DietProfile.objects.create(
nama="test", email="test@test.com", usia=20,
berat_badan=60, tinggi_badan=172, jenis_kelamin=2,
kondisi_khusus=1, aktif_badan=1, sayur_dimakan_sehari=1,
......@@ -17,4 +15,25 @@ class DietelaQuiz(TestCase):
cemilan_dimakan_sehari=1, jenis_makanan_pagi=1, kondisi_saat_ini=1,
masalah_ingin_diselesaikan=1, masalah_kesehatan_dimiliki=1
)
def test_diet_profile_saved(self):
self.assertEqual(DietProfile.objects.count(), 1)
def test_get_diet_profile_api(self):
response = self.client.get('/dietela-quiz/diet-profile/')
self.assertEqual(json.loads(response.content)[0].get("nama"), "test")
def test_post_diet_profile_api(self):
data = {
"nama": "test2", "email": "test2@test.com", "usia": 20,
"berat_badan": 60, "tinggi_badan": 172, "jenis_kelamin": 2,
"kondisi_khusus": 1, "aktif_badan": 1, "sayur_dimakan_sehari": 1,
"buah_dimakan_sehari": 1, "gorengan_dimakan_sehari": 1, "cemilan_manis_dimakan_sehari": 1,
"minuman_manis_diminum_sehari": 1, "makanan_kemasan_dimakan_sehari": 1, "makanan_besar_dimakan_sehari": 1,
"cemilan_dimakan_sehari": 1, "jenis_makanan_pagi": 1, "kondisi_saat_ini": 1,
"masalah_ingin_diselesaikan": 1, "masalah_kesehatan_dimiliki": 1
}
response = self.client.post('/dietela-quiz/diet-profile/', data, format="json")
self.assertEqual(json.loads(response.content).get("nama"), "test2")
self.assertEqual(DietProfile.objects.count(), 2)
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