Skip to content

Commit

Permalink
test: Get site_user name instead of guessing that it will be 'default'
Browse files Browse the repository at this point in the history
  • Loading branch information
bellisk committed Jul 1, 2024
1 parent 3b4673b commit 82090fe
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ckanext/switzerland/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class TestForceResetPasswords(OgdchFunctionalTestBase, SmtpServerHarness):
site_user = ""

@classmethod
def setup_class(cls):
super(TestForceResetPasswords, cls).setup_class()
Expand All @@ -29,6 +31,8 @@ def setup_class(cls):

def setup(self):
super(TestForceResetPasswords, self).setup()
self.site_user = self._get_context()["user"]

for n in range(3):
user = {
"name": "user{}".format(str(n)),
Expand All @@ -49,7 +53,7 @@ def test_reset_single_user_password(self):
)

initial_other_user_passwords = {}
for user in ["user1", "user2", "default"]:
for user in ["user1", "user2", self.site_user]:
initial_other_user_passwords[user] = tk.get_action("user_show")(
self._get_context(),
{"id": user, "include_password_hash": True}
Expand All @@ -66,7 +70,7 @@ def test_reset_single_user_password(self):
{"id": "user1", "include_password_hash": True}
)
other_user_passwords_after_reset = {}
for user in ["user1", "user2", "default"]:
for user in ["user1", "user2", self.site_user]:
other_user_passwords_after_reset[user] = tk.get_action("user_show")(
self._get_context(),
{"id": user, "include_password_hash": True}
Expand Down Expand Up @@ -120,8 +124,8 @@ def test_reset_multiple_user_passwords(self):
)["password_hash"]

assert_equal(
initial_user_passwords["default"],
user_passwords_after_update["default"],
initial_user_passwords[self.site_user],
user_passwords_after_update[self.site_user],
"The user at position 0 in the list should not have been updated",
)
assert_not_equal(
Expand All @@ -143,8 +147,10 @@ def test_reset_multiple_user_passwords(self):
def test_own_password_is_not_reset_single_user_password(self):
context = self._get_context()
context["ignore_auth"] = False
site_user = context["user"]

result = tk.get_action("ogdch_force_reset_passwords")(
context, {"user": "default"}
context, {"user": self.site_user}
)

assert_equal(
Expand All @@ -154,7 +160,7 @@ def test_own_password_is_not_reset_single_user_password(self):
)
assert_equal(
"Not resetting password for the signed-in user default",
result["errors"]["default"],
result["errors"][self.site_user],
"Expected error when resetting password for the user we are using to call the action"
)

Expand All @@ -172,7 +178,7 @@ def test_own_password_is_not_reset_multiple_user_passwords(self):
"Password should have been reset for the user we are not using to call the action"
)
assert_equal(
{"default": "Not resetting password for the signed-in user default"},
{self.site_user: "Not resetting password for the signed-in user default"},
result["errors"],
"Expected error when resetting password for the user we are using to call the action"
)
Expand Down

0 comments on commit 82090fe

Please sign in to comment.