Skip to content

Commit dca7dd3

Browse files
committed
test(setup): read the password tests' settings without saving them
The trial-site password tests changed System Settings with change_settings, which saves the document. Saving needs a language and a time zone, and the CI site never ran the setup wizard, so it has neither and the three tests failed with MandatoryError. They now patch what get_system_settings returns instead.
1 parent 5f1d7b0 commit dca7dd3

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎lms/tests/api/test_onboarding.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,28 @@ def tearDown(self):
118118
frappe.set_user("Administrator")
119119
super().tearDown()
120120

121+
def system_settings(self, **values):
122+
"""System Settings read as these values, without saving them: saving needs a language and
123+
time zone, which a CI site that never ran the setup wizard does not have."""
124+
read = frappe.get_system_settings
125+
return patch(
126+
"frappe.get_system_settings",
127+
side_effect=lambda key: values[key] if key in values else read(key),
128+
)
129+
121130
def as_trial_site(self):
122131
return patch.dict(
123132
frappe.conf, {"pilot_endpoint": "https://pilot.example.com", "pilot_auth_token": "t"}
124133
)
125134

126135
def test_a_trial_owner_without_a_password_is_asked_for_one(self):
127-
with self.as_trial_site(), self.change_settings("System Settings", login_with_email_link=1):
136+
with self.as_trial_site(), self.system_settings(login_with_email_link=1):
128137
self.assertTrue(needs_password_setup(self.owner.name))
129138

130139
def test_the_password_step_saves_on_a_trial_site(self):
131140
from frappe.utils.password import check_password
132141

133-
with self.as_trial_site(), self.change_settings("System Settings", login_with_email_link=1):
142+
with self.as_trial_site(), self.system_settings(login_with_email_link=1):
134143
frappe.set_user(self.owner.name)
135144
set_first_password("Eastern_43A1W")
136145
frappe.set_user("Administrator")
@@ -151,7 +160,7 @@ def test_a_user_with_a_password_cannot_use_it(self):
151160

152161
def test_not_asked_where_a_password_cannot_sign_in(self):
153162
self.assertFalse(needs_password_setup("Administrator"))
154-
with self.change_settings("System Settings", disable_user_pass_login=1):
163+
with self.system_settings(disable_user_pass_login=1):
155164
self.assertFalse(needs_password_setup(self.owner.name))
156165
self.owner.append("social_logins", {"provider": "google", "userid": "1234"})
157166
self.owner.save()

0 commit comments

Comments
 (0)