def test_add_to_readability(self, post, get): # noqa post.return_value = responses( 202, headers={ 'location': 'https://www.readability.com/api/rest/v1/bookmarks/19', }) user = UserFactory.create( read_later='readability', read_later_credentials=json.dumps({ 'oauth_token': 'token', 'oauth_token_secret': 'token secret', }), ) get.return_value = responses(200, 'sw-all.xml') feed = FeedFactory.create(category__user=user, user=user) get.assert_called_once_with(feed.url, headers={ 'User-Agent': USER_AGENT % '1 subscriber', 'Accept': feedparser.ACCEPT_HEADER }, timeout=10, auth=None) get.reset_mock() get.return_value = responses(200, data=json.dumps( {'article': { 'id': 'foo' }})) entry_pk = es.manager.user(user).fetch()['hits'][0].pk url = reverse('feeds:item', args=[entry_pk]) response = self.app.get(url, user=user) self.assertContains(response, "Add to Readability") form = response.forms['read-later'] response = form.submit() self.assertEqual(len(post.call_args_list), 1) self.assertEqual(len(get.call_args_list), 1) args, kwargs = post.call_args self.assertEqual( args, ('https://www.readability.com/api/rest/v1/bookmarks', )) self.assertEqual(kwargs['data'], {'url': 'http://simonwillison.net/2010/Mar/12/re2/'}) args, kwargs = get.call_args self.assertEqual( args, ('https://www.readability.com/api/rest/v1/bookmarks/19', )) entry = es.entry(user, entry_pk) self.assertEqual(entry.read_later_url, 'https://www.readability.com/articles/foo') response = self.app.get(url, user=user) self.assertNotContains(response, "Add to Instapaper")
def test_add_to_instapaper(self, post, get, head): # noqa head.side_effect = resolve_url post.return_value = responses(200, data=json.dumps([{ 'type': 'bookmark', 'bookmark_id': 12345, 'title': 'Some bookmark', 'url': 'http://example.com/some-bookmark', }])) user = UserFactory.create( read_later='instapaper', read_later_credentials=json.dumps({ 'oauth_token': 'token', 'oauth_token_secret': 'token secret', }), ) get.return_value = responses(304) feed = FeedFactory.create(category__user=user, user=user) get.reset_mock() get.return_value = responses(200, 'sw-all.xml') update_feed(feed.url) get.assert_called_once_with(feed.url, headers={ 'User-Agent': USER_AGENT % '1 subscriber', 'Accept': feedparser.ACCEPT_HEADER }, timeout=10, auth=None) entry_pk = es.manager.user(user).fetch()['hits'][0].pk url = reverse('feeds:item', args=[entry_pk]) response = self.app.get(url, user=user) self.assertContains(response, "Add to Instapaper") form = response.forms['read-later'] response = form.submit() self.assertEqual(len(post.call_args_list), 1) args, kwargs = post.call_args self.assertEqual(args, ('https://www.instapaper.com/api/1/bookmarks/add', )) self.assertEqual(kwargs['data'], {'url': 'http://simonwillison.net/2010/Mar/12/re2/'}) entry = es.entry(user, entry_pk) self.assertEqual(entry.read_later_url, 'https://www.instapaper.com/read/12345') response = self.app.get(url, user=user) self.assertNotContains(response, "Add to Instapaper")
def test_add_to_readability(self, post, get): # noqa post.return_value = responses(202, headers={ 'location': 'https://www.readability.com/api/rest/v1/bookmarks/19', }) user = UserFactory.create( read_later='readability', read_later_credentials=json.dumps({ 'oauth_token': 'token', 'oauth_token_secret': 'token secret', }), ) get.return_value = responses(200, 'sw-all.xml') feed = FeedFactory.create(category__user=user, user=user) get.assert_called_once_with( feed.url, headers={'User-Agent': USER_AGENT % '1 subscriber', 'Accept': feedparser.ACCEPT_HEADER}, timeout=10) get.reset_mock() get.return_value = responses(200, data=json.dumps( {'article': {'id': 'foo'}})) if user.es: entry_pk = es.manager.user(user).fetch()['hits'][0].pk else: entry_pk = Entry.objects.all()[0].pk url = reverse('feeds:item', args=[entry_pk]) response = self.app.get(url, user=user) self.assertContains(response, "Add to Readability") form = response.forms['read-later'] response = form.submit() self.assertEqual(len(post.call_args_list), 1) self.assertEqual(len(get.call_args_list), 1) args, kwargs = post.call_args self.assertEqual( args, ('https://www.readability.com/api/rest/v1/bookmarks',)) self.assertEqual(kwargs['data'], { 'url': 'http://simonwillison.net/2010/Mar/12/re2/'}) args, kwargs = get.call_args self.assertEqual( args, ('https://www.readability.com/api/rest/v1/bookmarks/19',)) if user.es: entry = es.entry(user, entry_pk) else: entry = Entry.objects.get(pk=entry_pk) self.assertEqual(entry.read_later_url, 'https://www.readability.com/articles/foo') response = self.app.get(url, user=user) self.assertNotContains(response, "Add to Instapaper")
def test_add_to_instapaper(self, post, get): # noqa post.return_value = responses(200, data=json.dumps([{ 'type': 'bookmark', 'bookmark_id': 12345, 'title': 'Some bookmark', 'url': 'http://example.com/some-bookmark', }])) user = UserFactory.create( read_later='instapaper', read_later_credentials=json.dumps({ 'oauth_token': 'token', 'oauth_token_secret': 'token secret', }), ) get.return_value = responses(304) feed = FeedFactory.create(category__user=user, user=user) get.reset_mock() get.return_value = responses(200, 'sw-all.xml') update_feed(feed.url) get.assert_called_once_with( feed.url, headers={'User-Agent': USER_AGENT % '1 subscriber', 'Accept': feedparser.ACCEPT_HEADER}, timeout=10) if user.es: entry_pk = es.manager.user(user).fetch()['hits'][0].pk else: entry_pk = Entry.objects.all()[0].pk url = reverse('feeds:item', args=[entry_pk]) response = self.app.get(url, user=user) self.assertContains(response, "Add to Instapaper") form = response.forms['read-later'] response = form.submit() self.assertEqual(len(post.call_args_list), 1) args, kwargs = post.call_args self.assertEqual(args, ('https://www.instapaper.com/api/1/bookmarks/add',)) self.assertEqual(kwargs['data'], {'url': 'http://simonwillison.net/2010/Mar/12/re2/'}) if user.es: entry = es.entry(user, entry_pk) else: entry = Entry.objects.get(pk=entry_pk) self.assertEqual(entry.read_later_url, 'https://www.instapaper.com/read/12345') response = self.app.get(url, user=user) self.assertNotContains(response, "Add to Instapaper")