tests/e2e: improve assertCountEqual diff (#6261)

* tests/e2e: improve assertCountEqual diff

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-07-17 11:47:28 +02:00 committed by GitHub
parent 27879d9d95
commit db4f61549d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 99 additions and 92 deletions

View File

@ -226,15 +226,13 @@ class TestProviderLDAP(SeleniumTestCase):
search_scope=SUBTREE,
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES],
)
response: dict = _connection.response
response: list = _connection.response
# Remove raw_attributes to make checking easier
for obj in response:
del obj["raw_attributes"]
del obj["raw_dn"]
o_user = outpost.user
self.assertCountEqual(
response,
[
expected = [
{
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
"attributes": {
@ -321,8 +319,17 @@ class TestProviderLDAP(SeleniumTestCase):
},
"type": "searchResEntry",
},
],
)
]
self.assert_list_dict_equal(expected, response)
def assert_list_dict_equal(self, expected: list[dict], actual: list[dict], match_key="dn"):
"""Assert a list of dictionaries is identical, ignoring the ordering of items"""
self.assertEqual(len(expected), len(actual))
for res_item in actual:
all_matching = [x for x in expected if x[match_key] == res_item[match_key]]
self.assertEqual(len(all_matching), 1)
matching = all_matching[0]
self.assertDictEqual(res_item, matching)
@retry()
@apply_blueprint(
@ -385,14 +392,13 @@ class TestProviderLDAP(SeleniumTestCase):
search_scope=SUBTREE,
attributes=["cn"],
)
response: dict = _connection.response
response: list = _connection.response
# Remove raw_attributes to make checking easier
for obj in response:
del obj["raw_attributes"]
del obj["raw_dn"]
o_user = outpost.user
self.assertCountEqual(
response,
self.assert_list_dict_equal(
[
{
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
@ -416,4 +422,5 @@ class TestProviderLDAP(SeleniumTestCase):
"type": "searchResEntry",
},
],
response,
)