Fakultas Ilmu Komputer UI

Commit e5edaf4a authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[RED] Change acara donor serializer attr and add more validation

parent ad48b1bd
......@@ -29,7 +29,8 @@ class AcaraDonorTest(TestCase):
- {waktu_berakhir.hour:02d}:{waktu_berakhir.minute:02d})"),
str(acara_donor))
@patch('django.utils.timezone.now', return_value=datetime.datetime(
2020, 6, 12, 9, 0, tzinfo=datetime.timezone.utc))
class AcaraDonorSerializerTest(TestCase):
""" Test module for Acara Donor serializer"""
......@@ -37,31 +38,55 @@ class AcaraDonorSerializerTest(TestCase):
self.user = UserFactory()
self.user.save()
self.acara_donor = AcaraDonorFactory(user=self.user)
base_time = timezone.localtime(
datetime.datetime(2020, 6, 12, 9, 18,
tzinfo=datetime.timezone.utc))
self.acara_donor_attr = {"alamat_institusi": "Pacilkom",
"alamat_lokasi_donor": "Sekre Pacil",
"email_kantor": "pacil@cs.ui.ac.id",
"email_koor": "pacilia@gmail.com",
"kategori": "Terbuka",
"kecamatan": "Beji",
"keterangan": "",
"nama_institusi": "Pacilkom",
"nama_koor": "dr. Pacilia",
"no_telp_kantor": "08165342342",
"no_telp_koor": "08167021743",
"nomor": "ea582779-fdfc-444e-ad03-4084e715af0a",
"perkiraan_jumlah_donor": 455,
"waktu_donor": timezone.now() + timezone.timedelta(days=3)}
"waktu_berakhir": base_time
+ timezone.timedelta(hours=5),
"waktu_mulai": base_time
+ timezone.timedelta(hours=3)}
def test_create_acara_donor_failed_due_to_duplication(self,
mock_timezone):
serializer = AcaraDonorSerializer(instance=self.acara_donor,
data=self.acara_donor_attr)
def test_create_acara_donor_failed_due_to_duplication(self):
serializer = AcaraDonorSerializer(instance=self.acara_donor, data=self.acara_donor_attr)
serializer.is_valid()
new_acara_donor = serializer.save()
new_acara_donor.refresh_from_db()
serializer = AcaraDonorSerializer(instance=self.acara_donor, data=self.acara_donor_attr)
serializer = AcaraDonorSerializer(instance=self.acara_donor,
data=self.acara_donor_attr)
self.assertFalse(serializer.is_valid())
def test_create_acara_donor_failed_because_time_has_passed(self,
mock_timezone):
self.acara_donor_attr['waktu_mulai'] = timezone.now() \
- timezone.timedelta(days=3)
serializer = AcaraDonorSerializer(instance=self.acara_donor,
data=self.acara_donor_attr)
self.assertFalse(serializer.is_valid())
def test_create_acara_donor_failed_because_time_has_passed(self):
self.acara_donor_attr['waktu_donor'] = timezone.now() - timezone.timedelta(days=3)
serializer = AcaraDonorSerializer(instance=self.acara_donor, data=self.acara_donor_attr)
def test_create_acara_donor_failed_because_end_time_is_before_start_time(
self, mock_timezone):
self.acara_donor_attr['waktu_mulai'] = timezone.now() \
+ timezone.timedelta(hours=5)
self.acara_donor_attr['waktu_berakhir'] = timezone.now() \
+ timezone.timedelta(hours=3)
serializer = AcaraDonorSerializer(instance=self.acara_donor,
data=self.acara_donor_attr)
self.assertFalse(serializer.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