Skip to content

Commit

Permalink
Use db fixture in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Sep 5, 2023
1 parent 7529721 commit ff071d7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/integration/models/alert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
import pytest


def test_delete_alert_subscription(alert, alertsub, account_alert_queue):
def test_delete_alert_subscription(db, alert, alertsub, account_alert_queue):
alertsub.delete()
assert not AccountAlertQueue.objects.filter(pk=account_alert_queue.pk).exists()
assert not AlertQueue.objects.filter(pk=alert.pk).exists()


def test_sending_alert_to_alert_address_with_empty_address_will_raise_error(
alert_address, alert, alertsub
db, alert_address, alert, alertsub
):
with pytest.raises(InvalidAlertAddressError):
alert_address.send(alert, alertsub)


def test_sending_alert_to_alert_address_with_invalid_address_will_raise_error(
alert_address, alert, alertsub
db, alert_address, alert, alertsub
):
alert_address.address = "abc"
alert_address.save()
Expand All @@ -39,19 +39,19 @@ def test_sending_alert_to_alert_address_with_invalid_address_will_raise_error(


def test_sending_alert_to_alert_address_with_invalid_address_will_delete_alert_and_fail(
alert, account_alert_queue
db, alert, account_alert_queue
):
assert not account_alert_queue.send()
assert not AlertQueue.objects.filter(pk=alert.pk).exists()


@pytest.fixture
def account():
def account(db):
return Account.objects.get(pk=Account.ADMIN_ACCOUNT)


@pytest.fixture
def alert_address(account):
def alert_address(db, account):
addr = AlertAddress(
account=account,
type=AlertSender.objects.get(name=AlertSender.SMS),
Expand All @@ -63,7 +63,7 @@ def alert_address(account):


@pytest.fixture
def alert_profile(account):
def alert_profile(db, account):
profile = AlertProfile(account=account)
profile.save()
yield profile
Expand All @@ -72,7 +72,7 @@ def alert_profile(account):


@pytest.fixture
def time_period(alert_profile):
def time_period(db, alert_profile):
time_period = TimePeriod(profile=alert_profile)
time_period.save()
yield time_period
Expand All @@ -81,7 +81,7 @@ def time_period(alert_profile):


@pytest.fixture
def alertsub(alert_address, time_period):
def alertsub(db, alert_address, time_period):
alertsub = AlertSubscription(
alert_address=alert_address,
time_period=time_period,
Expand All @@ -94,7 +94,7 @@ def alertsub(alert_address, time_period):


@pytest.fixture
def alert():
def alert(db):
alert = AlertQueue(
source=Subsystem.objects.first(), time=datetime.now(), value=1, severity=3
)
Expand All @@ -105,7 +105,7 @@ def alert():


@pytest.fixture
def account_alert_queue(alert, alertsub):
def account_alert_queue(db, alert, alertsub):
account_queue = AccountAlertQueue(alert=alert, subscription=alertsub)
account_queue.save()
yield account_queue
Expand Down

0 comments on commit ff071d7

Please sign in to comment.