-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstreamer_tests.py
70 lines (58 loc) · 2.58 KB
/
streamer_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from pshb import ContentParser, Post, PostFactory
from streamer import Subscription
import datetime
import feedparser
import pshb
import streamer
import unittest
class StubHubSubscriber(pshb.HubSubscriber):
def unsubscribe(self, url, hub, callback_url):
self.url = url
self.hub = hub
self.callback_url = callback_url
class SubscriptionTest(unittest.TestCase):
def setUp(self):
subscriptions = Subscription.all()
for subscription in subscriptions:
subscription.delete()
def testCanTellIfFeedIsAlreadyStored(self):
url = "http://example.org/atom"
s = Subscription(url=url, hub="http://hub.example.org/", sourceUrl="http://example.org/", key_name=url)
s.put()
self.assertTrue(Subscription.exists(url))
def testCanTellIfFeedIsNew(self):
url = "http://example.org/atom"
self.assertFalse(Subscription.exists(url))
def testAddingSubscriptionTwiceOnlyAddsOneRecordToDataStore(self):
url = "http://example.org/atom"
s = Subscription(url=url, hub="http://hub.example.org/", sourceUrl="http://example.org/", key_name=url)
s.put()
self.assertEquals(1, len(Subscription.find(url).fetch(1000)))
s2 = Subscription(url=url, hub="http://hub.example.org/", sourceUrl="http://example.org/", key_name=url)
s2.put()
self.assertEquals(1, len(Subscription.find(url).fetch(1000)))
self.assertEquals(1, Subscription.all().count())
def testCanDeleteSubscription(self):
url = "http://example.org/atom"
s = Subscription(url=url, hub="http://hub.example.org/", sourceUrl="http://example.org/", key_name=url)
s.put()
self.assertTrue(Subscription.exists(url))
Subscription.deleteSubscriptionWithMatchingUrl(url)
self.assertFalse(Subscription.exists(url))
class BackgroundHandlerTest(unittest.TestCase):
def testCanDeleteFeed(self):
url = "http://example.org/atom"
s = streamer.Subscription(url=url, hub="http://hub.example.org/", sourceUrl="http://example.org/", key_name=url)
s.put()
streamer.handleDeleteSubscription(url, hubSubscriber=StubHubSubscriber())
self.assertFalse(Subscription.exists(url))
def testDeletingFeedUnsubscribesFromHub(self):
url = "http://example.org/atom"
hub="http://hub.example.org/"
s = streamer.Subscription(url=url, hub=hub, sourceUrl="http://example.org/", key_name=url)
s.put()
hubSubscriber=StubHubSubscriber()
streamer.handleDeleteSubscription(url, hubSubscriber=hubSubscriber)
self.assertEquals(url, hubSubscriber.url)
self.assertEquals(hub, hubSubscriber.hub)
self.assertEquals('http://streamer-ade.appspot.com/posts', hubSubscriber.callback_url)