Beispiel #1
0
 def setUp(self):
     self.now = datetime.datetime.utcnow().replace(tzinfo=utc)
     self.timedelta = datetime.timedelta(15)
     author = User.objects.get(pk=1)
     category = Category()
     category.name = "Test Category"
     category.save()
     for count in range(1, 11):
         post = Post(title="Post %d Title" % count,
                     text="foo",
                     author=author)
         if count < 6:
             # publish the first five posts
             pubdate = self.now - self.timedelta * count
             post.published_date = pubdate
         post.save()
         if count % 2:
             category.posts.add(post)
             category.save()
class FrontEndTestCase(TestCase):
    """test views provided in the front-end"""
    fixtures = ['myblog_test_fixture.json', ]
    
    def setUp(self):
        self.now = datetime.datetime.utcnow().replace(tzinfo=utc)
        self.timedelta = datetime.timedelta(15)
        author = User.objects.get(pk=1)
        self.category = Category(name='A Category')
        self.category.save()
        for count in range(1,11):
            post = Post(title="Post %d Title" % count,
                        text="foo",
                        author=author)
            if count < 6:
                # publish the first five posts
                pubdate = self.now - self.timedelta * count
                post.published_date = pubdate
            post.save()
            if bool(count & 1):
                # put odd items in category:
                self.category.posts.add(post)

    def test_list_only_published(self):
        resp = self.client.get('/')
        self.assertTrue("Recent Posts" in resp.content)
        for count in range(1,11):
            title = "Post %d Title" % count
            if count < 6:
                self.assertContains(resp, title, count=1)
            else:
                self.assertNotContains(resp, title)

    def test_details_only_published(self):
        for count in range(1,11):
            title = "Post %d Title" % count
            post = Post.objects.get(title=title)
            resp = self.client.get('/posts/%d/' % post.pk)
            if count < 6:
                self.assertEqual(resp.status_code, 200)
                self.assertContains(resp, title)
            else:
                self.assertEqual(resp.status_code, 404)
Beispiel #3
0
 def setUp(self):
     for count in range(1, 5):
         category = Category(name="Category %d" % count, description="This is the %d category." % count)
         category.save()