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
Kape
Commits
f43b4a12
Commit
f43b4a12
authored
Nov 13, 2019
by
Ichlasul Affan
Browse files
Eliminate Code Smells and Duplications on Backend Codes (especially Tests)
parent
d7c86abe
Changes
8
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
f43b4a12
...
...
@@ -326,10 +326,4 @@ package-lock.json
# MacOS related files
.DS_Store
kape/files/student-photo/
kape/files/student-resume/
kape/files/student-sertifikat/
kape/files/student-ui-ux-portofolio/
kape/files/**/*
core/serializers/accounts.py
View file @
f43b4a12
...
...
@@ -127,9 +127,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
class
CompanyUpdateSerializer
(
serializers
.
ModelSerializer
):
def
to_representation
(
self
,
instance
):
logo
=
None
if
instance
.
logo
and
hasattr
(
instance
.
logo
,
'url'
):
logo
=
instance
.
logo
.
url
return
{
'address'
:
instance
.
address
,
'description'
:
instance
.
description
,
...
...
@@ -185,4 +182,4 @@ class RegisterSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
:
model
=
User
fields
=
(
'url'
,
'username'
,
'email'
,
'is_staff'
,
'company'
)
\ No newline at end of file
fields
=
(
'url'
,
'username'
,
'email'
,
'is_staff'
,
'company'
)
core/tests/mocks.py
0 → 100644
View file @
f43b4a12
def
mock_csui_oauth_verify
(
mock_obj
):
mock_obj
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
def
mock_csui_ldap_student
(
mock_obj
):
mock_obj
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
def
mock_csui_ldap_lecturer
(
mock_obj
):
mock_obj
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.dosen"
,
"nama"
:
"Dummy Dosen"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:dosen"
,
"kodeidentitas"
:
"1234567891"
,
"nama_role"
:
"dosen"
},
status_code
=
200
)
def
mock_csui_ldap_fail
(
mock_obj
):
mock_obj
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"state"
:
0
},
status_code
=
200
)
def
mock_csui_siak_student
(
mock_obj
):
mock_obj
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
core/tests/test_accounts.py
View file @
f43b4a12
...
...
@@ -6,28 +6,16 @@ from django.contrib.auth.models import User
from
django.core.exceptions
import
ValidationError
from
StringIO
import
StringIO
from
core.models.accounts
import
Company
,
Supervisor
,
Student
,
get_current_age
from
core.tests.mocks
import
(
mock_csui_oauth_verify
,
mock_csui_ldap_student
,
mock_csui_ldap_lecturer
,
mock_csui_ldap_fail
,
mock_csui_siak_student
)
class
LoginTests
(
APITestCase
):
@
requests_mock
.
Mocker
()
def
test_succesful_student_login_relogin
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_student
(
m
)
mock_csui_siak_student
(
m
)
url
=
'/api/login/'
...
...
@@ -39,15 +27,8 @@ class LoginTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_successful_supervisor_login_relogin
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.dosen"
,
"nama"
:
"Dummy Dosen"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:dosen"
,
"kodeidentitas"
:
"1234567891"
,
"nama_role"
:
"dosen"
},
status_code
=
200
)
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_lecturer
(
m
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.dosen'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
...
...
@@ -58,9 +39,7 @@ class LoginTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_failed_sso_login
(
self
,
m
):
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"state"
:
0
},
status_code
=
200
)
mock_csui_ldap_fail
(
m
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.salah'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
...
...
@@ -73,7 +52,7 @@ class LoginTests(APITestCase):
def
test_success_company_login
(
self
):
new_user
=
User
.
objects
.
create_user
(
'dummy.login.company'
,
'dummy.login.company@company.com'
,
'lalala123'
)
new_company
=
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.login.company'
,
'password'
:
'lalala123'
,
'login-type'
:
'company'
},
format
=
'json'
)
...
...
@@ -90,7 +69,6 @@ class LoginTests(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
class
RegisterTests
(
APITestCase
):
def
test_create_and_recreate
(
self
):
url
=
'/api/register/'
tc_post
=
{
'password'
:
'corporatepass'
,
'name'
:
'tutuplapak'
,
'description'
:
'menutup lapak'
,
'email'
:
'email@email.com'
,
'logo'
:
'lalala'
,
'address'
:
'alamat'
,
'category'
:
'Perusahaan Jasa'
,
'website'
:
'www.tutuplapak.com'
}
...
...
@@ -117,31 +95,16 @@ class RegisterTests(APITestCase):
class
ProfileUpdateTests
(
APITestCase
):
def
_create_test_file_pdf
(
self
,
path
):
def
_create_test_file_pdf
(
self
,
path
):
file
=
open
(
path
,
'rb'
)
return
{
'pdf_sertifikat'
:
file
}
@
requests_mock
.
Mocker
()
def
test_student_profile_update
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_student
(
m
)
mock_csui_siak_student
(
m
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
...
...
@@ -199,7 +162,7 @@ class ProfileUpdateTests(APITestCase):
url
=
'/api/students/'
+
str
(
student_id
)
+
"/profile/"
response
=
self
.
client
.
patch
(
url
,
{
'phone_number'
:
'````'
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
url
=
'/api/students/123123123/profile/'
response
=
self
.
client
.
patch
(
url
,
{
'phone_number'
:
'08123123123'
},
format
=
'multipart'
)
...
...
@@ -252,23 +215,9 @@ class ProfileUpdateTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_student_profile_update_filetype_validation
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_student
(
m
)
mock_csui_siak_student
(
m
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
...
...
@@ -299,7 +248,7 @@ class ProfileUpdateTests(APITestCase):
response
=
self
.
client
.
patch
(
url
,
{
'expected_salary'
:
'4000000'
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
self
.
assertEqual
(
response
.
data
.
get
(
'expected_salary'
),
'4000000'
)
response
=
self
.
client
.
patch
(
url
,
{
'job_seeking_status'
:
'Active'
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
self
.
assertEqual
(
response
.
data
.
get
(
'job_seeking_status'
),
'Active'
)
...
...
@@ -310,7 +259,7 @@ class ProfileUpdateTests(APITestCase):
url
=
'/api/students/'
+
str
(
student_id
)
+
"/profile/"
response
=
self
.
client
.
patch
(
url
,
{
'GPA'
:
"this is not a valid input"
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/profile/'
response
=
self
.
client
.
patch
(
url
,
{
'volunteer'
:
'Ketua BEM UI - 2020'
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
...
...
@@ -329,14 +278,14 @@ class ProfileUpdateTests(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
self
.
assertEqual
(
response
.
data
.
get
(
'work_experience'
),
'Magang 3 bulan di Pusilkom'
)
def
_create_test_file
(
self
,
path
):
f
=
open
(
path
,
'r'
)
return
{
'pdf_file'
:
f
}
def
test_company_profile_update
(
self
):
new_user
=
User
.
objects
.
create_user
(
'dummy.login.company'
,
'dummy.login.company@company.com'
,
'lalala123'
)
new_company
=
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.login.company'
,
'password'
:
'lalala123'
,
'login-type'
:
'company'
},
format
=
'json'
)
...
...
@@ -351,4 +300,4 @@ class ProfileUpdateTests(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
response
=
self
.
client
.
patch
(
url
,
{
'description'
:
'Masak-Masak'
},
format
=
'multipart'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
\ No newline at end of file
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_202_ACCEPTED
)
core/tests/test_feedbacks.py
View file @
f43b4a12
...
...
@@ -3,32 +3,14 @@ from rest_framework import status
from
rest_framework.test
import
APITestCase
from
core.models.feedbacks
import
Feedback
from
core.tests.mocks
import
mock_csui_oauth_verify
,
mock_csui_ldap_student
,
mock_csui_siak_student
class
FeedbacksTests
(
APITestCase
):
def
login
(
self
,
m
):
# Login
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_student
(
m
)
mock_csui_siak_student
(
m
)
login_url
=
'/api/login/'
self
.
client
.
post
(
login_url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
...
...
@@ -289,7 +271,7 @@ class FeedbacksTests(APITestCase):
feedbacks_url
=
'/api/feedbacks/'
+
str
(
feedback_id
)
+
'/'
response
=
self
.
client
.
put
(
feedbacks_url
,
{
"content"
:
"updated content"
,
"title"
:
"updated title"
})
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
data
[
"detail"
],
"Feedback with id {} doesn't exist"
.
format
(
feedback_id
))
...
...
core/tests/test_vacancies.py
View file @
f43b4a12
...
...
@@ -10,38 +10,22 @@ from rest_framework.test import APITestCase
from
core.models.accounts
import
Company
,
Student
,
Supervisor
from
core.models.vacancies
import
Vacancy
,
Application
,
VacancyMilestone
from
core.views.vacancies
import
date_validator
from
core.tests.mocks
import
mock_csui_oauth_verify
,
mock_csui_ldap_student
,
mock_csui_siak_student
class
ApplicationTests
(
APITestCase
):
@
requests_mock
.
Mocker
()
def
test_application_list
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
def
get_student_id
(
self
,
mock_obj
):
mock_csui_oauth_verify
(
mock_obj
)
mock_csui_ldap_student
(
mock_obj
)
mock_csui_siak_student
(
mock_obj
)
login_url
=
'/api/login/'
response
=
self
.
client
.
post
(
login_url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
return
response
.
data
.
get
(
'student'
).
get
(
'id'
)
@
requests_mock
.
Mocker
()
def
test_application_list
(
self
,
m
):
student_id
=
self
.
get_student_id
(
m
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/applied-vacancies/'
response
=
self
.
client
.
get
(
url
)
...
...
@@ -49,30 +33,7 @@ class ApplicationTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_application_search
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
student_id
=
self
.
get_student_id
(
m
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/applied-vacancies/?search=engineer'
response
=
self
.
client
.
get
(
url
)
...
...
@@ -80,34 +41,7 @@ class ApplicationTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_application_create_and_delete
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
student_id
=
self
.
get_student_id
(
m
)
new_user
=
User
.
objects
.
create_user
(
'dummy.company'
,
'dummy.company@company.com'
,
'lalala123'
)
new_company
=
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
...
...
@@ -168,30 +102,7 @@ class ApplicationTests(APITestCase):
@
requests_mock
.
Mocker
()
def
test_cannot_create_application_if_vacancy_is_closed
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
student_id
=
self
.
get_student_id
(
m
)
new_user
=
User
.
objects
.
create_user
(
'dummy.company'
,
'dummy.company@company.com'
,
'lalala123'
)
new_company
=
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
...
...
@@ -204,122 +115,51 @@ class ApplicationTests(APITestCase):
class
BookmarkApplicationTests
(
APITestCase
):
@
requests_mock
.
Mocker
()
def
test_application_list
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
def
setUp
(
self
,
m
):
mock_csui_oauth_verify
(
m
)
mock_csui_ldap_student
(
m
)
mock_csui_siak_student
(
m
)
login_url
=
'/api/login/'
response
=
self
.
client
.
post
(
login_url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
self
.
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/bookmarked-vacancies/'
def
test_application_list
(
self
):
url
=
'/api/students/'
+
str
(
self
.
student_id
)
+
'/bookmarked-vacancies/'
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
@
requests_mock
.
Mocker
()
def
test_search_bookmarked_application
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/bookmarked-vacancies/?search=engineer'
def
test_search_bookmarked_application
(
self
):
url
=
'/api/students/'
+
str
(
self
.
student_id
)
+
'/bookmarked-vacancies/?search=engineer'
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
@
requests_mock
.
Mocker
()
def
test_application_create_and_delete
(
self
,
m
):
m
.
get
(
'https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"username"
:
'dummy.mahasiswa'
,
"role"
:
'mahasiswa'
,
"identity_number"
:
'1234567890'
},
status_code
=
200
)
m
.
post
(
'https://api.cs.ui.ac.id/authentication/ldap/v2/'
,
json
=
{
"username"
:
"dummy.mahasiswa"
,
"nama"
:
"Dummy Mahasiswa"
,
"state"
:
1
,
"kode_org"
:
"01.00.12.01:mahasiswa"
,
"kodeidentitas"
:
"1234567890"
,
"nama_role"
:
"mahasiswa"
},
status_code
=
200
)
m
.
get
(
'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG'
,
json
=
{
"kota_lahir"
:
"kota_kota"
,
"tgl_lahir"
:
"2017-12-31"
,
"program"
:
[{
"nm_org"
:
"Ilmu Informasi"
,
"angkatan"
:
"2017"
}]
},
status_code
=
200
)
url
=
'/api/login/'
response
=
self
.
client
.
post
(
url
,
{
'username'
:
'dummy.mahasiswa'
,
'password'
:
'lalala'
,
'login-type'
:
'sso-ui'
},
format
=
'json'
)
student_id
=
response
.
data
.
get
(
'student'
).
get
(
'id'
)
def
test_application_create_and_delete
(
self
):
new_user
=
User
.
objects
.
create_user
(
'dummy.company2'
,
'dummy.compan2y@company.com'
,
'lalala123'
)
new_company
=
Company
.
objects
.
create
(
user
=
new_user
,
description
=
"lalala"
,
status
=
Company
.
VERIFIED
,
logo
=
None
,
address
=
None
)
new_vacancy
=
Vacancy
.
objects
.
create
(
company
=
new_company
,
verified
=
True
,
requirements
=
"requirements"
,
open_time
=
datetime
.
fromtimestamp
(
1541319300.0
),
description
=
"lalala"
,
close_time
=
timezone
.
now
(),
max_accepted_applicants
=
3
,
working_period
=
"3 Bulan"
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/bookmarked-vacancies/'
url
=
'/api/students/'
+
str
(
self
.
student_id
)
+
'/bookmarked-vacancies/'
response
=
self
.
client
.
post
(
url
,
{
'vacancy_id'
:
new_vacancy
.
pk
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
url
=
'/api/students/'
+
str
(
student_id
)
+
'/bookmarked-vacancies/'
+
str
(
new_vacancy
.
pk
)
+
'/'
url
=
'/api/students/'
+
str
(
self
.
student_id
)
+
'/bookmarked-vacancies/'
+
str
(
new_vacancy
.
pk
)
+
'/'
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
class
VacancyTest
(
APITestCase
):
def
login
(
self
,
mock_obj
):
mock_csui_oauth_verify
(
mock_obj
)
mock_csui_ldap_student
(
mock_obj
)
mock_csui_siak_student
(
mock_obj
)
login_url
=
'/api/login/'