Skip to content

Commit

Permalink
Merge pull request #2732 from johannaengland/bugfix/deactivate-alert-…
Browse files Browse the repository at this point in the history
…profile

Fix (de)activating alert profiles
  • Loading branch information
johannaengland authored Nov 13, 2023
2 parents ccb83d1 + c08f762 commit aafdcb6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/nav/web/alertprofiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def profile_save(request):
def profile_remove(request):
"""Removes a profile"""
post = request.POST.copy()
for data in post:
for data in request.POST:
if data.find("=") != -1:
attr, value = data.split("=")
del post[data]
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/web/alertprofiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ def test_alertprofiles_activate_profile(db, client, dummy_profile):
assert preference.active_profile == dummy_profile


def test_alertprofiles_activate_profile_with_info_in_key(db, client, dummy_profile):
# remarkably, activation/deactivation of profiles belong in the remove view!
url = reverse('alertprofiles-profile-remove')
response = client.post(
url,
follow=True,
data={
f'activate={dummy_profile.id}': ["Activate"],
},
)
assert response.status_code == 200
assert "Active profile set" in smart_str(response.content)
assert dummy_profile.name in smart_str(response.content)
preference = AlertPreference.objects.get(account=dummy_profile.account)
assert preference.active_profile == dummy_profile


def test_alertprofiles_deactivate_profile(db, client, activated_dummy_profile):
# remarkably, activation/deactivation of profiles belong in the remove view!
url = reverse('alertprofiles-profile-remove')
Expand All @@ -143,6 +160,26 @@ def test_alertprofiles_deactivate_profile(db, client, activated_dummy_profile):
assert preference.active_profile is None


def test_alertprofiles_deactivate_profile_with_info_in_key(
db, client, activated_dummy_profile
):
# remarkably, activation/deactivation of profiles belong in the remove view!
url = reverse('alertprofiles-profile-remove')
response = client.post(
url,
follow=True,
data={
f'deactivate={activated_dummy_profile.id}': ["Deactivate"],
},
)
assert response.status_code == 200
print(type(response.content))
assert "was deactivated" in smart_str(response.content)
assert activated_dummy_profile.name in smart_str(response.content)
preference = AlertPreference.objects.get(account=activated_dummy_profile.account)
assert preference.active_profile is None


def test_alertprofiles_add_private_filter_should_succeed(client):
"""Tests that an admin can POST a new private filter"""
url = reverse("alertprofiles-filters-save")
Expand Down

0 comments on commit aafdcb6

Please sign in to comment.