def test_notification_path(self): with open(TEST_FILES_DIR + 'boingboing.xml') as f: data = f.read() user = UserFactory(active=True) feed = FeedFactory(status=STATUS.SUBSCRIBED) author = AuthorFactory(name='Cory Doctorow', givenname='Cory', familyname='Doctorow', email='*****@*****.**') sub = SubscriptionFactory(user=user, author=author, active=True) sub.add_period(PERIOD.IMMEDIATE) db.session.commit() h = hmac.new(bytes(feed.secret, 'UTF-8'), digestmod=hashlib.sha1) h.update(data.encode('UTF-8')) digest = h.hexdigest() sig = "sha1=" + digest headers = {} headers['X-Hub-Signature'] = sig headers['content-type'] = 'application/rss+xml' headers['Link'] = str(LinkHeader([Link(feed.hub, rel="hub"), Link(feed.topic, rel="self")])) with self.app.test_client() as c: notification_received.connect(when_notification_received) entries_added.connect(when_entries_added) update_user_rss.connect(when_update_user_rss) with mail.record_messages() as outbox: response = c.post(get_public_url(feed), headers=headers, data=data) self.assertEqual(response.status_code, 200) authors = db.session.query(Author).all() self.assertEqual(len(authors), 6) entries = db.session.query(Entry).all() self.assertEqual(len(entries), 30) self.assertIs(type(entries[0].content), str) self.assertEqual(len(outbox), 1) emails = Email.query.all() self.assertEqual(len(emails), 1) self.assertEqual(emails[0].address, user.email)
def test_json_notification_path(self): with open(TEST_FILES_DIR + 'notification.json') as f: data = f.read() user = UserFactory(active=True) feed = FeedFactory(status=STATUS.SUBSCRIBED, topic='http://testfeed.test') author = AuthorFactory(name='Testy McTesterson', givenname='Testy', familyname='McTesterson') sub = SubscriptionFactory(user=user, author=author, active=True) sub.add_period(PERIOD.IMMEDIATE) db.session.commit() h = hmac.new(bytes(feed.secret, 'UTF-8'), digestmod=hashlib.sha1) h.update(data.encode('UTF-8')) digest = h.hexdigest() sig = "sha1=" + digest headers = {} headers['X-Hub-Signature'] = sig headers['content-type'] = 'application/json' headers['Link'] = str(LinkHeader([Link(feed.hub, rel='hub'), Link(feed.topic, rel='self')])) with self.app.test_client() as c: notification_received.connect(when_notification_received) entries_added.connect(when_entries_added) update_user_rss.connect(when_update_user_rss) with mail.record_messages() as outbox: response = c.post(get_public_url(feed), headers=headers, data=data) self.assertEqual(response.status_code, 200) authors = db.session.query(Author).all() self.assertEqual(len(authors), 3) author2 = Author.query.filter_by(name='John Doe').first() self.assertEqual(author2.name, 'John Doe') self.assertEqual(author2.givenname, 'John') self.assertEqual(author2.familyname, 'Doe') author3 = Author.query.filter_by(name=u'Tĕstá ĀũʈĥőŘ').first() self.assertEqual(author3.name, u'Tĕstá ĀũʈĥőŘ') self.assertEqual(author3.givenname, u'Tĕstá') self.assertEqual(author3.familyname, u'ĀũʈĥőŘ') entries = Entry.query.all() self.assertEqual(len(entries), 2) self.assertIs(type(entries[0].content), str) self.assertIs(type(entries[1].content), str) entry2 = Entry.query.filter_by(guid='domain.tld/2015-12-02').first() self.assertEqual(entry2.content, u'This is the second entry, it contains unicode Tĕstá ĀũʈĥőŘ') self.assertEqual(len(outbox), 1) emails = Email.query.all() self.assertEqual(len(emails), 1) self.assertEqual(emails[0].address, user.email)