From 7394564b7d156e4e2a5323de0e8f2f675278ac9a Mon Sep 17 00:00:00 2001 From: npalaska Date: Mon, 20 Feb 2023 21:52:43 -0500 Subject: [PATCH] remove attribute to fake session, remove real db_session ref? --- lib/pbench/test/unit/server/database/__init__.py | 4 ++++ lib/pbench/test/unit/server/database/test_users_db.py | 10 +++++----- .../test/unit/server/test_user_management_cli.py | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/pbench/test/unit/server/database/__init__.py b/lib/pbench/test/unit/server/database/__init__.py index 1ed9fd94d8..59e837258c 100644 --- a/lib/pbench/test/unit/server/database/__init__.py +++ b/lib/pbench/test/unit/server/database/__init__.py @@ -270,6 +270,10 @@ def reset_context(self): self.raise_on_commit = None __class__.throw_query = False + def remove(self): + """Mocks the db session remove method""" + self.reset_context() + def query(self, *entities, **kwargs) -> FakeQuery: """Perform a mocked query on the session, setting up the query context and returning it diff --git a/lib/pbench/test/unit/server/database/test_users_db.py b/lib/pbench/test/unit/server/database/test_users_db.py index 289ecdcee4..8f48234da4 100644 --- a/lib/pbench/test/unit/server/database/test_users_db.py +++ b/lib/pbench/test/unit/server/database/test_users_db.py @@ -153,9 +153,9 @@ def test_construct_duplicate(self, fake_db): (3, {"user": {"company": {"location": "Westford"}}}), ], ) - def test_user_update(self, db_session, fake_db, case, data): + def test_user_update(self, fake_db, case, data): """Test updating user profile with different types of kwargs""" - TestUsers.add_dummy_user(db_session) + TestUsers.add_dummy_user(fake_db) user = User.query(id=1) valid_dict = user.form_valid_dict(**data) user.update(new_profile=valid_dict) @@ -178,9 +178,9 @@ def test_user_update(self, db_session, fake_db, case, data): "data", [{"server.key": "value"}, {"server.role": ["value"]}, {"server": ""}], ) - def test_user_update_bad_key(self, db_session, fake_db, data): + def test_user_update_bad_key(self, fake_db, data): """Test updating user with non-updatable key:value pair""" - TestUsers.add_dummy_user(db_session) + TestUsers.add_dummy_user(fake_db) user = User.query(id=1) with pytest.raises( UserError, @@ -216,7 +216,7 @@ def test_user_delete(self, fake_db): user.delete() self.session.check_session(queries=0, filters=[], committed=[]) - def test_delete_exception(self): + def test_delete_exception(self, fake_db): """Test exception raised during the delete operation""" user = User( oidc_id=12345, diff --git a/lib/pbench/test/unit/server/test_user_management_cli.py b/lib/pbench/test/unit/server/test_user_management_cli.py index 899e04b5d9..f48b007408 100644 --- a/lib/pbench/test/unit/server/test_user_management_cli.py +++ b/lib/pbench/test/unit/server/test_user_management_cli.py @@ -137,6 +137,7 @@ def test_user_creation_with_invalid_role(server_config): @staticmethod def test_valid_user_delete(monkeypatch, server_config): + monkeypatch.setattr(User, "query", mock_valid_query) monkeypatch.setattr(User, "delete", mock_valid_delete) runner = CliRunner(mix_stderr=False)