From 35f1a7a262e07a485205ebc56ffbc7740b5f7f8a Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Tue, 25 Feb 2020 12:45:06 +0000
Subject: [PATCH] Fix failing tests

1. ensure that submitted reports are still considered in the submitted last
report
2. improve a flaky test to actually search for a value that is present
---
 hypha/apply/funds/tests/test_views.py         | 4 ++--
 hypha/apply/projects/models.py                | 8 +++++++-
 hypha/apply/projects/tests/test_commands.py   | 3 ++-
 hypha/apply/stream_forms/testing/factories.py | 2 +-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/hypha/apply/funds/tests/test_views.py b/hypha/apply/funds/tests/test_views.py
index 3908abf8e..5e5bd2cea 100644
--- a/hypha/apply/funds/tests/test_views.py
+++ b/hypha/apply/funds/tests/test_views.py
@@ -176,9 +176,9 @@ class TestStaffSubmissionView(BaseSubmissionViewTestCase):
         self.assertEqual(new_title, submission.title)
 
     def test_not_included_fields_render(self):
-        submission = ApplicationSubmissionFactory(form_fields__exclude__value=True)
+        submission = ApplicationSubmissionFactory(form_fields__exclude__checkbox=True)
         response = self.get_page(submission)
-        self.assertNotContains(response, 'Value')
+        self.assertNotContains(response, 'check_one')
 
     def test_can_screen_submission(self):
         screening_outcome = ScreeningStatusFactory()
diff --git a/hypha/apply/projects/models.py b/hypha/apply/projects/models.py
index 177520471..0acbf9a80 100644
--- a/hypha/apply/projects/models.py
+++ b/hypha/apply/projects/models.py
@@ -651,8 +651,14 @@ class ReportConfig(models.Model):
 
     def last_report(self):
         today = timezone.now().date()
+        # Get the most recent report that was either:
+        # - due by today and not submitted
+        # - was skipped but due after today
+        # - was submitted but due after today
         return self.project.reports.filter(
-            Q(end_date__lt=today) | Q(skipped=True)
+            Q(end_date__lt=today) |
+            Q(skipped=True) |
+            Q(submitted__isnull=False)
         ).first()
 
     def current_due_report(self):
diff --git a/hypha/apply/projects/tests/test_commands.py b/hypha/apply/projects/tests/test_commands.py
index 685162fe7..e3b885288 100644
--- a/hypha/apply/projects/tests/test_commands.py
+++ b/hypha/apply/projects/tests/test_commands.py
@@ -30,7 +30,8 @@ class TestNotifyReportDue(TestCase):
             end_date=config.schedule_start,
         )
         out = StringIO()
-        call_command('notify_report_due', 7, stdout=out)
+        with self.settings(ALLOWED_HOSTS=[ApplyHomePage.objects.first().get_site().hostname]):
+            call_command('notify_report_due', 7, stdout=out)
         self.assertNotIn('Notified project', out.getvalue())
 
     def test_dont_notify_already_notified(self):
diff --git a/hypha/apply/stream_forms/testing/factories.py b/hypha/apply/stream_forms/testing/factories.py
index 49d7c5bfc..8a705b5ea 100644
--- a/hypha/apply/stream_forms/testing/factories.py
+++ b/hypha/apply/stream_forms/testing/factories.py
@@ -179,7 +179,7 @@ class CheckboxFieldBlockFactory(FormFieldBlockFactory):
 
 
 class CheckboxesFieldBlockFactory(FormFieldBlockFactory):
-    checkboxes = ['check_one', 'check_two', 'check_three']
+    checkboxes = ['check_multiple_one', 'check_multiple_two', 'check_multiple_three']
 
     class Meta:
         model = stream_blocks.CheckboxesFieldBlock
-- 
GitLab