Fakultas Ilmu Komputer UI

Commit 4a1d0932 authored by rayhan muzakki's avatar rayhan muzakki
Browse files

[GREEN] passed tests for reportprogramdonationCSH and GDS

parents c68f4a5a 5a0e591b
Pipeline #60411 passed with stages
in 6 minutes and 25 seconds
{
"python.pythonPath": "env/bin/python3"
"python.pythonPath": "/usr/bin/python"
}
\ No newline at end of file
# Generated by Django 3.0.7 on 2020-10-26 09:14
import api.utils
import django.contrib.postgres.fields.citext
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ProgramProgress',
fields=[
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(verbose_name='date')),
('description', django.contrib.postgres.fields.citext.CICharField(max_length=200, verbose_name='description')),
('image', models.ImageField(blank=True, null=True, upload_to=api.utils.get_upload_file_path, verbose_name='image')),
('program', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='program', to='api.Program', verbose_name='program')),
],
options={
'verbose_name': 'program progress',
'verbose_name_plural': 'program progress',
'ordering': ['-date', 'id'],
},
),
]
......@@ -646,3 +646,31 @@ class Batch(db_models.Model):
def __str__(self):
return self.batch_name
class ProgramProgress(db_models.Model):
id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID'))
date = db_models.DateField(
blank=False,
verbose_name=_('date')
)
description = fields.CICharField(max_length=200, verbose_name=_('description'))
image = db_models.ImageField(
blank=True,
null=True,
upload_to=utils.get_upload_file_path,
verbose_name=_('image')
)
program = db_models.ForeignKey(
'api.Program',
on_delete=db_models.CASCADE,
related_name='program',
verbose_name=_('program')
)
class Meta:
ordering = ['-date', 'id']
verbose_name = _('program progress')
verbose_name_plural = _('program progress')
def __str__(self):
return self.name
\ No newline at end of file
......@@ -323,7 +323,7 @@ def create_program_donation_report_CSH(filter_params):
}
)
money_format = workbook.add_format({'num_format': '#,##0'})
program_donation_worksheet = workbook.add_worksheet(str(_('Program Donations')))
program_donation_worksheet = workbook.add_worksheet(str(_('Program Donations of CSH')))
program_donation_fields = [
(donation_donation_number_with_hyperlink, _('Donation Number')),
(transaction_or_donation_user_username_with_hyperlink, _('User Username')),
......
......@@ -57,6 +57,11 @@ PROGRAM_DATA = {
'link': 'https://example.com',
}
PROGRAM_PROGRESS_DATA = {
'date': '2020-10-26',
'description': 'Progress update 1'
}
PROGRAM_DONATION_CASH_DATA = {
'amount': '1000',
'user_bank_name': 'Dummy Bank Name',
......@@ -77,6 +82,7 @@ PROGRAM_DONATION_GOODS_DATA_DLV = {
'delivery_method': 'DLV',
}
HELP_CONTACT_CONFIG_DATA = {
'email': 'dummy@example.com',
}
......
......@@ -69,7 +69,10 @@ class DonationCreateSerializer(serializers.Serializer): # pylint: disable=abstra
min_value=decimal.Decimal('0.01'),
required=False
)
proof_of_bank_transfer = serializers.ImageField(label=_('Proof of bank transfer'))
proof_of_bank_transfer = serializers.ImageField(
label=_('Proof of bank transfer'),
required=False
)
user_bank_name = serializers.CharField(
label=_('User bank name'),
max_length=100,
......@@ -119,7 +122,7 @@ class DonationReuploadProofOfBankTransferSerializer(serializers.Serializer): # p
proof_of_bank_transfer = serializers.ImageField(label=_('Proof of bank transfer'))
user_bank_name = serializers.CharField(
label=_('User bank name'),
max_length=100
max_length=100,
)
user_bank_account_name = serializers.CharField(
label=_('User bank account name'),
......@@ -470,6 +473,31 @@ class ProgramSerializer(serializers.ModelSerializer):
return super().validate(attrs)
class ProgramProgressSerializer(serializers.ModelSerializer):
class Meta:
fields = [
'id',
'program',
'date',
'description',
'image',
]
model = models.ProgramProgress
read_only_fields = [
'id',
'program'
]
def validate(self, attrs):
instance = self.instance
date = attrs.get('date', getattr(instance, 'date', None))
errors = {}
if errors:
raise serializers.ValidationError(errors)
return super().validate(attrs)
class ProgramDonationSerializer(serializers.ModelSerializer):
program_code = serializers.ReadOnlyField(source='program.code')
user_username = serializers.ReadOnlyField(source='user.username')
......
......@@ -1966,3 +1966,44 @@ class BatchTest(rest_framework_test.APITestCase):
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(models.Batch.objects.get(id=batch.id).shipping_cost, 60000)
class ProgramProgressTest(rest_framework_test.APITestCase):
def setUp(self):
self.superuser = models.User.objects.create_superuser(**seeds.SUPERUSER_DATA)
self.superuser_http_authorization = get_http_authorization(
seeds.SUPERUSER_DATA['username'],
seeds.SUPERUSER_DATA['password']
)
self.program = models.Program.objects.create(**seeds.PROGRAM_DATA)
def test_program_progress_list_success(self):
response = request(
'GET',
'program-progress-list',
http_authorization=self.superuser_http_authorization,
url_args=[self.program.id]
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_create_program_progress_success(self):
data = seeds.PROGRAM_PROGRESS_DATA
response = request(
'POST',
'program-progress-list',
data,
http_authorization=self.superuser_http_authorization,
url_args=[self.program.id]
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(models.ProgramProgress.objects.count(), 1)
self.assertEqual(models.ProgramProgress.objects.get(id=response.data['id']).description, data['description'])
def test_create_program_progress_fail(self):
response = request(
'POST',
'program-progress-list',
http_authorization=self.superuser_http_authorization,
url_args=[self.program.id]
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(models.ProgramProgress.objects.count(), 0)
......@@ -87,6 +87,7 @@ urlpatterns = [
),
urls.path('programs/', api_views.ProgramList.as_view(), name='program-list'),
urls.path('programs/<str:pk>/', api_views.ProgramDetail.as_view(), name='program-detail'),
urls.path('programs/<str:program>/progress', api_views.ProgramProgressList.as_view(), name='program-progress-list'),
urls.path(
'program-donations/csh',
api_views.ProgramDonationListCSH.as_view(),
......
......@@ -624,6 +624,29 @@ class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
]
queryset = models.Product.objects.all()
serializer_class = api_serializers.ProductSerializer
class ProgramProgressList(generics.ListCreateAPIView):
permission_classes = [
api_permissions.IsAdminUserOrReadOnly,
rest_framework_permissions.IsAuthenticated,
]
lookup_field = 'program'
serializer_class = api_serializers.ProgramProgressSerializer
def get_queryset(self):
return models.ProgramProgress.objects.filter(program=self.get_program())
def perform_create(self, serializer):
serializer.save(program=self.get_program())
def get_program(self):
program = models.Program.objects.filter(id=self.kwargs.get(self.lookup_field)).first()
if program is None:
raise rest_framework_exceptions.NotFound(_(
'Program not found.'
))
return program
class ShoppingCartList(generics.ListAPIView):
......
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