Fakultas Ilmu Komputer UI

Commit 2a519108 authored by Ahmad Fauzan Amirul Isnain's avatar Ahmad Fauzan Amirul Isnain
Browse files

[#132] QA: Add Tests for PeriodForm Validation

parent bb5a2dfd
...@@ -10,7 +10,9 @@ from app.models import Category, Materi, LaporanMateri ...@@ -10,7 +10,9 @@ from app.models import Category, Materi, LaporanMateri
from authentication.models import User from authentication.models import User
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from datetime import datetime from datetime import datetime, timedelta
from .forms import PeriodForm
EDIT_ENDPOINT = "/edit" EDIT_ENDPOINT = "/edit"
ERROR_403_MESSAGE = 'Kamu harus login untuk mengakses halaman ini' ERROR_403_MESSAGE = 'Kamu harus login untuk mengakses halaman ini'
...@@ -1659,3 +1661,50 @@ class EditKontributorStatusTests(TestCase): ...@@ -1659,3 +1661,50 @@ class EditKontributorStatusTests(TestCase):
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
class PeriodFormTests(TestCase):
def test_validation_error_when_start_date_is_none(self):
data = {
'start_date': None,
'end_date': datetime.now(),
}
form = PeriodForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(
form["start_date"].errors,
['masukan waktu mulai']
)
def test_validation_error_when_end_date_is_none(self):
data = {
'start_date': datetime.now(),
'end_date': None,
}
form = PeriodForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(
form["end_date"].errors,
['masukan waktu selesai']
)
def test_validation_error_when_start_date_greater_than_end_date(self):
current_time = datetime.now()
data = {
'start_date': current_time + timedelta(days = 1),
'end_date': current_time,
}
form = PeriodForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(
form["end_date"].errors,
['waktu selesai sebelum waktu mulai']
)
def test_form_valid_when_data_valid(self):
current_time = datetime.now()
data = {
'start_date': current_time - timedelta(days = 1),
'end_date': current_time,
}
form = PeriodForm(data)
self.assertTrue(form.is_valid())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment