You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

from srht.database import db
from tests.factories import TrackerFactory, TicketFactory, UserFactory
from tests.factories import ParticipantFactory
from tests.utils import logged_in_as
from import get_or_create_subscription
from todosrht.types import TicketSubscription
from todosrht.urls import ticket_url
def test_get_or_create_subscription():
participant1 = ParticipantFactory()
participant2 = ParticipantFactory()
participant3 = ParticipantFactory()
tracker = TrackerFactory()
ticket = TicketFactory(tracker=tracker)
# Some existing subscriptions
ts1 = TicketSubscription(participant=participant1, ticket=ticket)
ts2 = TicketSubscription(participant=participant2, tracker=tracker)
assert set(ticket.subscriptions) == set([ts1])
assert set(tracker.subscriptions) == set([ts2])
# Return existing subs if they exist
assert get_or_create_subscription(ticket, participant1) == ts1
assert get_or_create_subscription(ticket, participant2) == ts2
# Create new ticket sub if none exists
ts3 = get_or_create_subscription(ticket, participant3)
assert set(ticket.subscriptions) == set([ts1, ts3])
assert set(tracker.subscriptions) == set([ts2])