Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
e6a9963a
Commit
e6a9963a
authored
Oct 07, 2020
by
Gregorius Aprisunnea
Browse files
[RED] creating 2 test for removing exif data in image. Adding folder: test_files and utils in app
parent
21095a1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/tests.py
View file @
e6a9963a
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment