def test_list_barriers_get_multiple_barriers(self): count = 2 BarrierFactory.create_batch(count) url = reverse("list-barriers") response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK assert count == response.data["count"]
def test_list_barriers_count(self): count = 2 BarrierFactory.create_batch(count) assert count == Barrier.objects.count() dataset_url = reverse("dataset:barrier-list") response = self.api_client.get(dataset_url) assert status.HTTP_200_OK == response.status_code assert count == len(response.data["results"])
def test_list_barriers_status_filter(self): prob_status = 2 BarrierFactory.create_batch(2, term=1) BarrierFactory(term=prob_status) assert 3 == Barrier.objects.count() url = f'{reverse("list-barriers")}?status={prob_status}' response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK barriers = Barrier.objects.filter(status=prob_status) assert response.data["count"] == barriers.count()
def test_list_barriers_country_filter(self): country_id = "a05f66a0-5d95-e211-a939-e4115bead28a" BarrierFactory.create_batch(2, country=country_id) BarrierFactory() assert 3 == Barrier.objects.count() url = f'{reverse("list-barriers")}?location={country_id}' response = self.api_client.get(url) assert response.status_code == status.HTTP_200_OK barriers = Barrier.objects.filter(country=country_id) assert barriers.count() == response.data["count"]
def test_inactive_barrier_reminder_email(self): test_user = create_test_user() inactivity_theshold_date = timezone.now() - timedelta( days=settings.BARRIER_INACTIVITY_THESHOLD_DAYS) BarrierFactory.create_batch(size=10) for barrier in Barrier.objects.all(): TeamMemberFactory(barrier=barrier, user=test_user, role="Owner", default=True) # modified_on can't be updated directly, so we need to update the barrier queryset Barrier.objects.all().update(modified_on=inactivity_theshold_date - timedelta(days=1)) # create recent barries that should not be sent a reminder BarrierFactory.create_batch(size=15) with patch.object(NotificationsAPIClient, "send_email_notification", return_value=None) as mock: send_barrier_inactivity_reminders() assert mock.call_count == 10 assert (Barrier.objects.filter( activity_reminder_sent__isnull=False).count() == 10) mock.stop() # when called a second time, no new reminders should be sent with patch.object(NotificationsAPIClient, "send_email_notification", return_value=None) as mock: send_barrier_inactivity_reminders() assert mock.call_count == 0 assert (Barrier.objects.filter( activity_reminder_sent__isnull=False).count() == 10) mock.stop()