self.assertEqual(rv.status_code,200) self.assertIn("Hello Zubizareta, please login here",rv.data) rv = self.add_user("Robbi", "diogenes123",'diogenes123', "*****@*****.**",0) self.assertIn("Hello Robbi, please login here",rv.data) rv = self.login("Robbi","diogenes123") self.assertIn('Logged in as Robbi',rv.data) rv = self.add_user('Miąższ','diodor99','diodor99','*****@*****.**',0) self.assertEqual(rv.status_code,200) self.assertIn("password and username must be in ascii",rv.data) def testRegisterUser(self): fakeUser = {"username":"******", "email":"*****@*****.**","password":"******"} rv = flaskr.register_user(fakeUser) def testoAuth(self): rv = self.add_user('Pawel_Miech','diogenes12','diogenes12','*****@*****.**',1) self.assertIn('Hello Pawel_Miech, ', rv.data, findElem(rv.data,'input','username')) rv = self.login('Pawel_Miech','') self.assertIn('field is required',rv.data,findElem(rv.data,'form','login')) rv = self.login('Pawel_Miech', 'a') self.assertIn('Invalid username or password',rv.data) rv = self.login('Pawel_Miech','"null') self.assertIn('Invalid username or password',rv.data) if __name__ == '__main__': manipulate_db.populateDb(TestConfig.DATABASE) unittest.main()
def test_anonymous_review(self): data = { 'reqId': 101, 'uid': 2, 'review_text': 'somehwere over the rain', 'rating': 5, 'date_written': datetime.datetime.fromtimestamp(time.time()), 'anonymous': True } self.rev.insert_(data) attempt = self.rev.get_review(205) self.assertTrue(attempt.get('anonymous')) attempt = self.rev.get_reviews_by_user(2) self.assertTrue(attempt[-1].get('anonymous')) # delete review self.rev.delete_review(205) data2 = data.copy() data2['anonymous'] = False self.rev.insert_(data2) attempt = self.rev.get_review(206) self.assertFalse(attempt.get('anonymous')) self.rev.delete_review(206) if __name__ == "__main__": manipulate_db.populateDb(TestConfig.DATABASE) unittest.main()
""" Initiate sample datatabase on dev server. """ from utilities.manipulate_db import populateDb from src.config import DevelopmentConfig if __name__ == "__main__": populateDb(DevelopmentConfig.DATABASE)