Skip to content

Commit

Permalink
Add tests for overview of alert profiles page
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Nov 17, 2023
1 parent 54449ed commit ba90a00
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion tests/integration/web/alertprofiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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="[email protected]",
)
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)
Expand Down

0 comments on commit ba90a00

Please sign in to comment.