Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 3b534417 authored by Muhammad Fauzan Fikri's avatar Muhammad Fauzan Fikri
Browse files

merge migrations and resolve conflict test

parents e30f273a c917b5b4
No related branches found
No related tags found
1 merge request!321506688802 02
Pipeline #22771 passed
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2019-10-10 04:34
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0039_merge_20191010_0833'),
]
operations = [
migrations.AlterField(
model_name='student',
name='phone_number',
field=models.CharField(blank=True, db_index=True, max_length=12, null=True, validators=[django.core.validators.RegexValidator('^0\\d{1,11}$')]),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-10 04:55
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0040_merge_20191010_1031'),
('core', '0040_auto_20191010_1134'),
]
operations = [
]
import requests_mock
from datetime import date, timedelta
from rest_framework import status
from rest_framework.test import APIClient, APITestCase
from django.contrib.auth.models import User
from core.models.accounts import Company, Supervisor, Student
from django.core.exceptions import ValidationError
from core.models.accounts import Company, Supervisor, Student, get_current_age
class LoginTests(APITestCase):
......@@ -86,12 +88,17 @@ class LoginTests(APITestCase):
response = self.client.post(url, {'username': 'lalala', 'password': 'lalalala', 'login-type' : 'lalala'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_return_age(self):
birth_day = (date.today() -timedelta(days = 700))
self.assertEqual(1, get_current_age(birth_day))
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'}
tc_post = {'password': 'corporatepass', 'name':'tutuplapak', 'description':'menutup lapak', 'email': 'email@email.com', 'logo':'lalala', 'address':'alamat', 'category':'Perusahaan Jasa', 'website':'www.tutuplapak.com'}
response = self.client.post(url, tc_post, format='multipart')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
......@@ -103,6 +110,16 @@ class RegisterTests(APITestCase):
response = self.client.post(url, {'username': 'lalala'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_npm_validator(self):
new_user = User.objects.create_user('dummy.student2', 'dummy.student@student.com', 'lalala123')
short_npm = Student(user=new_user, npm="123456789")
self.assertRaises(ValidationError, short_npm.full_clean)
wrong_checksum = Student(user=new_user, npm="1234567890")
self.assertRaises(ValidationError, wrong_checksum.full_clean)
right_checksum = Student(user=new_user, npm="1234567894")
right_checksum.full_clean()
class ProfileUpdateTests(APITestCase):
......@@ -125,7 +142,7 @@ class ProfileUpdateTests(APITestCase):
"angkatan": "2017"
}]
}, status_code=200)
print("Hello World!")
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
......@@ -146,6 +163,11 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('website_url'), 'https://www.example.com/')
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'recommendations': 'mantap kak'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('recommendations'), 'mantap kak')
response = self.client.patch(url, {'region': 'Indonesia'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('region'), 'Indonesia')
......@@ -154,6 +176,10 @@ class ProfileUpdateTests(APITestCase):
response = self.client.patch(url, {'email': 'saasdasd'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
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)
url = '/api/students/123123123/profile/'
response = self.client.patch(url, {'phone_number': '08123123123'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......@@ -173,7 +199,35 @@ class ProfileUpdateTests(APITestCase):
response = self.client.patch(url, {'phone_number': '08123123123'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file('./assets/pdf/pdf-coba.pdf')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_200_OK)
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file('./assets/img/image-coba.jpg')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'latest_work': 'Teaching assistant at Fasilkom UI'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('latest_work'), 'Teaching assistant at Fasilkom UI')
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'latest_work_desc': 'Evaluate weekly assignment for 15 students'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('latest_work_desc'), 'Evaluate weekly assignment for 15 students')
url = '/api/students/' + str(student_id) + '/profile/'
response = self.client.patch(url, {'intro': 'Saya tertarik dengan dunia front-end development'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('intro'), 'Saya tertarik dengan dunia front-end development')
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)
self.assertEqual(response.data.get('volunteer'), 'Ketua BEM UI - 2020')
def _create_test_file(self,path):
f = open(path, 'r')
return {'pdf_file': f}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment