Fakultas Ilmu Komputer UI

Commit e6a9963a authored by Gregorius Aprisunnea's avatar Gregorius Aprisunnea
Browse files

[RED] creating 2 test for removing exif data in image. Adding folder: test_files and utils in app

parent 21095a1c
import json
import json, tempfile, os
from io import StringIO
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
......@@ -19,6 +20,7 @@ from .views import (DaftarKatalog, DashboardKontributorView, DetailMateri,
SuksesLoginKontributorView, SuntingProfilView,
ProfilAdminView, PostsView, SuntingProfilAdminView, RevisiMateriView)
from app.forms import SuntingProfilForm
from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata
class DaftarKatalogTest(TestCase):
......@@ -1128,3 +1130,31 @@ class RatingMateriTest(TestCase):
def test_score_in_rating_should_not_be_null(self):
with self.assertRaises(TypeError):
Rating(materi=self.materi1, user=self.user_one).save()
class fileManagementUtilTest(TestCase):
def setUp(self):
self.filename = "image_with_exif_data.gif"
self.file_content = open(settings.BASE_DIR + "/app/test_files/" +
self.filename, "rb").read()
def test_get_random_filename_isCorrect(self):
generated_name = get_random_filename(self.filename)
self.assertTrue(generated_name != self.filename)
# 40 from 36 expected name length + 4 from extension
self.assertEqual(len(generated_name), 40)
self.assertTrue(generated_name[-4:] == ".gif")
def test_remove_image_exifdata_isCorrect(self):
with tempfile.TemporaryDirectory() as d:
image_with_exif_data_path = os.path.join(d, self.filename)
img = open(image_with_exif_data_path, "wb")
img.write(self.file_content)
img.close()
remove_image_exifdata(image_with_exif_data_path)
sanitized_img = open(image_with_exif_data_path, "rb").read()
self.assertTrue(len(sanitized_img) < len(self.file_content))
self.assertTrue(b'<exif:' not in sanitized_img)
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