Skip to content

Commit

Permalink
fix error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanpule committed Jul 7, 2020
1 parent 8b7d171 commit 22cd9c4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
19 changes: 19 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
email_host="mail.example.id",
email_user="[email protected]",
email_password="Password123",
email_port=587,
use_tls=False,
recipient_email="[email protected]"
)
18 changes: 7 additions & 11 deletions tests/accounts/test_views.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]')
self.user.set_password('password123')
self.user.save()

def test_inbox(self):
user = User.objects.get(email='[email protected]')
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
Expand Down
25 changes: 15 additions & 10 deletions tests/backoffice/test_training_materials.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
10 changes: 5 additions & 5 deletions tests/test_auth_user.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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='[email protected]')
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,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.test import TestCase
from tests import AcademyTestCase

from academy.apps.accounts.models import User
from academy.apps.students.models import Training, Student
from academy.website.accounts.forms import StudentForm, SignupForm
from academy.apps.campuses.models import Campus


class AccountsTestForm(TestCase):
class AccountsTestForm(AcademyTestCase):

def test_signup_form(self):
data = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_graduates.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 22cd9c4

Please sign in to comment.