Пример #1
0
 def test_create_post(self):
     post = Post(title='hello', text='world',
                 slug='hello', author_id=1)
     op = PostOperator(self.session)
     op.create_post(post)
     self.assertEqual(op.get_post(post.id), post)
     # same slug is not allowed
     another_post = Post(title='hello', text='world',
                         slug='hello', author_id=1)
     self.assertRaises(ModelError, op.create_post, another_post)
Пример #2
0
 def test_create_post(self):
     post = Post(title='hello', text='world', slug='hello', author_id=1)
     op = PostOperator(self.session)
     op.create_post(post)
     self.assertEqual(op.get_post(post.id), post)
     # same slug is not allowed
     another_post = Post(title='hello',
                         text='world',
                         slug='hello',
                         author_id=1)
     self.assertRaises(ModelError, op.create_post, another_post)
Пример #3
0
    def test_get_posts(self):
        op = PostOperator(self.session)
        # create post
        post = Post(title='hello',
                    text='world',
                    slug='hello-world',
                    author_id=1)
        op.create_post(post)
        self.assertEqual(op.get_post(post.id), post)
        # get public posts
        haskell = Post(title='haskell-2012',
                       text='world3',
                       slug='hehe',
                       author_id=1)
        haskell.created_at = datetime(year=2012, month=4, day=29)
        op.create_post(haskell)
        haskell.add_tags(['haskell', 'fp'])

        scheme = Post(title='scheme-2010',
                      text='world2',
                      slug='haha',
                      author_id=1)
        scheme.created_at = datetime(year=2010, month=1, day=16)
        op.create_post(scheme)
        scheme.add_tags(['scheme', 'fp'])

        clojure = Post(title='clojure-2009',
                       text='world1',
                       slug='haha',
                       author_id=1)
        clojure.created_at = datetime(year=2009, month=12, day=13)
        op.create_post(clojure)
        clojure.add_tags(['clojure', 'fp'])
        posts, more = op.get_public_posts()
        self.assertEqual(4, len(posts))
        self.assertEqual(posts, [post, haskell, scheme, clojure])
        self.assertFalse(more)  # no more
        self.assertEqual(set([str(tag) for tag in op.get_public_tags()]),
                         {'clojure', 'fp', 'scheme', 'haskell'})

        op.trash_post(post)
        posts, more = op.get_public_posts()
        self.assertEqual(posts, [haskell, scheme, clojure])
        self.assertFalse(more)
        # scheme will be removed from public tags
        op.trash_post(scheme)
        self.assertEqual(set([tag.name for tag in op.get_public_tags()]),
                         {'clojure', 'fp', 'haskell'})
        self.assertEqual(set([str(tag) for tag in op.get_trash_tags()]),
                         {'scheme', 'fp'})
Пример #4
0
    def test_get_posts(self):
        op = PostOperator(self.session)
        # create post
        post = Post(title='hello', text='world',
                    slug='hello-world', author_id=1)
        op.create_post(post)
        self.assertEqual(op.get_post(post.id), post)
        # get public posts
        haskell = Post(title='haskell-2012', text='world3',
                       slug='hehe', author_id=1)
        haskell.created_at = datetime(year=2012, month=4, day=29)
        op.create_post(haskell)
        haskell.add_tags(['haskell', 'fp'])

        scheme = Post(title='scheme-2010', text='world2',
                      slug='haha', author_id=1)
        scheme.created_at = datetime(year=2010, month=1, day=16)
        op.create_post(scheme)
        scheme.add_tags(['scheme', 'fp'])

        clojure = Post(title='clojure-2009', text='world1',
                       slug='haha', author_id=1)
        clojure.created_at = datetime(year=2009, month=12, day=13)
        op.create_post(clojure)
        clojure.add_tags(['clojure', 'fp'])
        posts, more = op.get_public_posts()
        self.assertEqual(4, len(posts))
        self.assertEqual(posts, [post, haskell, scheme, clojure])
        self.assertFalse(more)  # no more
        self.assertEqual(set([str(tag) for tag in op.get_public_tags()]),
                         {'clojure', 'fp', 'scheme', 'haskell'})

        op.trash_post(post)
        posts, more = op.get_public_posts()
        self.assertEqual(posts, [haskell, scheme, clojure])
        self.assertFalse(more)
        # scheme will be removed from public tags
        op.trash_post(scheme)
        self.assertEqual(set([tag.name for tag in op.get_public_tags()]),
                         {'clojure', 'fp', 'haskell'})
        self.assertEqual(set([str(tag) for tag in op.get_trash_tags()]),
                         {'scheme', 'fp'})