From ba90a00f1bb27f88e3abb6135e12136bb87f26bb Mon Sep 17 00:00:00 2001 From: Johanna England Date: Wed, 15 Nov 2023 13:50:16 +0100 Subject: [PATCH] Add tests for overview of alert profiles page --- tests/integration/web/alertprofiles_test.py | 56 ++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/integration/web/alertprofiles_test.py b/tests/integration/web/alertprofiles_test.py index ee04d388dc..2e1bcd9bc2 100644 --- a/tests/integration/web/alertprofiles_test.py +++ b/tests/integration/web/alertprofiles_test.py @@ -9,16 +9,17 @@ from django.urls import reverse from nav.compatibility import smart_str from nav.models.profiles import ( - Account, AlertAddress, AlertPreference, AlertProfile, AlertSender, + AlertSubscription, Expression, Filter, FilterGroup, MatchField, Operator, + TimePeriod, ) from nav.web.alertprofiles.views import set_active_profile @@ -48,6 +49,28 @@ def test_alertprofiles_view(client, view): assert "admin" in smart_str(response.content) +class TestsOverview: + def test_show_active_profile(self, db, client, activated_dummy_profile): + response = client.get(reverse('alertprofiles-overview')) + + assert response.status_code == 200 + assert activated_dummy_profile.name in smart_str(response.content) + + def test_show_subscriptions( + self, + db, + client, + dummy_alert_address, + dummy_filter_group, + dummy_alert_subscription, + ): + response = client.get(reverse('alertprofiles-overview')) + + assert response.status_code == 200 + assert dummy_alert_address.address in smart_str(response.content) + assert str(dummy_filter_group) in smart_str(response.content) + + class TestsAlertProfiles: def test_profile_with_nonascii_name_should_be_saved(self, db, admin_account): factory = RequestFactory() @@ -655,6 +678,37 @@ def activated_dummy_profile(dummy_profile): return dummy_profile +@pytest.fixture(scope="function") +def dummy_time_period(activated_dummy_profile): + time_period = TimePeriod(profile=activated_dummy_profile) + time_period.save() + return time_period + + +@pytest.fixture(scope="function") +def dummy_alert_address(admin_account): + alert_address = AlertAddress( + account=admin_account, + type=AlertSender.objects.get(name=AlertSender.SMS), + address="admin@example.com", + ) + alert_address.save() + return alert_address + + +@pytest.fixture(scope="function") +def dummy_alert_subscription( + dummy_alert_address, dummy_time_period, dummy_filter_group +): + alert_subscription = AlertSubscription( + alert_address=dummy_alert_address, + time_period=dummy_time_period, + filter_group=dummy_filter_group, + ) + alert_subscription.save() + return alert_subscription + + @pytest.fixture(scope="function") def dummy_filter(admin_account): filtr = Filter(name="dummy", owner=admin_account)