-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2741 from johannaengland/tests/alertprofiles/add-…
…overview-test Add tests for overview of alert profiles page
- Loading branch information
Showing
1 changed file
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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="[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) | ||
|