Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix related name when deleting filter group in alert profiles #2729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/nav/web/alertprofiles/views.py
Original file line number Diff line number Diff line change
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
37 changes: 37 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 @@ -531,6 +532,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 @@ -558,3 +588,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
Loading