Skip to content

Commit

Permalink
remove attribute to fake session, remove real db_session ref?
Browse files Browse the repository at this point in the history
  • Loading branch information
npalaska committed Feb 21, 2023
1 parent a9514ba commit 7394564
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/pbench/test/unit/server/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/pbench/test/unit/server/database/test_users_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/pbench/test/unit/server/test_user_management_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7394564

Please sign in to comment.