Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
fix more instances where old settings was referenced
Browse files Browse the repository at this point in the history
  • Loading branch information
Comeani committed Oct 17, 2023
1 parent a987356 commit 5f0f38a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 71 deletions.
4 changes: 2 additions & 2 deletions tests/account_logic/test_AccountServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_email_sent_for_expired(self, mock_locked_state, mock_send_message) -> N
lock_state = mock_locked_state.call_args.args[0]
self.assertTrue(lock_state, 'Account was not locked')

@patch.object(settings, "warning_days", (10,))
@patch.object(TestSettings, "warning_days", (10,))
def test_email_sent_for_warning_day(self, mock_send_message) -> None:
"""Test a warning email is sent if the account has reached an expiration warning limit"""

Expand All @@ -192,7 +192,7 @@ def test_email_sent_for_warning_day(self, mock_send_message) -> None:
sent_email = mock_send_message.call_args[0][0]
self.assertEqual(f'Your proposal expiry reminder for account: {self.account._account_name}', sent_email['subject'])

@patch.object(settings, "notify_levels", (1,)) # Ensure a notification is sent after small usage percentage
@patch.object(TestSettings, "notify_levels", (1,)) # Ensure a notification is sent after small usage percentage
@patch.object(SlurmAccount, "get_total_usage", lambda self: 100) # Ensure account usage is a reproducible value for testing
def test_email_sent_for_percentage(self, mock_send_message) -> None:
"""Test a warning email is sent if the account exceeds a certain usage percentage"""
Expand Down
2 changes: 1 addition & 1 deletion tests/account_logic/test_AdminServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ def test_unlocked_accounts_only_found(self) -> None:
# The unlocked account should be in the list of unlocked accounts, while the locked account should not
unlocked_accounts_by_cluster = self.admin_services.find_unlocked_account_names()
self.assertNotIn(self.slurm_account1.account_name, unlocked_accounts_by_cluster[TestSettings.test_cluster])
self.assertIn(self.slurm_account2.account_name, unlocked_accounts_by_cluster[settings.test_cluster])
self.assertIn(self.slurm_account2.account_name, unlocked_accounts_by_cluster[TestSettings.test_cluster])
38 changes: 19 additions & 19 deletions tests/account_logic/test_InvestmentServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def test_dates_are_modified(self) -> None:
new_start_date = old_investment.start_date + timedelta(days=5)
new_end_date = old_investment.end_date + timedelta(days=10)

InvestmentServices(settings.test_accounts[0]).modify_date(investment_id, start=new_start_date, end=new_end_date)
InvestmentServices(TestSettings.test_accounts[0]).modify_date(investment_id, start=new_start_date, end=new_end_date)

investment_query = select(Investment).join(Account) \
.where(Account.name == settings.test_accounts[0]) \
.where(Account.name == TestSettings.test_accounts[0]) \
.where(Investment.id == investment_id)

with DBConnection.session() as session:
Expand All @@ -136,7 +136,7 @@ def test_error_on_bad_dates(self) -> None:
"""Test a ``ValueError`` is raised when assigning chronologically wrong start/end dates"""

investment_query = select(Investment).join(Account) \
.where(Account.name == settings.test_accounts[0]) \
.where(Account.name == TestSettings.test_accounts[0]) \
.where(Investment.is_active)

with DBConnection.session() as session:
Expand All @@ -149,26 +149,26 @@ def test_error_on_bad_dates(self) -> None:

# No start or end date
self.assertFalse(
InvestmentServices(settings.test_accounts[0]).modify_date()
InvestmentServices(TestSettings.test_accounts[0]).modify_date()
)

# Start date after end date
with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).modify_date(start=bad_start_date, end=end_date)
InvestmentServices(TestSettings.test_accounts[0]).modify_date(start=bad_start_date, end=end_date)

# Start date after end date, providing start date alone
with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).modify_date(start=bad_start_date)
InvestmentServices(TestSettings.test_accounts[0]).modify_date(start=bad_start_date)

# End date before start date, providing end date alone
with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).modify_date(end=bad_end_date)
InvestmentServices(TestSettings.test_accounts[0]).modify_date(end=bad_end_date)

def test_error_on_bad_dates_with_id(self) -> None:
"""Test a ``ValueError`` is raised when assigning chronologically wrong start/end dates"""

investment_query = select(Investment).join(Account) \
.where(Account.name == settings.test_accounts[0]) \
.where(Account.name == TestSettings.test_accounts[0]) \
.where(Investment.is_active)

