def test_bone(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id likedbefore = DB.session.query(User).first().has_liked(id) response = self.bone(id, 'like') with APP.app_context(): likedafter = DB.session.query(User).first().has_liked(id) self.assertNotEqual(likedbefore, likedafter)
def test_comments(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id response = self.comment(id, "comentariutest") n = 0 with APP.app_context(): n = DB.session.query(Comment).count() self.assertEqual(1, n)
def test_delete_post(self): self.create_admin() self.post("test", "testdesc", 100, "Male", "husky") with APP.app_context(): id = DB.session.query(Post).first().id countbefore = DB.session.query(Post).count() response = self.APP.post(('/delete_post?id=%d' % id), follow_redirects=True) with APP.app_context(): countafter = DB.session.query(Post).count() self.assertNotEqual(countbefore, countafter)
def create_admin(self): response = self.register('*****@*****.**', 'admin123', 'admin') with APP.app_context(): DB.session.query(User).first().rank = 1 DB.session.commit() response = self.login('admin', 'admin123') self.assertEqual(response.status_code, 200)
def test_valid_posting(self): self.create_admin() response = self.post("test", "testdesc", 100, "Male", "husky") response = self.post("test2", "testdesc", 100, "Male", "husky") n = 0 with APP.app_context(): n = DB.session.query(Post).count() self.assertEqual(2, n)
def setUp(self): with APP.app_context(): APP.config['TESTING'] = True APP.config['WTF_CSRF_ENABLED'] = False APP.config['DEBUG'] = False APP.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' self.APP = APP.test_client() DB.init_app(APP) DB.drop_all() DB.create_all() self.assertEqual(APP.debug, False)
def test_profile(self): self.create_admin() self.APP.post('/profile', data=dict(last_name="gigel", first_name="adminul", phone="0722222222"), follow_redirects=True) with APP.app_context(): user = DB.session.query(User).first() self.assertEqual(user.last_name, "gigel") self.assertEqual(user.first_name, "adminul") self.assertEqual(user.phone, "0722222222")
def app(): """Yield your app with its context set up and ready""" with APP.app_context(): yield APP