From 8e1b5121196c864b0c9752bf89da0830da68ac07 Mon Sep 17 00:00:00 2001
From: Caitlin Barnard <caitlin@madetech.com>
Date: Fri, 15 Nov 2024 16:39:34 +0000
Subject: [PATCH 1/3] Update chrome image to chromium to work with arm

---
 docker-compose.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 7d33fcec..7a6761c5 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -52,7 +52,7 @@ services:
       - "6379:6379"
 
   chrome:
-    image: selenium/standalone-chrome:latest
+    image: selenium/standalone-chromium:latest
     shm_size: 2gb
     depends_on:
       - web

From db129a74653bde733abc7e741f8abeb3fccd72af Mon Sep 17 00:00:00 2001
From: Caitlin Barnard <caitlin@madetech.com>
Date: Fri, 15 Nov 2024 16:39:56 +0000
Subject: [PATCH 2/3] Refactor test to remove duplication

---
 forecast/test/test_clear_forecast_command.py | 202 +++----------------
 1 file changed, 30 insertions(+), 172 deletions(-)

diff --git a/forecast/test/test_clear_forecast_command.py b/forecast/test/test_clear_forecast_command.py
index 9cb3bbc1..3bf691c8 100644
--- a/forecast/test/test_clear_forecast_command.py
+++ b/forecast/test/test_clear_forecast_command.py
@@ -12,146 +12,62 @@
 
 class ClearForecastCommandNoArchiveTest(TestCase):
     def setUp(self):
-        self.out = StringIO()
         init_data = MonthlyFigureSetup()
         init_data.setup_forecast()
         init_data.setup_budget()
         self.current_year = get_current_financial_year()
 
-    def test_no_answer(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
+    def assertFiguresCount(self, should_exist=True):
+        count_assert = self.assertNotEqual if should_exist else self.assertEqual
+        count_assert(
+            BudgetMonthlyFigure.objects.filter(financial_year=self.current_year).count(),
             0,
         )
-        self.assertNotEqual(
+        count_assert(
             ForecastMonthlyFigure.objects.filter(
                 financial_year=self.current_year
             ).count(),
             0,
         )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        count_assert(FinancialCode.objects.all().count(), 0)
+
+    def test_no_answer(self):
+        self.assertFiguresCount()
         with captured_stdin() as stdin:
             stdin.write("n\n")
             stdin.seek(0)
             with self.assertRaises(CommandError):
                 call_command("clear_forecast")
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
 
     def test_yes_no_answer(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
         with captured_stdin() as stdin:
             stdin.write("y\n")
             stdin.write("n")
             stdin.seek(0)
             with self.assertRaises(CommandError):
                 call_command("clear_forecast")
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
 
     def test_yes_yes_answer(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
         with captured_stdin() as stdin:
             stdin.write("y\n")
             stdin.write("y")
             stdin.seek(0)
             call_command("clear_forecast")
-        self.assertEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount(False)
 
     def test_not_interactive(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
         with self.assertRaises(CommandError):
             call_command("clear_forecast", "--noinput")
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
 
 
 class ClearForecastCommandWithArchiveTest(TestCase):
     def setUp(self):
-        self.out = StringIO()
         init_data = MonthlyFigureSetup()
         init_data.setup_forecast()
         init_data.setup_budget()
@@ -161,96 +77,38 @@ def setUp(self):
             "archive_current_year",
         )
 
-    def test_no_answer(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
+    def assertFiguresCount(self, should_exist=True):
+        count_assert = self.assertNotEqual if should_exist else self.assertEqual
+        count_assert(
+            BudgetMonthlyFigure.objects.filter(financial_year=self.current_year).count(),
             0,
         )
-        self.assertNotEqual(
+        count_assert(
             ForecastMonthlyFigure.objects.filter(
                 financial_year=self.current_year
             ).count(),
             0,
         )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        count_assert(FinancialCode.objects.all().count(), 0)
+
+    def test_no_answer(self):
+        self.assertFiguresCount()
         with captured_stdin() as stdin:
             stdin.write("n\n")
             stdin.seek(0)
             with self.assertRaises(CommandError):
                 call_command("clear_forecast")
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
 
     def test_yes_answer(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
         with captured_stdin() as stdin:
             stdin.write("y")
             stdin.seek(0)
             call_command("clear_forecast")
-        self.assertEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount(False)
 
     def test_not_interactive(self):
-        self.assertNotEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertNotEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount()
         call_command("clear_forecast", "--noinput")
-        self.assertEqual(
-            BudgetMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(
-            ForecastMonthlyFigure.objects.filter(
-                financial_year=self.current_year
-            ).count(),
-            0,
-        )
-        self.assertEqual(FinancialCode.objects.all().count(), 0)
+        self.assertFiguresCount(False)

From d5124be58c01d7f1a0fcbd98844df077efb9141f Mon Sep 17 00:00:00 2001
From: Caitlin Barnard <caitlin@madetech.com>
Date: Mon, 18 Nov 2024 09:29:09 +0000
Subject: [PATCH 3/3] Formatting

---
 forecast/test/test_clear_forecast_command.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/forecast/test/test_clear_forecast_command.py b/forecast/test/test_clear_forecast_command.py
index 3bf691c8..7860d1c8 100644
--- a/forecast/test/test_clear_forecast_command.py
+++ b/forecast/test/test_clear_forecast_command.py
@@ -1,5 +1,3 @@
-from io import StringIO
-
 from django.core.management import call_command
 from django.core.management.base import CommandError
 from django.test import TestCase
@@ -20,7 +18,9 @@ def setUp(self):
     def assertFiguresCount(self, should_exist=True):
         count_assert = self.assertNotEqual if should_exist else self.assertEqual
         count_assert(
-            BudgetMonthlyFigure.objects.filter(financial_year=self.current_year).count(),
+            BudgetMonthlyFigure.objects.filter(
+                financial_year=self.current_year
+            ).count(),
             0,
         )
         count_assert(
@@ -80,7 +80,9 @@ def setUp(self):
     def assertFiguresCount(self, should_exist=True):
         count_assert = self.assertNotEqual if should_exist else self.assertEqual
         count_assert(
-            BudgetMonthlyFigure.objects.filter(financial_year=self.current_year).count(),
+            BudgetMonthlyFigure.objects.filter(
+                financial_year=self.current_year
+            ).count(),
             0,
         )
         count_assert(