Skip to content

Commit

Permalink
Change selenium docker image and refactor tests (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard authored Nov 18, 2024
1 parent 86f0f58 commit c8fc4c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 169 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ services:
- "6379:6379"

chrome:
image: selenium/standalone-chrome:latest
image: selenium/standalone-chromium:latest
shm_size: 2gb
depends_on:
- web
Expand Down
196 changes: 28 additions & 168 deletions forecast/test/test_clear_forecast_command.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,146 +10,64 @@

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(
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()
Expand All @@ -161,96 +77,40 @@ def setUp(self):
"archive_current_year",
)

def test_no_answer(self):
self.assertNotEqual(
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)

0 comments on commit c8fc4c3

Please sign in to comment.