Fakultas Ilmu Komputer UI

Commit 97b2e23c authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[RED] Change acara donor filter test

parent 34b22578
......@@ -123,8 +123,8 @@ class AcaraDonorCreateViewTest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
@patch('acara_donor.filters.now',
new=lambda: datetime.datetime(2020, 5, 10, 9, 0, tzinfo=datetime.timezone.utc))
@patch('acara_donor.filters.now', new=lambda:
datetime.datetime(2020, 5, 10, 9, 0, tzinfo=datetime.timezone.utc))
class AcaraDonorFilterTest(TestCase):
""" Test module for Acara Donor filter"""
......@@ -132,42 +132,61 @@ class AcaraDonorFilterTest(TestCase):
self.user = UserFactory()
self.user.save()
base_time = timezone.localtime(datetime.datetime(2020, 5, 10, 9, 14,
tzinfo=datetime.timezone.utc))
base_time = timezone.localtime(datetime.datetime(
2020, 5, 10, 9, 14, tzinfo=datetime.timezone.utc))
self.acara_donor_today = AcaraDonorFactory(user=self.user,
waktu_donor=base_time + timezone.timedelta(hours=3))
self.acara_donor_today = AcaraDonorFactory(
user=self.user,
waktu_mulai=base_time + timezone.timedelta(hours=3))
self.acara_donor_today.save()
self.acara_donor_overmorrow = AcaraDonorFactory(user=self.user,
waktu_donor=base_time + timezone.timedelta(days=2))
self.acara_donor_overmorrow = AcaraDonorFactory(
user=self.user,
waktu_mulai=base_time + timezone.timedelta(days=2))
self.acara_donor_overmorrow.save()
self.acara_donor_next_month = AcaraDonorFactory(user=self.user,
waktu_donor=base_time + timezone.timedelta(days=33))
self.acara_donor_next_month = AcaraDonorFactory(
user=self.user,
waktu_mulai=base_time + timezone.timedelta(days=33))
self.acara_donor_next_month.save()
def test_filter_acara_donor_today_success(self):
filter_today = AcaraDonorFilter(None, {'waktu_donor': 'today'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_today.queryset(None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_donor, self.acara_donor_today.waktu_donor)
filter_today = AcaraDonorFilter(None, {'waktu_mulai': 'today'},
AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_today.queryset(
None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_mulai,
self.acara_donor_today.waktu_mulai)
def test_filter_acara_donor_next_seven_days_success(self):
filter_seven_days = AcaraDonorFilter(None, {'waktu_donor': 'next_seven_days'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_seven_days.queryset(None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_donor, self.acara_donor_overmorrow.waktu_donor)
filter_seven_days = AcaraDonorFilter(
None, {'waktu_mulai': 'next_seven_days'},
AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_seven_days.queryset(
None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_mulai,
self.acara_donor_overmorrow.waktu_mulai)
def test_filter_acara_donor_this_month_success(self):
filter_this_month = AcaraDonorFilter(None, {'waktu_donor': 'this_month'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_this_month.queryset(None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_donor, self.acara_donor_overmorrow.waktu_donor)
filter_this_month = AcaraDonorFilter(
None, {'waktu_mulai': 'this_month'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_this_month.queryset(
None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_mulai,
self.acara_donor_overmorrow.waktu_mulai)
def test_filter_acara_donor_next_month_success(self):
filter_next_month = AcaraDonorFilter(None, {'waktu_donor': 'next_month'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_next_month.queryset(None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_donor, self.acara_donor_next_month.waktu_donor)
filter_next_month = AcaraDonorFilter(
None, {'waktu_mulai': 'next_month'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_next_month.queryset(
None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_mulai,
self.acara_donor_next_month.waktu_mulai)
def test_filter_acara_donor_this_year_success(self):
filter_this_year = AcaraDonorFilter(None, {'waktu_donor': 'this_year'}, AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_this_year.queryset(None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_donor, self.acara_donor_next_month.waktu_donor)
filter_this_year = AcaraDonorFilter(None, {'waktu_mulai': 'this_year'},
AcaraDonor, AcaraDonorAdmin)
acara_donor_filtered = filter_this_year.queryset(
None, AcaraDonor.objects.all())[0]
self.assertEqual(acara_donor_filtered.waktu_mulai,
self.acara_donor_next_month.waktu_mulai)
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