Exemplo n.º 1
0
 def setUp(self):
     super(FlaskTestCase, self).setUp()
     app.config['DEBUG'] = True
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
     db.create_all()
     self.app = app.test_client()
Exemplo n.º 2
0
        self.assertEqual(workouts[1]['id'], workout_1['id'])

        links = json.loads(res.data)['_links']
        self.assertNotIn('next', links, u"")

        # Per Page is set to 2 so creating more workouts should make new pages
        self.create_workout()
        self.create_workout()

        res = self.request('get', '/workouts')
        links = json.loads(res.data)['_links']
        self.assertIn('next', links, u"With per_page set to 2, this resource should be split and point to the next page")

        res = self.request('get', links['next']['href'])
        self.assertEqual(res.status_code, 200)
        links = json.loads(res.data)['_links']
        self.assertNotIn('next', links, u"Last page should not have `next` link")

        res = self.request('get', '/workouts?per_page=4')
        links = json.loads(res.data)['_links']
        self.assertIn('next', links, u"per_page was overwritten in a url argument "
                                     u"but and server seems to have respected it "
                                     u"since a next link was introduced in the _links. "
                                     u"However the upper limit should be the `per_page`"
                                     u"set on the class.")


if __name__ == '__main__':
    db.create_all()
    unittest.main()