Fakultas Ilmu Komputer UI

Commit 4e11f0a2 authored by Moh Faisal's avatar Moh Faisal
Browse files

Merge branch '1706039502-79' into 'master'

1706039502 79

See merge request !107
parents 87716fc7 dac8ebcc
Pipeline #60167 passed with stages
in 23 minutes and 6 seconds
import mock
import pandas as pd
import base64
import datetime as dt
import json
......@@ -9,7 +11,7 @@ import time
import itertools
from django.test import override_settings
from datetime import datetime
from io import StringIO
from io import StringIO, BytesIO
from time import sleep
import mock
......@@ -25,8 +27,8 @@ from django.contrib import messages as dj_messages
from django.contrib.auth import get_user_model
from django.core import mail, serializers
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile, InMemoryUploadedFile
from django.core.files import File
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management import call_command
from django.db.utils import IntegrityError
from pytz import timezone, UTC
......@@ -1326,7 +1328,6 @@ class UploadPageTest(TestCase):
# Negative tests
self.assertNotContains(response, "anything")
class UploadExcelPageTest(TestCase):
def setUp(self):
self.client = Client()
......@@ -3153,9 +3154,6 @@ class YTUrlVideoTest(TestCase):
@override_settings(MEDIA_ROOT=tempfile.gettempdir())
def setUpImage(self):
from io import BytesIO
from django.core.files.uploadedfile import InMemoryUploadedFile
self.cover = InMemoryUploadedFile(
BytesIO(base64.b64decode(TEST_IMAGE)),
field_name='tempfile',
......@@ -3948,3 +3946,43 @@ class MateriStatsTest(TestCase):
response = self.client.get(self.path_json)
jobj = json.loads(response.content)
self.assertEqual(len(jobj['labels']), 6)
class UploadMateriTest(TestCase):
def setUp(self):
self.client = Client()
self.user = User.objects._create_user(email="kontributor@gov.id",
password="kontributor", is_contributor=True)
self.setUpImage()
self.content = SimpleUploadedFile("ExampleFile221.pdf", b"Test file")
self.category = Category.objects.create(id="1", name="sains", description="kategori sains")
@override_settings(MEDIA_ROOT=tempfile.gettempdir())
def setUpImage(self):
self.cover = InMemoryUploadedFile(
BytesIO(base64.b64decode(TEST_IMAGE)),
field_name='tempfile',
name='tempfile.png',
content_type='image/png',
size=len(TEST_IMAGE),
charset='utf-8',
)
def test_for_invalid_input_shows_validation_error(self):
self.client.login(email="kontributor@gov.id",
password="kontributor")
response = self.client.post("/unggah/", data={"title": ""})
self.assertContains(response, "This field is required.")
def test_data_form_upload_materi_success_save_to_db(self):
self.client.login(email="kontributor@gov.id",
password="kontributor")
data = {"title":"Dunia Binatang", "author":"Parzival", "publisher":"Buku Asyik",
"release_year":"2015", "descriptions":"Buku dunia binatang seri 1",
'categories':"1", "cover":self.cover, "content":self.content}
self.client.post("/unggah/", data=data)
self.assertEqual(Materi.objects.count(), 1)
\ No newline at end of file
Markdown is supported
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