Skip to content

Commit

Permalink
Fix get_users
Browse files Browse the repository at this point in the history
  • Loading branch information
satyaog committed Mar 27, 2024
1 parent ea499f8 commit fde7114
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sarc/ldap/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_users(query=None, query_options: dict | None = None, latest=True) -> lis
query_options = {}

if query is None:
return {}
query = {}

if latest:
query = {
Expand All @@ -69,7 +69,7 @@ def get_users(query=None, query_options: dict | None = None, latest=True) -> lis
]
}

results = users_collection().find_by(query, query_options)
results = users_collection().find_by(query, **query_options)

return list(results)

Expand Down
18 changes: 8 additions & 10 deletions tests/unittests/ldap/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,36 @@
({}, {}),
],
[
{"query":"q"},
{"kwarg1":1, "kwarg2":2},
{"query": "q"},
{"kwarg1": 1, "kwarg2": 2},
False,
None,
],
[
{"query":"q"},
{"query": "q"},
{},
True,
(
{
"$and": [
query_latest_records(),
{"query":"q"},
{"query": "q"},
]
},
{}
{},
),
],
]
],
)
def test_get_users(query, query_options, latest, expected, monkeypatch):
if expected is None:
expected = (query, query_options)

monkeypatch.setattr(
"sarc.ldap.api.config", lambda:MagicMock()
)
monkeypatch.setattr("sarc.ldap.api.config", lambda: MagicMock())
user_repository_mock = MagicMock()
user_repository_mock.find_by.return_value = tuple()
monkeypatch.setattr(
"sarc.ldap.api.UserRepository", lambda*_args,**_kwargs:user_repository_mock
"sarc.ldap.api.UserRepository", lambda *_args, **_kwargs: user_repository_mock
)
result = get_users(query, query_options, latest)
assert isinstance(result, list)
Expand Down

0 comments on commit fde7114

Please sign in to comment.