diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..9e3297c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,19 @@ +from django.test import TestCase +from academy.apps.offices.models import Setting, AuthSetting, ConfigEmail + + +class AcademyTestCase(TestCase): + + def setUp(self): + Setting.objects.create() + AuthSetting.objects.create() + ConfigEmail.objects.update_or_create( + id=1, + from_email="no-reply@example.id", + email_host="mail.example.id", + email_user="no-reply@example.id", + email_password="Password123", + email_port=587, + use_tls=False, + recipient_email="no-reply@example.id" + ) diff --git a/tests/accounts/test_views.py b/tests/accounts/test_views.py index 3369e90..20246e8 100644 --- a/tests/accounts/test_views.py +++ b/tests/accounts/test_views.py @@ -1,23 +1,19 @@ -from django.test import TestCase -from django.test import Client +from tests import AcademyTestCase from academy.apps.accounts.models import User, Inbox -from academy.apps.offices.models import Setting, AuthSetting -class AccountsUserViewTest(TestCase): +class AccountsUserViewTest(AcademyTestCase): fixtures = ['accounts.json', 'students.json'] def setUp(self): - Setting.objects.create() - AuthSetting.objects.create() + super().setUp() + self.user = User.objects.get(email='user2@gmail.com') + self.user.set_password('password123') + self.user.save() def test_inbox(self): - user = User.objects.get(email='user2@gmail.com') - user.set_password('password123') - user.save() - - login = self.client.login(username=user.username, password='password123') + login = self.client.login(username=self.user.username, password='password123') self.assertTrue(login) # normal url diff --git a/tests/backoffice/test_training_materials.py b/tests/backoffice/test_training_materials.py index dad2ef4..6cbf156 100644 --- a/tests/backoffice/test_training_materials.py +++ b/tests/backoffice/test_training_materials.py @@ -1,14 +1,19 @@ -from django.test import TestCase, Client +from urllib.parse import urlencode + +from tests import AcademyTestCase +from django.test import Client from django.urls import reverse from academy.apps.accounts.models import User from academy.apps.students.models import Student, Training, TrainingStatus +from academy.backoffice.training_materials.forms import StudentFilterForm -class TrainingMaterialTest(TestCase): +class TrainingMaterialTest(AcademyTestCase): fixtures = ['accounts.json', 'students.json'] def setUp(self): + super().setUp() self.admin = User.objects.filter(is_superuser=True).first() self.admin.set_password('123qweasd') self.admin.save() @@ -26,17 +31,17 @@ def test_bulk_material_status(self): training__materials__id=training_material.id) data = { 'students': list(students.values_list('id', flat=True)), - 'training_materials': training_material, - 'status': TrainingStatus.STATUS.not_yet + 'training_materials': training_material.id, + 'status': TrainingStatus.STATUS.graduate, + 'student_status': StudentFilterForm.STUDENT_STATUS.participants, + 'batch': training.id } - - query_params = f"?training_materials={training_material.id}&batch={training.batch}"\ - f"&status={Student.STATUS.participants}" - response = self.client.post(reverse('backoffice:training_materials:bulk_material_status') - + query_params, data=data) + query_params = urlencode(data) + url = f"{reverse('backoffice:training_materials:bulk_material_status')}?{query_params}" + response = self.client.post(url) self.assertEqual(response.status_code, 200) for student in students: materi = student.training.materials.get(id=training_material.id) status = materi.get_training_status(student.user).status - self.assertEqual(status, TrainingStatus.STATUS.not_yet) + self.assertEqual(status, TrainingStatus.STATUS.graduate) diff --git a/tests/test_auth_user.py b/tests/test_auth_user.py index 2fff2d0..20488ac 100644 --- a/tests/test_auth_user.py +++ b/tests/test_auth_user.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests import AcademyTestCase from django.urls import reverse from academy.apps.accounts.models import User @@ -7,19 +7,19 @@ from academy.website.accounts.forms import SurveyForm -class AuthUserViewTest(TestCase): +class AuthUserViewTest(AcademyTestCase): fixtures = ['accounts.json', 'students.json'] def test_auth_user(self): user = User.objects.get(email='user2@gmail.com') url = user.generate_auth_url() response = self.client.get(url) - + # kalau belum punya survey harus redirect ke survey self.assertRedirects(response, '/accounts/survey/', status_code=302, target_status_code=200, fetch_redirect_response=True) - #test untuk user yang sudah memiliki memiliki survey - #create survey + # test untuk user yang sudah memiliki memiliki survey + # create survey data = { 'working_status': Survey.WORKING_STATUS_CHOICES.employee, 'graduate_channeled': True, diff --git a/tests/test_forms.py b/tests/test_forms.py index 7ac9ffb..79c3167 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests import AcademyTestCase from academy.apps.accounts.models import User from academy.apps.students.models import Training, Student @@ -6,7 +6,7 @@ from academy.apps.campuses.models import Campus -class AccountsTestForm(TestCase): +class AccountsTestForm(AcademyTestCase): def test_signup_form(self): data = { diff --git a/tests/test_graduates.py b/tests/test_graduates.py index c4c309e..783c1bb 100644 --- a/tests/test_graduates.py +++ b/tests/test_graduates.py @@ -1,10 +1,10 @@ -from django.test import TestCase +from tests import AcademyTestCase from academy.apps.accounts.models import User from academy.apps.graduates.models import Graduate -class GraduateTest(TestCase): +class GraduateTest(AcademyTestCase): fixtures = ['accounts.json', 'students.json'] def test_generate_certificate_number(self):