Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change selenium docker image and refactor tests #545

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)