Fakultas Ilmu Komputer UI

Commit 5d213b71 authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Merge branch 'PBI-7-Checkout' into 'staging'

Pbi 7 checkout

See merge request !34
parents a4708230 3585b03e
Pipeline #71069 passed with stages
in 7 minutes and 43 seconds
......@@ -11,7 +11,7 @@ pylint:
- pip install -r requirements.txt
when: on_success
script:
- pylint --load-plugins pylint_django --rcfile=./.pylintrc dietela_backend dietela_program dietela_quiz nutritionists authentication
- pylint --load-plugins pylint_django --rcfile=./.pylintrc dietela_backend dietela_program dietela_quiz nutritionists authentication payment
UnitTest:
image: python:3.6.5
......@@ -29,7 +29,7 @@ UnitTest:
- coverage erase
- SSLCONF="?sslmode=require"
- echo "$TEST_DATABASE_URL$SSLCONF"
- DATABASE_URL="$TEST_DATABASE_URL$SSLCONF" coverage run --branch --source=dietela_quiz,nutritionists,dietela_program,authentication manage.py test --keepdb
- DATABASE_URL="$TEST_DATABASE_URL$SSLCONF" coverage run --branch --source=dietela_quiz,nutritionists,dietela_program,authentication,payment manage.py test --keepdb
- coverage xml -i
- coverage report -m
artifacts:
......
......@@ -11,3 +11,4 @@ max-parents=15
max-locals=30
max-returns=10
ignore-imports=yes
ignore-patterns=test.*?py
......@@ -56,6 +56,7 @@ INSTALLED_APPS = [
'dietela_quiz',
'dietela_program',
'authentication',
'payment',
# auth
'rest_framework.authtoken',
......
......@@ -6,5 +6,6 @@ urlpatterns = [
path('', include('nutritionists.urls')),
path('', include('dietela_quiz.urls')),
path('', include('dietela_program.urls')),
path('', include('payment.urls')),
path('', include('authentication.urls')),
]
from django.contrib import admin
from .models import Cart
admin.site.register(Cart)
from django.apps import AppConfig
class PaymentConfig(AppConfig):
name = 'payment'
# Generated by Django 3.1 on 2021-04-16 09:44
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dietela_program', '0001_initial'),
('nutritionists', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Cart',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('nutritionist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='nutritionists.nutritionist')),
('program', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dietela_program.dietelaprogram')),
],
),
]
from django.db import models
from authentication.models import CustomUser
from dietela_program.models import DietelaProgram
from nutritionists.models import Nutritionist
class Cart(models.Model):
client = models.ForeignKey(
CustomUser,
on_delete=models.CASCADE
)
program = models.ForeignKey(
DietelaProgram,
on_delete=models.CASCADE
)
nutritionist = models.ForeignKey(
Nutritionist,
on_delete=models.CASCADE
)
def __str__(self):
return f"{self.client} - {self.program.unique_code} - {self.nutritionist}"
from rest_framework import serializers
from dietela_program.serializers import DietelaProgramSerializer
from nutritionists.serializers import NutritionistSerializer
from authentication.serializers import CustomUserDetailsSerializer
from .models import Cart
class CartSerializer(serializers.ModelSerializer):
client = CustomUserDetailsSerializer()
program = DietelaProgramSerializer()
nutritionist = NutritionistSerializer()
class Meta:
model = Cart
fields = "__all__"
from rest_framework.test import APITestCase
from rest_framework import status
from .models import Cart
from .serializers import CartSerializer
from authentication.models import CustomUser
from dietela_quiz.models import *
from dietela_program.models import DietelaProgram
from nutritionists.models import Nutritionist
class CartTests(APITestCase):
@classmethod
def setUpTestData(cls):
cls.BASE_URL = "/payment/cart/"
cls.diet_profile_1 = DietProfile.objects.create(
name="test",
email="test@test.com",
age=22,
weight=70,
height=173,
gender=1,
special_condition=2,
body_activity=2,
vegetables_in_one_day=2,
fruits_in_one_day=2,
fried_food_in_one_day=2,
sweet_snacks_in_one_day=2,
sweet_drinks_in_one_day=2,
packaged_food_in_one_day=2,
large_meal_in_one_day=2,
snacks_in_one_day=2,
breakfast_type=2,
current_condition=2,
problem_to_solve=2,
health_problem=[1])
cls.user_1 = CustomUser.objects.create_user(
email='test@test.com',
password='tes',
diet_profile=cls.diet_profile_1,
)
cls.dietela_program_1 = DietelaProgram.objects.create(
unique_code="PRG1",
name="Program 1",
price=350000.00,
)
cls.dietela_program_2 = DietelaProgram.objects.create(
unique_code="PRG2",
name="Program 2",
price=300000.00,
)
cls.nutritionist_1 = Nutritionist.objects.create(
full_name_and_degree="Test, S.Gz",
registration_certificate_no="1234567890",
university="Universitas Indonesia",
mastered_nutritional_problems="Manajemen berat badan, hipertensi",
handled_age_group="12-17 tahun (Remaja)",
another_practice_place="RSCM",
languages="Bahasa Indonesia, Bahasa Inggris",
)
cls.cart_1 = Cart.objects.create(
client = cls.user_1,
program = cls.dietela_program_1,
nutritionist = cls.nutritionist_1,
)
cls.cart_2 = Cart.objects.create(
client = cls.user_1,
program = cls.dietela_program_2,
nutritionist = cls.nutritionist_1,
)
def test_get_all_carts(self):
response = self.client.get(self.BASE_URL)
cart = Cart.objects.all()
serializer = CartSerializer(cart, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_valid_single_cart(self):
url = f"{self.BASE_URL}{self.cart_1.pk}/"
response = self.client.get(url)
cart = Cart.objects.get(
pk=self.cart_1.pk)
serializer = CartSerializer(cart)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_invalid_single_cart(self):
url = f"{self.BASE_URL}1303/"
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_cart_string(self):
self.assertEqual(str(self.cart_1), 'test@test.com - PRG1 - Test, S.Gz')
from rest_framework import routers
from .views import CartViewSet
router = routers.SimpleRouter()
router.register('payment/cart', CartViewSet)
urlpatterns = []
urlpatterns += router.urls
from rest_framework import viewsets
from .serializers import CartSerializer
from .models import Cart
class CartViewSet(viewsets.ModelViewSet):
serializer_class = CartSerializer
queryset = Cart.objects.all()
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