mirror of
https://github.com/ae-utbm/sith.git
synced 2026-01-11 21:40:08 +00:00
test UserPreferencesView
This commit is contained in:
@@ -427,6 +427,19 @@ class TestUserQuerySetViewableBy:
|
|||||||
assert not viewable.exists()
|
assert not viewable.exists()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_user_preferences(client: Client):
|
||||||
|
user = subscriber_user.make()
|
||||||
|
client.force_login(user)
|
||||||
|
url = reverse("core:user_prefs", kwargs={"user_id": user.id})
|
||||||
|
response = client.get(url)
|
||||||
|
assert response.status_code == 200
|
||||||
|
response = client.post(url, {"notify_on_click": "true"})
|
||||||
|
assertRedirects(response, url)
|
||||||
|
user.preferences.refresh_from_db()
|
||||||
|
assert user.preferences.notify_on_click is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_user_stats(client: Client):
|
def test_user_stats(client: Client):
|
||||||
user = subscriber_user.make()
|
user = subscriber_user.make()
|
||||||
|
|||||||
@@ -476,10 +476,10 @@ class UserPreferencesView(UserTabsMixin, UseFragmentsMixin, CanEditMixin, Update
|
|||||||
current_tab = "prefs"
|
current_tab = "prefs"
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
return super().get_form_kwargs() | {"instance": self.object.preferences}
|
||||||
pref = self.object.preferences
|
|
||||||
kwargs.update({"instance": pref})
|
def get_success_url(self):
|
||||||
return kwargs
|
return self.request.path
|
||||||
|
|
||||||
def get_fragment_context_data(self) -> dict[str, SafeString]:
|
def get_fragment_context_data(self) -> dict[str, SafeString]:
|
||||||
# Avoid cyclic import error
|
# Avoid cyclic import error
|
||||||
|
|||||||
Reference in New Issue
Block a user