Fakultas Ilmu Komputer UI

tests.py 1.79 KB
Newer Older
1
2
import json
from rest_framework.test import APITestCase
3
4
5
from .models import DietProfile

# Create your tests here.
6
class dietela_quizTests(APITestCase):
7
8
    
    def setUp(self):
9
        self.dietProfile = DietProfile.objects.create(
10
11
12
13
14
15
16
            name="test", email="test@test.com", age=20,
            weight=60, height=172, gender=2,
            special_condition=1, body_activity=1, vegetables_in_one_day=1,
            fruits_in_one_day=1, fried_food_in_one_day=1, sweet_snacks_in_one_day=1,
            sweet_drinks_in_one_day=1, packaged_food_in_one_day=1, large_meal_in_one_day=1,
            snacks_in_one_day=1, breakfast_type=1, current_condition=1,
            problem_to_solve=1, health_problem=1
17
        )
18
19

    def test_diet_profile_saved(self):
20
        self.assertEqual(DietProfile.objects.count(), 1)
21
22
23

    def test_get_diet_profile_api(self):
        response = self.client.get('/dietela-quiz/diet-profile/')
24
        self.assertEqual(json.loads(response.content)[0].get("name"), "test")
25
26
27

    def test_post_diet_profile_api(self):
        data = {
28
29
30
31
32
33
34
            "name": "test2", "email": "test2@test.com", "age": 20,
            "weight": 60, "height": 172, "gender": 2,
            "special_condition": 1, "body_activity": 1, "vegetables_in_one_day": 1,
            "fruits_in_one_day": 1, "fried_food_in_one_day": 1, "sweet_snacks_in_one_day": 1,
            "sweet_drinks_in_one_day": 1, "packaged_food_in_one_day": 1, "large_meal_in_one_day": 1,
            "snacks_in_one_day": 1, "breakfast_type": 1, "current_condition": 1,
            "problem_to_solve": 1, "health_problem": 1
35
36
        }
        response = self.client.post('/dietela-quiz/diet-profile/', data, format="json")
37
        self.assertEqual(json.loads(response.content).get("name"), "test2")
38
39
        self.assertEqual(DietProfile.objects.count(), 2)