Skip to content
Browse files

added few integration tests for the news app

  • Loading branch information...
1 parent 3e9206c commit 7862f2a6b1ea90116f8d91b2273e6625bb90690c @denibertovic denibertovic committed
Showing with 41 additions and 3 deletions.
  1. +1 −1 news/models.py
  2. +0 −1 tests/events_test.py
  3. +10 −1 tests/factories.py
  4. +30 −0 tests/news_tests.py
View
2 news/models.py
@@ -14,7 +14,7 @@ class News(models.Model):
content = HTMLField(u'Sadržaj', blank=True)
created_at = models.DateTimeField(auto_now_add=True)
expire_at = models.DateTimeField(null=True)
- sticky = models.BooleanField(u'Sticky')
+ sticky = models.BooleanField(u'Sticky', default=False)
thumb = FileBrowseField(u'Sličica', max_length=255, blank=True)
slug = models.SlugField(blank=True, max_length=128)
View
1 tests/events_test.py
@@ -17,5 +17,4 @@ def test_get_events_archive(self):
# password='foobar')
response = self.client.get('events-archive')
- print response
self.assertEquals(200, response.status_code)
View
11 tests/factories.py
@@ -2,8 +2,10 @@
import factory
+from news.models import News
-class UserFactory(factory.Factory):
+
+class UserFactory(factory.django.DjangoModelFactory):
"""
Generates unique user so other factories don't generate
integrity error when they need a user.
@@ -27,3 +29,10 @@ def _prepare(cls, create, **kwargs):
is_staff = True
is_active = True
is_superuser = False
+
+
+class NewsFactory(factory.django.DjangoModelFactory):
+ FACTORY_FOR = News
+
+ subject = factory.Sequence(lambda n: 'TestNews%s' % n)
+ slug = factory.Sequence(lambda n: 'test-news-%s' % n)
View
30 tests/news_tests.py
@@ -0,0 +1,30 @@
+from django.test import TestCase
+
+from .base import BaseTestClient
+
+from .factories import NewsFactory
+from news.models import News
+
+__all__ = ['NewsViewTest']
+
+
+class NewsViewTest(TestCase):
+
+ def setUp(self):
+ super(NewsViewTest, self).setUp()
+ self.client = BaseTestClient()
+
+ def test_get_news_by_slug(self):
+ news = NewsFactory()
+ response = self.client.get('news-slug', slug=news.slug)
+ self.assertEquals(200, response.status_code)
+
+ def test_get_homepage(self):
+ news = NewsFactory()
+ response = self.client.get('root')
+ self.assertEquals(200, response.status_code)
+
+ def test_get_news_archive(self):
+ news = NewsFactory()
+ response = self.client.get('news-archive')
+ self.assertEquals(200, response.status_code)

0 comments on commit 7862f2a

Please sign in to comment.
Something went wrong with that request. Please try again.