Merge lp:~daker/loco-team-portal/ltp-blog-fixes into lp:~cjohnston/loco-team-portal/LTP-Blogroll

Proposed by Adnane Belmadiaf
Status: Merged
Approved by: Chris Johnston
Approved revision: 476
Merge reported by: Chris Johnston
Merged at revision: not available
Proposed branch: lp:~daker/loco-team-portal/ltp-blog-fixes
Merge into: lp:~cjohnston/loco-team-portal/LTP-Blogroll
Diff against target: 114 lines (+41/-35)
2 files modified
loco_directory/articles/models.py (+10/-13)
loco_directory/articles/tests.py (+31/-22)
To merge this branch: bzr merge lp:~daker/loco-team-portal/ltp-blog-fixes
Reviewer Review Type Date Requested Status
Chris Johnston Approve
LoCo Team Portal Developers Pending
Review via email: mp+73095@code.launchpad.net

Commit message

* Added test to blog feeds
* Changed code to match the coding style

To post a comment you must log in.
Revision history for this message
Michael Hall (mhall119) wrote :

How do you know the canonical.com feed will always have 10 articles in it?

476. By Adnane Belmadiaf

* Small Fixes

Revision history for this message
Adnane Belmadiaf (daker) wrote :

I have updated the test to use a feed with a fixed items.

Revision history for this message
Chris Johnston (cjohnston) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/articles/models.py'
2--- loco_directory/articles/models.py 2011-06-02 12:08:30 +0000
3+++ loco_directory/articles/models.py 2011-08-27 16:08:24 +0000
4@@ -1,3 +1,4 @@
5+# -*- coding: utf-8 -*-
6 import feedparser
7 import time
8 import datetime
9@@ -30,18 +31,16 @@
10 return '%s:%s' % (feed.id, hash(entry.title))
11
12 class Feed(models.Model):
13-
14- class Meta:
15- ordering = ('title',)
16-
17 user = models.ForeignKey(UserProfile, blank=True, null=True)
18 team = models.ForeignKey(Team, blank=True, null=True)
19 url = models.URLField()
20 title = models.CharField(max_length=128, null=True, blank=True)
21 last_updated = models.DateTimeField(null=False, blank=False, default=datetime.datetime(1970, 1, 1))
22-
23 active = models.BooleanField(default=True)
24-
25+
26+ class Meta:
27+ ordering = ('title',)
28+
29 def __unicode__(self):
30 return self.title
31
32@@ -99,10 +98,6 @@
33 Article.objects.filter(source=self, uid__in=obsolete_articles).delete()
34
35 class Article(models.Model):
36-
37- class Meta:
38- ordering = ['-imported', '-published',]
39-
40 source = models.ForeignKey(Feed, null=True, blank=True)
41 uid = models.CharField(max_length=256)
42 author = models.CharField(max_length=128, null=True, blank=True)
43@@ -111,7 +106,9 @@
44 link = models.URLField(max_length=1024, null=True, blank=True)
45 title = models.CharField(max_length=128, null=True, blank=True)
46 snippet = models.CharField(max_length=512, null=True, blank=True)
47-
48+
49+ class Meta:
50+ ordering = ['-imported', '-published',]
51+
52 def __unicode__(self):
53- return '%s (%s)' % (self.title, self.author)
54-
55+ return u'%s (%s)' % (self.title, self.author)
56
57=== modified file 'loco_directory/articles/tests.py'
58--- loco_directory/articles/tests.py 2011-06-01 22:19:20 +0000
59+++ loco_directory/articles/tests.py 2011-08-27 16:08:24 +0000
60@@ -1,23 +1,32 @@
61-"""
62-This file demonstrates two different styles of tests (one doctest and one
63-unittest). These will both pass when you run "manage.py test".
64-
65-Replace these with more appropriate tests for your application.
66-"""
67-
68 from django.test import TestCase
69-
70-class SimpleTest(TestCase):
71- def test_basic_addition(self):
72- """
73- Tests that 1 + 1 always equals 2.
74- """
75- self.failUnlessEqual(1 + 1, 2)
76-
77-__test__ = {"doctest": """
78-Another way to test that 1 + 1 is equal to 2.
79-
80->>> 1 + 1 == 2
81-True
82-"""}
83-
84+from django.test.client import Client
85+
86+from articles.models import Feed, Article
87+
88+class ArticlesTests(TestCase):
89+
90+ def setUp(self):
91+ super(ArticlesTests, self).setUp()
92+ self.feed_url = 'http://www.xml.com/cs/xml/query/q/19'
93+ self.feed = Feed.objects.create(url=self.feed_url, title="LTP")
94+
95+ def test_environment(self):
96+ """Just make sure everything is set up correctly."""
97+ self.assert_(True)
98+ try:
99+ import feedparser
100+ except:
101+ self.assert_(False)
102+
103+ def test_update(self):
104+ """Update and check for new articles"""
105+ self.feed.update(first_load=True)
106+ articles = Article.objects.all()
107+ self.assertEqual(len(articles), 15)
108+
109+ def test_check_duplicate(self):
110+ """Update and check for duplicated articles"""
111+ feed = Feed.objects.get(url=self.feed_url)
112+ feed.update()
113+ articles = Article.objects.all()
114+ self.assertEqual(len(articles), 15)

Subscribers

People subscribed via source and target branches