Skip to content

Commit

Permalink
Merge branch '5.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
lunkwill42 committed Nov 15, 2023
2 parents 624f671 + acd96ec commit 04daaaf
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -1929,7 +1929,7 @@ def filter_group_remove(request):
time_periods = TimePeriod.objects.filter(
alert_subscriptions__in=subscriptions
)
profiles = AlertProfile.objects.filter(timeperiod__in=time_periods)
profiles = AlertProfile.objects.filter(time_periods__in=time_periods)
warnings = []

try:
Expand Down
74 changes: 74 additions & 0 deletions tests/integration/web/alertprofiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AlertSender,
Expression,
Filter,
FilterGroup,
MatchField,
Operator,
)
Expand Down Expand Up @@ -125,6 +126,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 +161,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 Expand Up @@ -556,6 +594,35 @@ def test_alertprofiles_add_invalid_phone_number_should_fail(client):
assert "Not a valid phone number." in smart_str(response.content)


def test_alertprofiles_confirm_remove_filter_group(db, client, dummy_filter_group):
url = reverse('alertprofiles-filter_groups-remove')
response = client.post(
url,
follow=True,
data={
'confirm': '1',
'element': [dummy_filter_group.id],
},
)
assert response.status_code == 200
assert not FilterGroup.objects.filter(pk=dummy_filter_group.pk).exists()


def test_alertprofiles_remove_filter_group(db, client, dummy_filter_group):
url = reverse('alertprofiles-filter_groups-remove')
response = client.post(
url,
follow=True,
data={
'filter_group': [dummy_filter_group.id],
},
)
assert response.status_code == 200
assert "Confirm deletion" in smart_str(response.content)
assert dummy_filter_group.name in smart_str(response.content)
assert FilterGroup.objects.filter(pk=dummy_filter_group.pk).count() == 1


#
# fixtures and helpers
#
Expand Down Expand Up @@ -583,3 +650,10 @@ def dummy_filter():
filtr = Filter(name="dummy", owner=Account.objects.get(id=Account.ADMIN_ACCOUNT))
filtr.save()
return filtr


@pytest.fixture(scope="function")
def dummy_filter_group(admin_account):
filter_group = FilterGroup(name="dummy_group", owner=admin_account)
filter_group.save()
return filter_group

0 comments on commit 04daaaf

Please sign in to comment.