def test_posts_with_posts_in_db(self): posts_count = 10 PostFactory.create_batch(posts_count) response = self.app.get('/posts') self.assertEqual(len(response.json), posts_count)
def init(): """ Populate data """ User.objects.filter(email='*****@*****.**').delete() user = UserFactory(email='*****@*****.**') logger.debug('User %s', user) posts = PostFactory.create_batch(10, author=user) logger.debug('Created posts %s', posts)
def test_ordering(self): posts = PostFactory.create_batch(3) response = self.app.get('/posts?order=-title') sorted_posts = sorted(posts, key=lambda x: x.title, reverse=True) self.assertEqual( list(map(lambda x: x['title'], response.json)), [post.title for post in sorted_posts], )
def test_offset(self): posts_count = 10 offset = 5 posts = PostFactory.create_batch(posts_count) response = self.app.get(f'/posts?offset={offset}') self.assertEqual( list(map(lambda x: x['id'], response.json)), [post.external_id for post in posts][offset:], )