Fakultas Ilmu Komputer UI

Commit 408eb9bf authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo Committed by Muzaki Azami
Browse files

[REFACTOR] change health_problem attribute to multi select field and delete...

[REFACTOR] change health_problem attribute to multi select field and delete migrations to resolve migration conflict
parent c677ba1e
......@@ -47,10 +47,6 @@ SonarScanner:
-Dsonar.login=$SONARQUBE_TOKEN
-Dsonar.branch.name=$CI_COMMIT_REF_NAME
-Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
only:
- master
- staging
- development
DeploymentStaging:
image: ruby:2.4
......
......@@ -51,6 +51,7 @@ INSTALLED_APPS = [
'nutritionists',
'dietela_quiz',
'dietela_program',
'multiselectfield',
]
MIDDLEWARE = [
......
# Generated by Django 3.1 on 2021-03-17 08:59
# Generated by Django 3.1 on 2021-03-22 16:06
from django.db import migrations, models
import multiselectfield.db.fields
class Migration(migrations.Migration):
......@@ -20,26 +21,26 @@ class Migration(migrations.Migration):
primary_key=True,
serialize=False,
verbose_name='ID')),
('nama',
('name',
models.CharField(
max_length=100)),
('email',
models.EmailField(
max_length=100)),
('usia',
('age',
models.PositiveIntegerField()),
('berat_badan',
('weight',
models.PositiveIntegerField()),
('tinggi_badan',
('height',
models.PositiveIntegerField()),
('jenis_kelamin',
('gender',
models.IntegerField(
choices=[
(1,
'Laki-laki'),
(2,
'Perempuan')])),
('kondisi_khusus',
('special_condition',
models.IntegerField(
choices=[
(1,
......@@ -54,7 +55,7 @@ class Migration(migrations.Migration):
'Menyusui Bayi 0-6 Bulan'),
(6,
'Menyusui Bayi 7-12 Bulan')])),
('aktif_badan',
('body_activity',
models.IntegerField(
choices=[
(1,
......@@ -67,7 +68,7 @@ class Migration(migrations.Migration):
'Olahraga rutin 45-60 menit per hari'),
(5,
'Olahraga rutin lebih dari 60 menit per hari')])),
('sayur_dimakan_sehari',
('vegetables_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -80,7 +81,7 @@ class Migration(migrations.Migration):
'3 porsi'),
(5,
'Lebih dari 3 porsi')])),
('buah_dimakan_sehari',
('fruits_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -93,7 +94,7 @@ class Migration(migrations.Migration):
'3 porsi'),
(5,
'Lebih dari 3 porsi')])),
('gorengan_dimakan_sehari',
('fried_food_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -106,7 +107,7 @@ class Migration(migrations.Migration):
'3 potong'),
(5,
'Lebih dari 3 potong')])),
('cemilan_manis_dimakan_sehari',
('sweet_snacks_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -119,7 +120,7 @@ class Migration(migrations.Migration):
'3 potong'),
(5,
'Lebih dari 3 potong')])),
('minuman_manis_diminum_sehari',
('sweet_drinks_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -132,7 +133,7 @@ class Migration(migrations.Migration):
'3 gelas'),
(5,
'Lebih dari 3 gelas')])),
('makanan_kemasan_dimakan_sehari',
('packaged_food_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -145,7 +146,7 @@ class Migration(migrations.Migration):
'3 porsi'),
(5,
'Lebih dari 3 porsi')])),
('makanan_besar_dimakan_sehari',
('large_meal_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -156,7 +157,7 @@ class Migration(migrations.Migration):
'3 kali'),
(4,
'Lebih dari 3 kali')])),
('cemilan_dimakan_sehari',
('snacks_in_one_day',
models.IntegerField(
choices=[
(1,
......@@ -169,7 +170,7 @@ class Migration(migrations.Migration):
'3 kali'),
(5,
'Lebih dari 3 kali')])),
('jenis_makanan_pagi',
('breakfast_type',
models.IntegerField(
choices=[
(1,
......@@ -178,7 +179,7 @@ class Migration(migrations.Migration):
'Makanan yang ringan saja'),
(3,
'Makanan yang sampai mengenyangkan perut')])),
('kondisi_saat_ini',
('current_condition',
models.IntegerField(
choices=[
(1,
......@@ -195,7 +196,7 @@ class Migration(migrations.Migration):
'Saya sudah pernah merubah diet dan gaya hidup menjadi lebih sehat tetapi tidak bertahan lama (dilakukan kurang dari 6 bulan)'),
(7,
'Saya sudah pernah berhasil menjalani diet dan gaya hidup sehat selama lebih dari 6 bulan dan ingin melakukannya lagi')])),
('masalah_ingin_diselesaikan',
('problem_to_solve',
models.IntegerField(
choices=[
(1,
......@@ -218,8 +219,8 @@ class Migration(migrations.Migration):
'Transisi vegan'),
(10,
' Butuh pengaturan gizi pada anak-anak atau remaja')])),
('masalah_kesehatan_dimiliki',
models.IntegerField(
('health_problem',
multiselectfield.db.fields.MultiSelectField(
choices=[
(1,
'Tidak ada yang perlu dikhawatirkan'),
......@@ -246,7 +247,8 @@ class Migration(migrations.Migration):
(12,
'Penyintas Kanker'),
(13,
'Penyakit Kronis Lainnya')])),
'Penyakit Kronis Lainnya')],
max_length=29)),
],
),
]
# Generated by Django 3.1 on 2021-03-19 01:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dietela_quiz', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='dietprofile',
old_name='usia',
new_name='age',
),
migrations.RenameField(
model_name='dietprofile',
old_name='aktif_badan',
new_name='body_activity',
),
migrations.RenameField(
model_name='dietprofile',
old_name='jenis_makanan_pagi',
new_name='breakfast_type',
),
migrations.RenameField(
model_name='dietprofile',
old_name='kondisi_saat_ini',
new_name='current_condition',
),
migrations.RenameField(
model_name='dietprofile',
old_name='gorengan_dimakan_sehari',
new_name='fried_food_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='buah_dimakan_sehari',
new_name='fruits_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='jenis_kelamin',
new_name='gender',
),
migrations.RenameField(
model_name='dietprofile',
old_name='masalah_kesehatan_dimiliki',
new_name='health_problem',
),
migrations.RenameField(
model_name='dietprofile',
old_name='tinggi_badan',
new_name='height',
),
migrations.RenameField(
model_name='dietprofile',
old_name='makanan_besar_dimakan_sehari',
new_name='large_meal_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='nama',
new_name='name',
),
migrations.RenameField(
model_name='dietprofile',
old_name='makanan_kemasan_dimakan_sehari',
new_name='packaged_food_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='masalah_ingin_diselesaikan',
new_name='problem_to_solve',
),
migrations.RenameField(
model_name='dietprofile',
old_name='cemilan_dimakan_sehari',
new_name='snacks_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='kondisi_khusus',
new_name='special_condition',
),
migrations.RenameField(
model_name='dietprofile',
old_name='minuman_manis_diminum_sehari',
new_name='sweet_drinks_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='cemilan_manis_dimakan_sehari',
new_name='sweet_snacks_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='sayur_dimakan_sehari',
new_name='vegetables_in_one_day',
),
migrations.RenameField(
model_name='dietprofile',
old_name='berat_badan',
new_name='weight',
),
]
from django.db import models
from constants.model_choices import DietProfileChoices
from multiselectfield import MultiSelectField
class DietProfile(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(max_length=100)
age = models.PositiveIntegerField()
......@@ -36,5 +36,5 @@ class DietProfile(models.Model):
choices=DietProfileChoices.CHOICES_CURRENT_CONDITION)
problem_to_solve = models.IntegerField(
choices=DietProfileChoices.CHOICES_PROBLEM_TO_SOLVE)
health_problem = models.IntegerField(
health_problem = MultiSelectField(
choices=DietProfileChoices.CHOICES_HEALTH_PROBLEM)
from rest_framework import serializers
from rest_framework import fields, serializers
from constants.model_choices import DietProfileChoices
from .models import DietProfile
class DietProfileSerializer(serializers.ModelSerializer):
health_problem = fields.MultipleChoiceField(
choices=DietProfileChoices.CHOICES_HEALTH_PROBLEM)
class Meta:
model = DietProfile
......
import json
from rest_framework.test import APITestCase
from rest_framework import status
from .models import DietProfile
from django.test import TestCase
from constants.quiz_constants import *
from constants.model_choices import DietProfileChoices
from .formulas import (
body_mass_index,
nutrition_status,
......@@ -40,7 +42,7 @@ class DietelaQuizTests(APITestCase):
breakfast_type=1,
current_condition=1,
problem_to_solve=1,
health_problem=1)
health_problem=[2, 3])
def test_diet_profile_saved(self):
self.assertEqual(DietProfile.objects.count(), 1)
......@@ -48,6 +50,7 @@ class DietelaQuizTests(APITestCase):
def test_get_diet_profile_api(self):
response = self.client.get('/dietela-quiz/diet-profile/')
self.assertEqual(json.loads(response.content)[0].get('name'), 'test')
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_post_diet_profile_api(self):
data = {
......@@ -70,12 +73,34 @@ class DietelaQuizTests(APITestCase):
'breakfast_type': 1,
'current_condition': 1,
'problem_to_solve': 1,
'health_problem': 1
'health_problem': [2, 3]
}
response = self.client.post(
'/dietela-quiz/diet-profile/', data, format='json')
self.assertEqual(json.loads(response.content).get('name'), 'test2')
self.assertEqual(DietProfile.objects.count(), 2)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_incomplete_post_diet_profile_api(self):
'''
Post without food or drink portion in a day,
and without beakfast type, current condition,
problem to solve, and health problem fields
'''
data = {
'name': 'test2',
'email': 'test2@test.com',
'age': 20,
'weight': 60,
'height': 172,
'gender': 2,
'special_condition': 1,
'body_activity': 1
}
response = self.client.post(
'/dietela-quiz/diet-profile/', data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
class FormulaTest(TestCase):
......
......@@ -4,6 +4,7 @@ djangorestframework==3.11.1
django-cors-headers==3.4.0
requests==2.24.0
Pillow==7.1.2
django-multiselectfield==0.1.12
# database
dj-database-url==0.5.0
......
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