diff --git a/administration/tests.py b/administration/tests.py index 6ba9e50b788c568dd4ce4661922f25283005647b..cc7b72df30e9b727df09ed8e055755dd5751577f 100644 --- a/administration/tests.py +++ b/administration/tests.py @@ -10,7 +10,9 @@ from app.models import Category, Materi, LaporanMateri from authentication.models import User from bs4 import BeautifulSoup -from datetime import datetime +from datetime import datetime, timedelta + +from .forms import PeriodForm EDIT_ENDPOINT = "/edit" ERROR_403_MESSAGE = 'Kamu harus login untuk mengakses halaman ini' @@ -1659,3 +1661,50 @@ class EditKontributorStatusTests(TestCase): 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()) diff --git a/digipus/__pycache__/settings.cpython-36.pyc b/digipus/__pycache__/settings.cpython-36.pyc index 1cf78ac5dc695e4dca1c09a4b10db034aec54534..43d2d1c4169e7113ebfa287197b9840fd637a652 100644 Binary files a/digipus/__pycache__/settings.cpython-36.pyc and b/digipus/__pycache__/settings.cpython-36.pyc differ