with DBConnection.session() as session:
Expand All @@ -181,18 +181,18 @@ def test_error_on_bad_dates_with_id(self) -> None:

# Attempt to modify date without specifying a date
self.assertFalse(
InvestmentServices(settings.test_accounts[0]).modify_date(investment_id)
InvestmentServices(TestSettings.test_accounts[0]).modify_date(investment_id)
)

# Start date after end date
with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).modify_date(
InvestmentServices(TestSettings.test_accounts[0]).modify_date(
investment_id,
bad_start_date, end_date)

# End date before start date
with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).modify_date(
InvestmentServices(TestSettings.test_accounts[0]).modify_date(
investment_id,
start_date, bad_end_date)

Expand All @@ -205,7 +205,7 @@ def test_sus_are_added(self) -> None:

inv_id = 1
sus_to_add = 1000
InvestmentServices(settings.test_accounts[0]).add_sus(inv_id, sus_to_add)
InvestmentServices(TestSettings.test_accounts[0]).add_sus(inv_id, sus_to_add)

inv_sus_query = select(Investment.service_units).where(Investment.id == inv_id)
with DBConnection.session() as session:
Expand All @@ -215,7 +215,7 @@ def test_sus_are_added(self) -> None:
def test_error_on_negative_sus(self) -> None:
"""Test a ``ValueError`` is raised when assigning negative service units"""

account = InvestmentServices(settings.test_accounts[0])
account = InvestmentServices(TestSettings.test_accounts[0])
with self.assertRaises(ValueError):
account.add_sus(1, -1)

Expand All @@ -230,7 +230,7 @@ def test_account_inserted_AccountServices(self) -> None:
"""Test the account has an entry in the DB upon InvestmentServices object creation"""

# Create an account services object for an existing SLURM account
acct = InvestmentServices(settings.test_accounts[0])
acct = InvestmentServices(TestSettings.test_accounts[0])

with DBConnection.session() as session:
# Query the DB for the account
Expand All @@ -249,7 +249,7 @@ def test_sus_are_subtracted(self) -> None:

inv_id = 1
sus_to_subtract = 100
InvestmentServices(settings.test_accounts[0]).subtract_sus(inv_id, sus_to_subtract)
InvestmentServices(TestSettings.test_accounts[0]).subtract_sus(inv_id, sus_to_subtract)

inv_sus_query = select(Investment.service_units).where(Investment.id == inv_id)
with DBConnection.session() as session:
Expand All @@ -259,7 +259,7 @@ def test_sus_are_subtracted(self) -> None:
def test_error_on_negative_sus(self) -> None:
"""Test a ``ValueError`` is raised when assigning negative service units"""

account = InvestmentServices(settings.test_accounts[0])
account = InvestmentServices(TestSettings.test_accounts[0])
with self.assertRaises(ValueError):
account.subtract_sus(1, -1)

Expand All @@ -270,15 +270,15 @@ def test_error_on_over_subtract(self) -> None:
"""Test for a ``ValueError`` if more service units are subtracted than available"""

with self.assertRaises(ValueError):
InvestmentServices(settings.test_accounts[0]).subtract_sus(1, self.num_inv_sus + 1000)
InvestmentServices(TestSettings.test_accounts[0]).subtract_sus(1, self.num_inv_sus + 1000)


class AdvanceInvestmentSus(ProposalSetup, InvestmentSetup, TestCase):
"""Tests for the withdrawal of service units from a single investment"""

def setUp(self) -> None:
super().setUp()
self.account = InvestmentServices(settings.test_accounts[0])
self.account = InvestmentServices(TestSettings.test_accounts[0])
self.inv_id = self.account._get_active_investment_id()

def test_investment_is_advanced(self) -> None:
Expand Down Expand Up @@ -323,7 +323,7 @@ def setUp(self) -> None:
"""Delete any investments that may already exist for the test account"""

super().setUp()
self.account = InvestmentServices(settings.test_accounts[0])
self.account = InvestmentServices(TestSettings.test_accounts[0])

def test_error_on_delete(self) -> None:
"""Test for a ``MissingInvestmentError`` error when deleting a missing investment"""
Expand Down
28 changes: 14 additions & 14 deletions tests/account_logic/test_ProposalServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_error_on_negative_sus(self) -> None:
"""Test a ``ValueError`` is raised when assigning negative service units"""

with self.assertRaises(ValueError):
self.account.add_sus(**{settings.test_cluster: -1})
self.account.add_sus(**{TestSettings.test_cluster: -1})


class SetupDBAccountEntry(TestCase):
Expand All @@ -163,7 +163,7 @@ def test_account_inserted_AccountServices(self) -> None:
"""Test the account has an entry in the DB upon InvestmentServices object creation"""

# Create an account services object for an existing SLURM account
acct = ProposalServices(settings.test_accounts[0])
acct = ProposalServices(TestSettings.test_accounts[0])

with DBConnection.session() as session:
# Query the DB for the account
Expand All @@ -180,7 +180,7 @@ class SubtractSus(ProposalSetup, TestCase):

def setUp(self) -> None:
super().setUp()
self.account = ProposalServices(settings.test_accounts[0])
self.account = ProposalServices(TestSettings.test_accounts[0])

def test_sus_are_subtracted(self) -> None:
"""Test SUs are removed from the proposal"""
Expand All @@ -189,7 +189,7 @@ def test_sus_are_subtracted(self) -> None:
original_sus = session.execute(sus_query).scalars().first()

sus_to_subtract = 1000
self.account.subtract_sus(**{settings.test_cluster: sus_to_subtract})
self.account.subtract_sus(**{TestSettings.test_cluster: sus_to_subtract})

with DBConnection.session() as session:
new_sus = session.execute(sus_query).scalars().first()
Expand All @@ -205,21 +205,21 @@ def test_error_on_negative_sus(self) -> None:
"""Test a ``ValueError`` is raised when assigning negative service units"""

with self.assertRaises(ValueError):
self.account.subtract_sus(**{settings.test_cluster: -1})
self.account.subtract_sus(**{TestSettings.test_cluster: -1})

def test_error_on_over_subtraction(self) -> None:
"""Test a value error is raised for subtraction resulting in negative sus"""

with self.assertRaises(ValueError):
self.account.subtract_sus(**{settings.test_cluster: self.num_proposal_sus + 100})
self.account.subtract_sus(**{TestSettings.test_cluster: self.num_proposal_sus + 100})


class MissingProposalErrors(EmptyAccountSetup, TestCase):
"""Tests for errors when manipulating an account that does not have a proposal"""

def setUp(self) -> None:
super().setUp()
self.account = ProposalServices(settings.test_accounts[0])
self.account = ProposalServices(TestSettings.test_accounts[0])

def test_error_on_delete(self) -> None:
"""Test for a ``MissingProposalError`` error when deleting without a proposal ID"""
Expand All @@ -237,27 +237,27 @@ def test_error_on_add(self) -> None:
"""Test a ``MissingProposalError`` error is raised when adding to a missing proposal"""

with self.assertRaises(MissingProposalError):
self.account.add_sus(**{settings.test_cluster: 1})
self.account.add_sus(**{TestSettings.test_cluster: 1})

def test_error_on_subtract(self) -> None:
"""Test a ``MissingProposalError`` error is raised when subtracting from a missing proposal"""

with self.assertRaises(MissingProposalError):
self.account.subtract_sus(**{settings.test_cluster: 1})
self.account.subtract_sus(**{TestSettings.test_cluster: 1})


class PreventOverlappingProposals(EmptyAccountSetup, TestCase):
"""Tests to ensure proposals cannot overlap in time"""

def setUp(self) -> None:
super().setUp()
self.account = ProposalServices(settings.test_accounts[0])
self.account = ProposalServices(TestSettings.test_accounts[0])

def test_neighboring_proposals_are_allowed(self):
"""Test that proposals with neighboring durations are allowed"""

self.account.create(start=TODAY, end=TOMORROW, **{settings.test_cluster: 100})
self.account.create(start=TOMORROW, end=DAY_AFTER_TOMORROW, **{settings.test_cluster: 100})
self.account.create(start=TODAY, end=TOMORROW, **{TestSettings.test_cluster: 100})
self.account.create(start=TOMORROW, end=DAY_AFTER_TOMORROW, **{TestSettings.test_cluster: 100})

def test_error_on_proposal_creation_same_start(self):
"""Test new proposals are not allowed to overlap with existing proposals"""
Expand All @@ -283,8 +283,8 @@ def test_error_on_proposal_creation_default_dates(self):
def test_error_on_proposal_modification(self):
"""Test existing proposals can not be modified to overlap with other proposals"""

self.account.create(start=YESTERDAY, end=TOMORROW, **{settings.test_cluster: 100})
self.account.create(start=DAY_AFTER_TOMORROW, end=DAY_AFTER_TOMORROW+timedelta(days=2), **{settings.test_cluster: 100})
self.account.create(start=YESTERDAY, end=TOMORROW, **{TestSettings.test_cluster: 100})
self.account.create(start=DAY_AFTER_TOMORROW, end=DAY_AFTER_TOMORROW+timedelta(days=2), **{TestSettings.test_cluster: 100})

with self.assertRaises(ProposalExistsError):
self.account.modify_date(end=DAY_AFTER_TOMORROW)
2 changes: 1 addition & 1 deletion tests/cli/parsers/test_AdminParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_no_arguments(self) -> None:
def test_single_clusters_argument(self) -> None:
"""Test the ``--cluster`` argument accepts at least one cluster name"""

self.assert_parser_matches_func_signature(AdminParser(), f'list_locked --cluster {test_cluster}')
self.assert_parser_matches_func_signature(AdminParser(), f'list_locked --cluster {TEST_CLUSTER}')

# Test the clusters are parsed into the `cluster` attribute
args = AdminParser().parse_args(['list_locked', '--cluster', TEST_CLUSTER])
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/parsers/test_InvestmentParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def test_invalid_date_format(self) -> None:

# Create an investment using a start date with the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
InvestmentParser().parse_args([f'create', TEST_ACCOUNT, '--sus', '100', '--start', '09/01/2500'])
InvestmentParser().parse_args([f'create', TEST_ACCOUNT, '--sus', '100', '--start', '09/01/25'])

# Create an investment using an end date with the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
InvestmentParser().parse_args([f'create', TEST_ACCOUNT, '--sus', '100', '--end', '09/01/2500'])
InvestmentParser().parse_args([f'create', TEST_ACCOUNT, '--sus', '100', '--end', '09/01/25'])


class Delete(TestCase, CLIAsserts):
Expand Down Expand Up @@ -275,11 +275,11 @@ def test_incorrect_date_format(self) -> None:

# Modify the start date using the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
InvestmentParser().parse_args(['create', TEST_ACCOUNT, '--start', '09/01/2500'])
InvestmentParser().parse_args(['create', TEST_ACCOUNT, '--start', '09/01/25'])

# Modify the end date using the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
InvestmentParser().parse_args(['create', TEST_ACCOUNT, '--id', '0', '--start', '09/01/2500'])
InvestmentParser().parse_args(['create', TEST_ACCOUNT, '--id', '0', '--start', '09/01/25'])


class Advance(TestCase, CLIAsserts):
Expand Down
12 changes: 6 additions & 6 deletions tests/cli/parsers/test_ProposalParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def test_invalid_date_format(self) -> None:

# Create a proposal using a start date with the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
ProposalParser().parse_args([f'create', TEST_ACCOUNT, f'--{TEST_CLUSTER}', '100', '--start', '09/01/2500'])
ProposalParser().parse_args([f'create', TEST_ACCOUNT, f'--{TEST_CLUSTER}', '100', '--start', '09/01/25'])

# Create a proposal using an end date with the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
ProposalParser().parse_args([f'create', TEST_ACCOUNT, f'--{TEST_CLUSTER}', '100', '--end', '09/01/2500'])
ProposalParser().parse_args([f'create', TEST_ACCOUNT, f'--{TEST_CLUSTER}', '100', '--end', '09/01/25'])


class Delete(CLIAsserts, TestCase):
Expand Down Expand Up @@ -194,9 +194,9 @@ class Modify(TestCase, CLIAsserts):
"""Test the ``modify`` subparser"""

start_date = datetime.now()
start_date_str = start_date.strftime(settings.date_format)
start_date_str = start_date.strftime(TestSettings.date_format)
end_date = start_date + timedelta(days=180)
end_date_str = end_date.strftime(settings.date_format)
end_date_str = end_date.strftime(TestSettings.date_format)

def test_modify_active_proposal(self) -> None:
"""Test changing the dates of the currently active proposal"""
Expand Down Expand Up @@ -246,8 +246,8 @@ def test_incorrect_date_format(self) -> None:

# Modify the start date using the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
ProposalParser().parse_args(['create', TEST_ACCOUNT, '--start', '09/01/2500'])
ProposalParser().parse_args(['create', TEST_ACCOUNT, '--start', '09/01/25'])

# Modify the end date using the wrong format
with self.assertRaisesRegex(SystemExit, 'Could not parse the given date'):
ProposalParser().parse_args(['create', TEST_ACCOUNT, '--id', '0', '--start', '09/01/2500'])
ProposalParser().parse_args(['create', TEST_ACCOUNT, '--id', '0', '--start', '09/01/25'])
Loading

0 comments on commit 5f0f38a

Please sign in to comment.