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

Add tests for overview of alert profiles page #2741

Merged
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
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
Loading