Add test for notify_applicants_tou_changes.py
@@ -2855,6 +2855,35 @@ class EvaluateApplicationTest(TestCase):
self.application.refresh_from_db()
self.assertEqual(self.application.sent_by, coordinator.user)
+ def test_notify_applicants_tou_changes(self):
+ # Run the command which should add comments to outstanding apps.
+ call_command("notify_applicants_tou_changes")
+ # Filter apps with the same queryset as the above command.
+ pending_apps = (
+ Application.objects.filter(
+ status__in=[Application.PENDING, Application.QUESTION],
+ partner__status__in=[Partner.AVAILABLE],
+ editor__isnull=False,
+ editor__user__userprofile__terms_of_use=False
+ )
+ .exclude(editor__user__groups__name="restricted")
+ .order_by("status", "partner", "date_created")
+ )
+ twl_comment_count = 0
+ twl_team = User.objects.get(username='TWL Team')
+ # Loop through the apps and count comments from twl_team.
+ for app in pending_apps:
+ twl_comment_count += Comment.objects.filter(
+ object_pk=str(app.pk),
+ site_id=settings.SITE_ID,
+ user=twl_team,
+ ).count()
+ # Assert that we have at least one pending app; if other tests leave no pending_apps, we want to fail here
+ # because that might mask a problem with the command that causes it to leave no comments.
+ self.assertGreater(pending_apps.count(), 0)
+ # Assert one twl_team comment per pending_app.
+ self.assertEqual(twl_comment_count, pending_apps.count())
+
class BatchEditTest(TestCase):
def setUp(self):
