3 from datetime
import datetime
5 from django
.contrib
.auth
import get_user_model
6 from django
.test
import TestCase
8 from mygpo
.users
.models
import Client
9 from mygpo
.podcasts
.models
import Podcast
13 class TestSubscribe(TestCase
):
14 """ Test subscribing to podcasts """
17 User
= get_user_model()
19 username
='duplicate-subscribe',
20 email
='duplicate-subscribe@example.com',
22 self
.user
.set_password('secret')
24 self
.client
= Client
.objects
.create(
25 user
=self
.user
, uid
='dev1', id=uuid
.uuid1())
27 self
.url
= 'http://www.example.com/pdocast.rss'
28 self
.podcast
= Podcast
.objects
.get_or_create_for_url(self
.url
).object
30 def test_duplicate_subscribe(self
):
31 """ Test that a duplicate subscription is skipped """
32 from . import _perform_subscribe
33 clients
= [self
.client
, self
.client
]
34 changed_clients
= list(_perform_subscribe(
42 # ensure only one client is changed
43 self
.assertEqual(len(changed_clients
), 1)
44 self
.assertEqual(changed_clients
[0], self
.client
)
46 # ensure exactly one subscription has been created
47 subscriptions
= models
.Subscription
.objects
.filter(
51 self
.assertEqual(subscriptions
.count(), 1)
52 subscriptions
[0].delete()