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
e527bfeb
Commit
e527bfeb
authored
Oct 31, 2020
by
Arief Pratama
Browse files
[HOTFIX] Fix Code smell and timezone-aware datetime
parent
c320f26c
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
app/services.py
View file @
e527bfeb
...
...
@@ -4,21 +4,24 @@ import random
import
shutil
from
functools
import
cmp_to_key
import
requests
from
administration.models
import
VerificationReport
from
digipus
import
settings
from
django.contrib
import
messages
from
django.contrib.auth.models
import
AnonymousUser
from
django.core.exceptions
import
ValidationError
from
django.db.models
import
Case
,
When
,
Count
,
Q
from
django.db.models
import
Case
,
Count
,
Q
,
When
from
django.shortcuts
import
get_object_or_404
from
django.utils
import
timezone
from
pydrive.auth
import
GoogleAuth
from
pydrive.drive
import
GoogleDrive
from
administration.models
import
VerificationReport
from
app.forms
import
SuntingProfilForm
from
app.models
import
Category
,
Like
,
Like
Comment
,
DislikeComment
,
Materi
,
Comment
,
Rating
,
DownloadStatistics
,
\
ViewStatistics
,
ReadLater
from
app.utils.fileManagementUtil
import
get_random_filename
,
remove_image_exifdata
from
digipus
import
settings
import
requests
from
app.models
import
(
Category
,
Comment
,
DislikeComment
,
DownloadStatistics
,
Like
,
LikeComment
,
Materi
,
Rating
,
ReadLater
,
ViewStatistics
)
from
app.utils.fileManagementUtil
import
(
get_random_filename
,
remove_image_exifdata
)
class
DafterKatalogService
:
...
...
@@ -160,7 +163,7 @@ class CitationService:
@
staticmethod
def
get_citation_ieee
(
request
,
materi
):
current_date
=
datetime
.
datetim
e
.
now
()
current_date
=
timezon
e
.
now
()
current_day
=
str
(
current_date
.
day
)
current_month
=
current_date
.
strftime
(
"%b"
)
current_year
=
str
(
current_date
.
year
)
...
...
@@ -483,4 +486,4 @@ class ReadLaterService:
else
:
ReadLater
(
materi
=
materi
,
user
=
current_user
).
save
()
response
=
{
"success"
:
True
,
"read_later_checked"
:
True
}
return
response
\ No newline at end of file
return
response
app/tests.py
View file @
e527bfeb
import
json
,
tempfile
,
os
,
mock
,
base64
import
pandas
as
pd
from
io
import
StringIO
import
base64
import
datetime
as
dt
import
json
import
os
import
random
import
re
import
tempfile
import
time
import
random
from
django.test
import
override_settings
from
datetime
import
datetime
from
io
import
StringIO
from
time
import
sleep
import
mock
import
pandas
as
pd
import
pytz
from
administration.models
import
VerificationReport
,
VerificationSetting
from
administration.utils
import
id_generator
from
authentication.models
import
User
from
bs4
import
BeautifulSoup
from
d
atetime
import
datetime
from
d
igipus.settings
import
TIME_ZONE
from
django.conf
import
settings
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.files
import
File
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.files
import
File
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.core.management
import
call_command
from
django.test
import
Client
,
TestCase
,
TransactionTestCase
from
django.urls
import
resolve
,
reverse
from
django.db.utils
import
IntegrityError
from
django.test
import
Client
,
RequestFactory
,
TestCase
,
TransactionTestCase
from
pytz
import
timezone
from
time
import
sleep
import
datetime
as
dt
from
django.test
import
(
Client
,
RequestFactory
,
TestCase
,
TransactionTestCase
,
override_settings
)
from
django.urls
import
resolve
,
reverse
from
django.utils
import
timezone
from
administration.models
import
VerificationSetting
,
VerificationReport
from
administration.utils
import
id_generator
from
app.views
import
UploadMateriHTML
,
add_rating_materi
from
authentication.models
import
User
from
digipus.settings
import
TIME_ZONE
from
.models
import
(
Category
,
Comment
,
Review
,
DislikeComment
,
DownloadStatistics
,
Materi
,
Like
,
LikeComment
,
Rating
,
ReqMaterial
,
RatingContributor
,
ViewStatistics
,
ReadLater
)
from
.services
import
(
DetailMateriService
,
)
from
.views
import
(
DaftarKatalog
,
DashboardKontributorView
,
DetailMateri
,
ProfilView
,
SuntingProfilView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
PostsView
,
RevisiMateriView
,
ReqMateriView
,
KatalogPerKontributorView
,
UploadMateriView
,
UploadMateriExcelView
,
PasswordChangeViews
,
password_success
,
MateriFavorite
,
)
from
app.forms
import
SuntingProfilForm
,
year_choices
from
app.utils.fileManagementUtil
import
get_random_filename
,
remove_image_exifdata
from
app.utils.fileManagementUtil
import
(
get_random_filename
,
remove_image_exifdata
)
from
app.utils.PasswordValidator
import
PasswordPolicyValidator
from
app.views
import
UploadMateriHTML
,
add_rating_materi
from
.models
import
(
Category
,
Comment
,
DislikeComment
,
DownloadStatistics
,
Like
,
LikeComment
,
Materi
,
Rating
,
RatingContributor
,
ReadLater
,
ReqMaterial
,
Review
,
ViewStatistics
)
from
.services
import
DetailMateriService
from
.views
import
(
DaftarKatalog
,
DashboardKontributorView
,
DetailMateri
,
KatalogPerKontributorView
,
MateriFavorite
,
PasswordChangeViews
,
PostsView
,
ProfilView
,
ReqMateriView
,
RevisiMateriView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
SuntingProfilView
,
UploadMateriExcelView
,
UploadMateriView
,
password_success
)
ERROR_403_MESSAGE
=
"Kamu harus login untuk mengakses halaman ini"
from
statistics
import
mean
import
requests
from
django.test
import
LiveServerTestCase
from
selenium
import
webdriver
from
selenium.common.exceptions
import
NoSuchElementException
from
selenium.webdriver.chrome.options
import
Options
from
selenium.webdriver.common.keys
import
Keys
from
webdriver_manager.chrome
import
ChromeDriverManager
from
selenium.common.exceptions
import
NoSuchElementException
import
requests
from
statistics
import
mean
class
DaftarKatalogTest
(
TestCase
):
...
...
@@ -343,7 +321,7 @@ class DetailMateriTest(TestCase):
self
.
materi_with_published_date
=
Materi
.
objects
.
create
(
title
=
"Materi 1"
,
author
=
"Agas"
,
uploader
=
self
.
contributor
,
publisher
=
"Kelas SC"
,
descriptions
=
"Deskripsi Materi 1"
,
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
())
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
())
self
.
materi_with_published_date_url
=
"/materi/"
+
str
(
self
.
materi_with_published_date
.
id
)
+
"/"
VerificationReport
.
objects
.
create
(
report
=
'{"feedback": "Something", "kriteria": [{"title": "Kriteria 1", "status": true},'
+
\
' {"title": "Kriteria 2", "status": true}, {"title": "Kriteria 3", "status": true}]}'
,
\
...
...
@@ -758,7 +736,7 @@ class DetailMateriTest(TestCase):
def
test_citation_IEEE_materi_has_no_published_date
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
current_date
=
datetim
e
.
now
()
current_date
=
timezon
e
.
now
()
current_day
=
str
(
current_date
.
day
)
current_month
=
current_date
.
strftime
(
"%b"
)
current_year
=
str
(
current_date
.
year
)
...
...
@@ -781,7 +759,7 @@ class DetailMateriTest(TestCase):
def
test_citation_IEEE_materi_has_published_date
(
self
):
response
=
self
.
client
.
get
(
self
.
materi_with_published_date_url
)
current_date
=
datetim
e
.
now
()
current_date
=
timezon
e
.
now
()
current_day
=
str
(
current_date
.
day
)
current_month
=
current_date
.
strftime
(
"%b"
)
current_year
=
str
(
current_date
.
year
)
...
...
@@ -983,7 +961,7 @@ class PostsViewTest(TestCase):
for
j
in
range
(
LIKES_COUNT_PER_POST
[
i
]):
Like
.
objects
.
create
(
timestamp
=
datetim
e
.
now
(),
timestamp
=
timezon
e
.
now
(),
materi
=
post
,
session_id
=
(
"dummysession-"
+
str
(
i
)
+
'-'
+
str
(
j
))
)
...
...
@@ -1050,6 +1028,8 @@ class PostsViewTest(TestCase):
response
=
self
.
_request_as_user
()
posts
=
list
(
self
.
data
.
keys
())
posts
.
sort
()
comments
=
{
i
:
[
comment
.
id
for
comment
in
self
.
data
[
post_id
][
"comments"
]]
for
i
,
post_id
in
enumerate
(
posts
)
...
...
@@ -2740,7 +2720,7 @@ class DownloadHistoryViewTest(TestCase):
self
.
client
.
get
(
self
.
download_url2
)
self
.
client
.
get
(
self
.
download_url1
)
jkt_timezone
=
timezone
(
TIME_ZONE
)
jkt_timezone
=
pytz
.
timezone
(
TIME_ZONE
)
download_history
=
self
.
user_anonim
.
riwayat_unduh
.
all
()
response
=
self
.
client
.
get
(
self
.
history_url
)
...
...
@@ -2760,7 +2740,7 @@ class DownloadHistoryViewTest(TestCase):
self
.
client
.
get
(
self
.
download_url2
)
self
.
client
.
get
(
self
.
download_url1
)
jkt_timezone
=
timezone
(
TIME_ZONE
)
jkt_timezone
=
pytz
.
timezone
(
TIME_ZONE
)
response
=
self
.
client
.
get
(
self
.
history_url
)
resp_html
=
response
.
content
.
decode
(
'utf8'
)
...
...
@@ -2780,7 +2760,7 @@ class DownloadHistoryViewTest(TestCase):
self
.
client
.
logout
()
jkt_timezone
=
timezone
(
TIME_ZONE
)
jkt_timezone
=
pytz
.
timezone
(
TIME_ZONE
)
download_history
=
self
.
user_anonim
.
riwayat_unduh
.
all
()
response
=
self
.
client
.
get
(
self
.
history_url
)
...
...
@@ -2856,16 +2836,16 @@ class MateriModelTest(TestCase):
self
.
materi
=
Materi
.
objects
.
create
(
title
=
"Materi 1"
,
author
=
"Agas"
,
uploader
=
self
.
contributor
,
publisher
=
"Kelas SC"
,
descriptions
=
"Deskripsi Materi 1"
,
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
())
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
())
def
test_like_count_return_zero_when_there_is_no_like
(
self
):
self
.
assertEqual
(
0
,
self
.
materi
.
like_count
)
def
test_like_count_return_right_value_when_there_is_like
(
self
):
Like
.
objects
.
create
(
timestamp
=
datetim
e
.
now
(),
materi
=
self
.
materi
,
session_id
=
"dummysessionid1"
)
Like
.
objects
.
create
(
timestamp
=
timezon
e
.
now
(),
materi
=
self
.
materi
,
session_id
=
"dummysessionid1"
)
self
.
assertEqual
(
1
,
self
.
materi
.
like_count
)
Like
.
objects
.
create
(
timestamp
=
datetim
e
.
now
(),
materi
=
self
.
materi
,
session_id
=
"dummysessionid2"
)
Like
.
objects
.
create
(
timestamp
=
timezon
e
.
now
(),
materi
=
self
.
materi
,
session_id
=
"dummysessionid2"
)
self
.
assertEqual
(
2
,
self
.
materi
.
like_count
)
class
MateriFavoriteTest
(
TestCase
):
...
...
@@ -2904,8 +2884,8 @@ class RandomizedMateriTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
self
.
materi
=
Materi
.
objects
.
create
(
...
...
@@ -2917,8 +2897,8 @@ class RandomizedMateriTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
def
test_randomized_materi_returns_200
(
self
):
...
...
@@ -2998,8 +2978,9 @@ class YTUrlVideoTest(TestCase):
@
override_settings
(
MEDIA_ROOT
=
tempfile
.
gettempdir
())
def
setUpImage
(
self
):
from
django.core.files.uploadedfile
import
InMemoryUploadedFile
from
io
import
BytesIO
from
django.core.files.uploadedfile
import
InMemoryUploadedFile
self
.
cover
=
InMemoryUploadedFile
(
BytesIO
(
base64
.
b64decode
(
TEST_IMAGE
)),
field_name
=
'tempfile'
,
...
...
@@ -3367,8 +3348,8 @@ class MateriRecommendationTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
Like
.
objects
.
create
(
materi
=
materi1
)
...
...
@@ -3383,8 +3364,8 @@ class MateriRecommendationTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
Like
.
objects
.
create
(
materi
=
materi2
)
...
...
@@ -3400,8 +3381,8 @@ class MateriRecommendationTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
response
=
Client
().
get
(
"/?recommendation=1"
)
...
...
@@ -3418,8 +3399,8 @@ class MateriRecommendationTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
Like
.
objects
.
create
(
materi
=
materi2
)
...
...
@@ -3434,8 +3415,8 @@ class MateriRecommendationTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
,
date_modified
=
datetim
e
.
now
(),
date_created
=
datetim
e
.
now
(),
date_modified
=
timezon
e
.
now
(),
date_created
=
timezon
e
.
now
(),
)
Like
.
objects
.
create
(
materi
=
materi1
)
...
...
app/tests.py.56b44c7bd7ec54dbc681b2c3905ccac9.tmp
deleted
100644 → 0
View file @
c320f26c
This diff is collapsed.
Click to expand it.
app/views.py
View file @
e527bfeb
...
...
@@ -346,6 +346,7 @@ def delete_materi(request, pk):
class
UploadMateriView
(
TemplateView
):
template_name
=
UNGGAH_HTML
context
=
{}
redirect_path
=
"/unggah/"
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
UploadMateriView
,
self
).
get_context_data
(
**
kwargs
)
...
...
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