Fakultas Ilmu Komputer UI

Commit 728d5227 authored by Muhammad Fairuzi Teguh's avatar Muhammad Fairuzi Teguh
Browse files

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

Pbi 7 edukasi

See merge request !110
parents 18eab632 8d244c97
Pipeline #48887 passed with stages
in 13 minutes and 55 seconds
.data
\ No newline at end of file
......@@ -22,7 +22,7 @@ DRF Unit Tests:
- export DEBUG=True
- pip install -r requirements-dev.txt
script:
- coverage run --include='main/*,stok_darah/*,donor/*,rest_framework_authlib/*,acara_donor/*' manage.py test
- coverage run --include='main/*,stok_darah/*,donor/*,rest_framework_authlib/*,acara_donor/*,edukasi/*' manage.py test
- coverage report --show-missing
- coverage xml
artifacts:
......
......@@ -10,3 +10,4 @@ db.sqlite3
.coverage
coverage.xml
.idea/
media/
\ No newline at end of file
......@@ -47,7 +47,7 @@ PS C:\Users\Giovan\Projects\mantan-aab-d-blood\drf> Set-ExecutionPolicy -Scope C
5. Run unit tests and measure coverage
```
(venv) PS C:\Users\Giovan\Projects\mantan-aab-d-blood\drf> coverage run --include='main/*,stok_darah/*,donor/*,rest_framework_authlib/*' manage.py test
(venv) PS C:\Users\Giovan\Projects\mantan-aab-d-blood\drf> coverage run --include='main/*,stok_darah/*,donor/*,rest_framework_authlib/*,acara_donor/*,edukasi/*' manage.py test
(venv) PS C:\Users\Giovan\Projects\mantan-aab-d-blood\drf> coverage report --show-missing
```
......
......@@ -34,6 +34,7 @@ INSTALLED_APPS = [
'anymail',
'corsheaders',
'donor',
'edukasi',
'acara_donor'
]
......
import os
from .production import *
SECRET_KEY = os.getenv('SECRET_KEY', '__super_secret_high_entropy_pseudo_random_bytes_a608e1fb__')
......
......@@ -22,6 +22,7 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('donor/', include('donor.urls')),
path('edukasi/', include('edukasi.urls')),
path('acara-donor/', include('acara_donor.urls')),
path('stok-darah/', include('stok_darah.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.contrib import admin
from edukasi.models import Artikel
@admin.register(Artikel)
class ArtikelAdmin(admin.ModelAdmin):
pass
from django.apps import AppConfig
class EdukasiConfig(AppConfig):
name = 'edukasi'
import os
import factory
from faker import Faker
from edukasi.models import Artikel
fake = Faker()
class ArtikelFactory(factory.DjangoModelFactory):
class Meta:
model = Artikel
title = fake.sentence()[:-1]
featured_image = os.path.join("edukasi", "placeholder.jpg")
content = "\n".join(fake.paragraphs())
import os
import random
from django.core.management import BaseCommand
from faker import Faker
from edukasi.models import Artikel
fake = Faker()
fake.seed_instance(10) # NOSONAR
class Command(BaseCommand):
help = 'Add dummy data artikel edukasi'
def handle(self, *args, **options):
for i in range(20):
content = []
for i in range(5):
content.append(" ".join(fake.paragraphs()))
Artikel.objects.create(
title=fake.sentence()[:-1],
featured_image=os.path.join("edukasi", random.choice([ # NOSONAR
"placeholder1.jpg", "placeholder2.jpg", "placeholder3.jpg"])),
content="\n".join(content)
)
self.stdout.write(self.style.SUCCESS("Successfully add dummy data artikel edukasi"))
# Generated by Django 3.0.5 on 2020-05-04 05:45
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Artikel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=32)),
('featured_image', models.ImageField(upload_to='')),
('content', models.TextField()),
],
),
]
# Generated by Django 3.0.5 on 2020-05-04 05:56
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('edukasi', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='artikel',
name='posted_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]
from django.db import models
class Artikel(models.Model):
title = models.CharField(max_length=32)
featured_image = models.ImageField()
content = models.TextField()
posted_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Artikel " + self.title
class Meta:
pass
from rest_framework import serializers
from .models import Artikel
class ArtikelSerializer(serializers.ModelSerializer):
class Meta:
model = Artikel
fields = ['id', 'title', 'featured_image', 'content']
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APITestCase
from .factories import ArtikelFactory
class ArtikelTests(TestCase):
def test_create(self):
article = ArtikelFactory(title="Sepuluh Manfaat Donor Darah")
self.assertEqual(str(article), "Artikel Sepuluh Manfaat Donor Darah")
class ArtikelViewTests(APITestCase):
def setUp(self):
self.article = ArtikelFactory(title="Sepuluh Manfaat Donor Darah")
def test_get_artikel_sorted_by_posted_at(self):
new_article = ArtikelFactory()
response = self.client.get('/edukasi/artikel/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['results'][0]['title'], new_article.title)
self.assertEqual(response.data['results'][1]['title'], self.article.title)
def test_retrieve_artikel(self):
response = self.client.get('/edukasi/artikel/' + str(self.article.id) + '/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['title'], self.article.title)
self.assertEqual(response.data['content'], self.article.content)
from rest_framework.routers import DefaultRouter
from edukasi.views import ArtikelViewSet
router = DefaultRouter()
router.register(r'artikel', ArtikelViewSet, basename='artikel')
urlpatterns = router.urls
from rest_framework import viewsets
from .serializers import ArtikelSerializer
from .models import Artikel
from main.paginations import SmallResultsSetPagination
class ArtikelViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = ArtikelSerializer
pagination_class = SmallResultsSetPagination
queryset = Artikel.objects.all().order_by('-posted_at')
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