Fakultas Ilmu Komputer UI

Commit f43b4a12 authored by Ichlasul Affan's avatar Ichlasul Affan
Browse files

Eliminate Code Smells and Duplications on Backend Codes (especially Tests)

parent d7c86abe
...@@ -326,10 +326,4 @@ package-lock.json ...@@ -326,10 +326,4 @@ package-lock.json
# MacOS related files # MacOS related files
.DS_Store .DS_Store
kape/files/student-photo/ kape/files/**/*
kape/files/student-resume/
kape/files/student-sertifikat/
kape/files/student-ui-ux-portofolio/
...@@ -127,9 +127,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer): ...@@ -127,9 +127,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
class CompanyUpdateSerializer(serializers.ModelSerializer): class CompanyUpdateSerializer(serializers.ModelSerializer):
def to_representation(self, instance): def to_representation(self, instance):
logo = None
if instance.logo and hasattr(instance.logo, 'url'):
logo = instance.logo.url
return { return {
'address': instance.address, 'address': instance.address,
'description': instance.description, 'description': instance.description,
...@@ -185,4 +182,4 @@ class RegisterSerializer(serializers.HyperlinkedModelSerializer): ...@@ -185,4 +182,4 @@ class RegisterSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = User model = User
fields = ('url', 'username', 'email', 'is_staff', 'company') fields = ('url', 'username', 'email', 'is_staff', 'company')
\ No newline at end of file
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)
...@@ -6,28 +6,16 @@ from django.contrib.auth.models import User ...@@ -6,28 +6,16 @@ from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from StringIO import StringIO from StringIO import StringIO
from core.models.accounts import Company, Supervisor, Student, get_current_age 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): class LoginTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_succesful_student_login_relogin(self, m): 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) mock_csui_oauth_verify(m)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ mock_csui_ldap_student(m)
"username": "dummy.mahasiswa", mock_csui_siak_student(m)
"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/' url = '/api/login/'
...@@ -39,15 +27,8 @@ class LoginTests(APITestCase): ...@@ -39,15 +27,8 @@ class LoginTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_successful_supervisor_login_relogin(self, m): 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) mock_csui_oauth_verify(m)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ mock_csui_ldap_lecturer(m)
"username": "dummy.dosen",
"nama": "Dummy Dosen",
"state": 1,
"kode_org": "01.00.12.01:dosen",
"kodeidentitas": "1234567891",
"nama_role": "dosen"
}, status_code=200)
url = '/api/login/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json') response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
...@@ -58,9 +39,7 @@ class LoginTests(APITestCase): ...@@ -58,9 +39,7 @@ class LoginTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_failed_sso_login(self, m): def test_failed_sso_login(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ mock_csui_ldap_fail(m)
"state": 0
}, status_code=200)
url = '/api/login/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.salah', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json') response = self.client.post(url, {'username': 'dummy.salah', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
...@@ -73,7 +52,7 @@ class LoginTests(APITestCase): ...@@ -73,7 +52,7 @@ class LoginTests(APITestCase):
def test_success_company_login(self): def test_success_company_login(self):
new_user = User.objects.create_user('dummy.login.company', 'dummy.login.company@company.com', 'lalala123') 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/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json') response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json')
...@@ -90,7 +69,6 @@ class LoginTests(APITestCase): ...@@ -90,7 +69,6 @@ class LoginTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
class RegisterTests(APITestCase): class RegisterTests(APITestCase):
def test_create_and_recreate(self): def test_create_and_recreate(self):
url = '/api/register/' 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'} 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): ...@@ -117,31 +95,16 @@ class RegisterTests(APITestCase):
class ProfileUpdateTests(APITestCase): class ProfileUpdateTests(APITestCase):
def _create_test_file_pdf(self, path):
def _create_test_file_pdf(self,path):
file = open(path, 'rb') file = open(path, 'rb')
return {'pdf_sertifikat':file} return {'pdf_sertifikat':file}
@requests_mock.Mocker() @requests_mock.Mocker()
def test_student_profile_update(self, m): 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) mock_csui_oauth_verify(m)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ mock_csui_ldap_student(m)
"username": "dummy.mahasiswa", mock_csui_siak_student(m)
"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/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json') format='json')
...@@ -199,7 +162,7 @@ class ProfileUpdateTests(APITestCase): ...@@ -199,7 +162,7 @@ class ProfileUpdateTests(APITestCase):
url = '/api/students/' + str(student_id) + "/profile/" url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'phone_number': '````'}, format='multipart') 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/' url = '/api/students/123123123/profile/'
response = self.client.patch(url, {'phone_number': '08123123123'}, format='multipart') response = self.client.patch(url, {'phone_number': '08123123123'}, format='multipart')
...@@ -252,23 +215,9 @@ class ProfileUpdateTests(APITestCase): ...@@ -252,23 +215,9 @@ class ProfileUpdateTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_student_profile_update_filetype_validation(self, m): 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) mock_csui_oauth_verify(m)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ mock_csui_ldap_student(m)
"username": "dummy.mahasiswa", mock_csui_siak_student(m)
"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/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
...@@ -299,7 +248,7 @@ class ProfileUpdateTests(APITestCase): ...@@ -299,7 +248,7 @@ class ProfileUpdateTests(APITestCase):
response = self.client.patch(url, {'expected_salary': '4000000'}, format='multipart') response = self.client.patch(url, {'expected_salary': '4000000'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('expected_salary'), '4000000') self.assertEqual(response.data.get('expected_salary'), '4000000')
response = self.client.patch(url, {'job_seeking_status': 'Active'}, format='multipart') response = self.client.patch(url, {'job_seeking_status': 'Active'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('job_seeking_status'), 'Active') self.assertEqual(response.data.get('job_seeking_status'), 'Active')
...@@ -310,7 +259,7 @@ class ProfileUpdateTests(APITestCase): ...@@ -310,7 +259,7 @@ class ProfileUpdateTests(APITestCase):
url = '/api/students/' + str(student_id) + "/profile/" url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'GPA': "this is not a valid input"}, format='multipart') response = self.client.patch(url, {'GPA': "this is not a valid input"}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
url = '/api/students/' + str(student_id) + '/profile/' url = '/api/students/' + str(student_id) + '/profile/'
response = self.client.patch(url, {'volunteer': 'Ketua BEM UI - 2020'}, format='multipart') response = self.client.patch(url, {'volunteer': 'Ketua BEM UI - 2020'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
...@@ -329,14 +278,14 @@ class ProfileUpdateTests(APITestCase): ...@@ -329,14 +278,14 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('work_experience'), 'Magang 3 bulan di Pusilkom') self.assertEqual(response.data.get('work_experience'), 'Magang 3 bulan di Pusilkom')
def _create_test_file(self,path): def _create_test_file(self,path):
f = open(path, 'r') f = open(path, 'r')
return {'pdf_file': f} return {'pdf_file': f}
def test_company_profile_update(self): def test_company_profile_update(self):
new_user = User.objects.create_user('dummy.login.company', 'dummy.login.company@company.com', 'lalala123') 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/' url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json') response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json')
...@@ -351,4 +300,4 @@ class ProfileUpdateTests(APITestCase): ...@@ -351,4 +300,4 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
response = self.client.patch(url, {'description': 'Masak-Masak'}, format='multipart') response = self.client.patch(url, {'description': 'Masak-Masak'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED) self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
\ No newline at end of file
...@@ -3,32 +3,14 @@ from rest_framework import status ...@@ -3,32 +3,14 @@ from rest_framework import status
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from core.models.feedbacks import Feedback 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): class FeedbacksTests(APITestCase):
def login(self, m): def login(self, m):
# Login mock_csui_oauth_verify(m)
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', mock_csui_ldap_student(m)
json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, mock_csui_siak_student(m)
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)
login_url = '/api/login/' login_url = '/api/login/'
self.client.post(login_url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, self.client.post(login_url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json') format='json')
...@@ -289,7 +271,7 @@ class FeedbacksTests(APITestCase): ...@@ -289,7 +271,7 @@ class FeedbacksTests(APITestCase):
feedbacks_url = '/api/feedbacks/' + str(feedback_id) + '/' feedbacks_url = '/api/feedbacks/' + str(feedback_id) + '/'
response = self.client.put(feedbacks_url, response = self.client.put(feedbacks_url,
{"content": "updated content", "title": "updated title"}) {"content": "updated content", "title": "updated title"})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["detail"], "Feedback with id {} doesn't exist".format(feedback_id)) self.assertEqual(response.data["detail"], "Feedback with id {} doesn't exist".format(feedback_id))
......
...@@ -10,38 +10,22 @@ from rest_framework.test import APITestCase ...@@ -10,38 +10,22 @@ from rest_framework.test import APITestCase
from core.models.accounts import Company, Student, Supervisor from core.models.accounts import Company, Student, Supervisor
from core.models.vacancies import Vacancy, Application, VacancyMilestone from core.models.vacancies import Vacancy, Application, VacancyMilestone
from core.views.vacancies import date_validator 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): class ApplicationTests(APITestCase):
@requests_mock.Mocker() def get_student_id(self, mock_obj):
def test_application_list(self, m): mock_csui_oauth_verify(mock_obj)
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', mock_csui_ldap_student(mock_obj)
json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, mock_csui_siak_student(mock_obj)
status_code=200) login_url = '/api/login/'
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ response = self.client.post(login_url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
"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') 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/' url = '/api/students/' + str(student_id) + '/applied-vacancies/'
response = self.client.get(url) response = self.client.get(url)
...@@ -49,30 +33,7 @@ class ApplicationTests(APITestCase): ...@@ -49,30 +33,7 @@ class ApplicationTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_application_search(self, m): 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) student_id = self.get_student_id(m)
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) + '/applied-vacancies/?search=engineer' url = '/api/students/' + str(student_id) + '/applied-vacancies/?search=engineer'
response = self.client.get(url) response = self.client.get(url)
...@@ -80,34 +41,7 @@ class ApplicationTests(APITestCase): ...@@ -80,34 +41,7 @@ class ApplicationTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_application_create_and_delete(self, m): def test_application_create_and_delete(self, m):
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', student_id = self.get_student_id(m)
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')
new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123') 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, new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None) address=None)
...@@ -168,30 +102,7 @@ class ApplicationTests(APITestCase): ...@@ -168,30 +102,7 @@ class ApplicationTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_cannot_create_application_if_vacancy_is_closed(self, m): 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) student_id = self.get_student_id(m)
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')
new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123') 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, new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None) address=None)
...@@ -204,122 +115,51 @@ class ApplicationTests(APITestCase): ...@@ -204,122 +115,51 @@ class ApplicationTests(APITestCase):
class BookmarkApplicationTests(APITestCase): class BookmarkApplicationTests(APITestCase):
@requests_mock.Mocker() @requests_mock.Mocker()
def test_application_list(self, m): def setUp(self, m):
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', mock_csui_oauth_verify(m)
json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, mock_csui_ldap_student(m)
status_code=200) mock_csui_siak_student(m)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={ login_url = '/api/login/'
"username": "dummy.mahasiswa", response = self.client.post(login_url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
"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",