mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Updating rss_feeds tests for completeness. Updating README to include how to run test suite.
This commit is contained in:
parent
ad4bc10c92
commit
8f5a4c612d
8 changed files with 69 additions and 36 deletions
|
@ -203,6 +203,13 @@ To populate the statistics graphs on the homepage, use the `collect_stats` manag
|
|||
command every few minutes:
|
||||
|
||||
./manage.py collect_stats
|
||||
|
||||
### Running unit and integration tests
|
||||
|
||||
NewsBlur comes complete with a test suite that tests the functionality of the rss_feeds,
|
||||
reader, and feed importer. To run the test suite:
|
||||
|
||||
./manage.py test --settings=utils.test-settings
|
||||
|
||||
|
||||
## Roadmap
|
||||
|
|
|
@ -78,7 +78,8 @@ class ReaderTest(TestCase):
|
|||
# connection.queries = []
|
||||
|
||||
self.client.login(username='conesus', password='test')
|
||||
response = self.client.get(reverse('load-single-feed', args=[1]))
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=1))
|
||||
response = self.client.get(url)
|
||||
feed = json.decode(response.content)
|
||||
self.assertEquals(len(feed['feed_tags']), 0)
|
||||
self.assertEquals(len(feed['classifiers']['tags']), 0)
|
||||
|
|
|
@ -3,19 +3,30 @@
|
|||
"pk": 1,
|
||||
"model": "rss_feeds.feed",
|
||||
"fields": {
|
||||
"premium_subscribers": -1,
|
||||
"creation": "2011-08-27",
|
||||
"exception_code": 0,
|
||||
"last_load_time": 0,
|
||||
"active_subscribers": 1,
|
||||
"feed_address": "%(NEWSBLUR_DIR)s/apps/rss_feeds/fixtures/gawker1.xml",
|
||||
"days_to_trim": 90,
|
||||
"feed_link": "%(NEWSBLUR_DIR)s/apps/rss_feeds/fixtures/gawker1.html",
|
||||
"num_subscribers": 0,
|
||||
"creation": "2009-01-12",
|
||||
"feed_title": "Gawker",
|
||||
"last_update": "2009-07-06 22:30:03",
|
||||
"next_scheduled_update": "2009-07-06 22:30:03",
|
||||
"queued_date": "2009-07-06 22:30:03",
|
||||
"min_to_decay": 1,
|
||||
"etag": "",
|
||||
"last_modified": "2009-07-06 22:30:03",
|
||||
"active": 1
|
||||
"last_update": "2011-08-27 02:45:21",
|
||||
"etag": null,
|
||||
"average_stories_per_month": 0,
|
||||
"feed_title": "Gawker",
|
||||
"last_modified": null,
|
||||
"next_scheduled_update": "2011-08-28 14:33:50",
|
||||
"favicon_color": null,
|
||||
"stories_last_month": 0,
|
||||
"active": true,
|
||||
"favicon_not_found": false,
|
||||
"has_page_exception": false,
|
||||
"fetched_once": false,
|
||||
"days_to_trim": 90,
|
||||
"num_subscribers": 1,
|
||||
"queued_date": "2011-08-28 00:03:50",
|
||||
"min_to_decay": 720,
|
||||
"has_feed_exception": false
|
||||
}
|
||||
}
|
||||
]
|
|
@ -2,6 +2,7 @@ from utils import json_functions as json
|
|||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
from django.core import management
|
||||
from django.core.urlresolvers import reverse
|
||||
from apps.rss_feeds.models import Feed, MStory
|
||||
|
||||
class FeedTest(TestCase):
|
||||
|
@ -19,21 +20,23 @@ class FeedTest(TestCase):
|
|||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 0)
|
||||
|
||||
management.call_command('refresh_feed', force=1, feed=1, single_threaded=True, daemonize=False)
|
||||
feed.update(force=True)
|
||||
|
||||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 38)
|
||||
|
||||
management.call_command('loaddata', 'gawker2.json', verbosity=0)
|
||||
management.call_command('refresh_feed', force=1, feed=1, single_threaded=True, daemonize=False)
|
||||
|
||||
feed.update(force=True)
|
||||
|
||||
# Test: 1 changed char in content
|
||||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 38)
|
||||
|
||||
response = self.client.post('/reader/feed', { "feed_id": 1 })
|
||||
feed = json.decode(response.content)
|
||||
self.assertEquals(len(feed['stories']), 30)
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=1))
|
||||
response = self.client.get(url)
|
||||
feed = json.decode(response.content)
|
||||
self.assertEquals(len(feed['stories']), 12)
|
||||
|
||||
def test_load_feeds__gothamist(self):
|
||||
self.client.login(username='conesus', password='test')
|
||||
|
@ -48,9 +51,10 @@ class FeedTest(TestCase):
|
|||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 42)
|
||||
|
||||
response = self.client.post('/reader/feed', { "feed_id": 4 })
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=4))
|
||||
response = self.client.get(url)
|
||||
content = json.decode(response.content)
|
||||
self.assertEquals(len(content['stories']), 30)
|
||||
self.assertEquals(len(content['stories']), 12)
|
||||
|
||||
management.call_command('loaddata', 'gothamist_aug_2009_2.json', verbosity=0)
|
||||
management.call_command('refresh_feed', force=1, feed=4, single_threaded=True, daemonize=False)
|
||||
|
@ -58,11 +62,12 @@ class FeedTest(TestCase):
|
|||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 42)
|
||||
|
||||
response = self.client.get('/reader/feed', { "feed_id": 4 })
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=4))
|
||||
response = self.client.get(url)
|
||||
# print [c['story_title'] for c in json.decode(response.content)]
|
||||
content = json.decode(response.content)
|
||||
# Test: 1 changed char in title
|
||||
self.assertEquals(len(content['stories']), 30)
|
||||
self.assertEquals(len(content['stories']), 12)
|
||||
|
||||
def test_load_feeds__slashdot(self):
|
||||
self.client.login(username='conesus', password='test')
|
||||
|
@ -84,13 +89,14 @@ class FeedTest(TestCase):
|
|||
stories = MStory.objects(story_feed_id=feed.pk)
|
||||
self.assertEquals(stories.count(), 38)
|
||||
|
||||
response = self.client.post('/reader/feed', { "feed_id": 5 })
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=5))
|
||||
response = self.client.get(url)
|
||||
|
||||
# pprint([c['story_title'] for c in json.decode(response.content)])
|
||||
feed = json.decode(response.content)
|
||||
|
||||
# Test: 1 changed char in title
|
||||
self.assertEquals(len(feed['stories']), 30)
|
||||
self.assertEquals(len(feed['stories']), 12)
|
||||
|
||||
def test_load_feeds__brokelyn__invalid_xml(self):
|
||||
self.client.login(username='conesus', password='test')
|
||||
|
@ -98,7 +104,8 @@ class FeedTest(TestCase):
|
|||
management.call_command('loaddata', 'brokelyn.json', verbosity=0)
|
||||
management.call_command('refresh_feed', force=1, feed=6, single_threaded=True, daemonize=False)
|
||||
|
||||
response = self.client.post('/reader/feed', { "feed_id": 6 })
|
||||
url = reverse('load-single-feed', kwargs=dict(feed_id=6))
|
||||
response = self.client.get(url)
|
||||
|
||||
# pprint([c['story_title'] for c in json.decode(response.content)])
|
||||
feed = json.decode(response.content)
|
||||
|
|
|
@ -32,6 +32,7 @@ if '/vendor' not in ' '.join(sys.path):
|
|||
ADMINS = (
|
||||
('Samuel Clay', 'samuel@ofbrooklyn.com'),
|
||||
)
|
||||
TEST_DEBUG = False
|
||||
SEND_BROKEN_LINK_EMAILS = False
|
||||
MANAGERS = ADMINS
|
||||
PAYPAL_RECEIVER_EMAIL = 'samuel@ofbrooklyn.com'
|
||||
|
|
|
@ -62,6 +62,7 @@ class FetchFeed:
|
|||
's' if self.feed.num_subscribers != 1 else '',
|
||||
URL
|
||||
)
|
||||
|
||||
self.fpf = feedparser.parse(self.feed.feed_address,
|
||||
agent=USER_AGENT,
|
||||
etag=etag,
|
||||
|
@ -385,7 +386,7 @@ class Dispatcher:
|
|||
for key, val in ret_entries.items():
|
||||
self.entry_stats[key] += val
|
||||
|
||||
time_taken = datetime.datetime.utcnow() - self.time_start
|
||||
# time_taken = datetime.datetime.utcnow() - self.time_start
|
||||
|
||||
@timelimit(20)
|
||||
def count_unreads_for_subscribers(self, feed):
|
||||
|
|
|
@ -5,6 +5,7 @@ import traceback
|
|||
import pprint
|
||||
from django.core.mail import mail_admins
|
||||
from django.utils.translation import ungettext
|
||||
from django.conf import settings
|
||||
from utils import log as logging
|
||||
|
||||
class TimeoutError(Exception): pass
|
||||
|
@ -26,17 +27,19 @@ def timelimit(timeout):
|
|||
self.result = function(*args, **kw)
|
||||
except:
|
||||
self.error = sys.exc_info()
|
||||
|
||||
c = Dispatch()
|
||||
c.join(timeout)
|
||||
if c.isAlive():
|
||||
raise TimeoutError, 'took too long'
|
||||
if c.error:
|
||||
tb = ''.join(traceback.format_exception(c.error[0], c.error[1], c.error[2]))
|
||||
logging.debug(tb)
|
||||
mail_admins('Error in timeout: %s' % c.error[0], tb)
|
||||
raise c.error[0], c.error[1]
|
||||
return c.result
|
||||
if not settings.DEBUG and not settings.TEST_DEBUG:
|
||||
c = Dispatch()
|
||||
c.join(timeout)
|
||||
if c.isAlive():
|
||||
raise TimeoutError, 'took too long'
|
||||
if c.error:
|
||||
tb = ''.join(traceback.format_exception(c.error[0], c.error[1], c.error[2]))
|
||||
logging.debug(tb)
|
||||
mail_admins('Error in timeout: %s' % c.error[0], tb)
|
||||
raise c.error[0], c.error[1]
|
||||
return c.result
|
||||
else:
|
||||
return function(*args, **kw)
|
||||
return _2
|
||||
return _1
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ MONGO_DB = {
|
|||
|
||||
TEST_DATABASE_NAME = ":memory:"
|
||||
|
||||
TEST_DEBUG = True
|
||||
|
||||
# from django.db import connection
|
||||
# cursor = connection.cursor()
|
||||
# cursor.execute('PRAGMA temp_store = MEMORY;')
|
||||
|
|
Loading…
Add table
Reference in a new issue