def test_logout(self): tester = app.test_client(self) tester.post('/login', data=dict(email="Manny@hdsalkfjal", password="******"), follow_redirects=True) response = tester.get('/logout', follow_redirects=True) self.assertIn(b'You have successfully logged out', response.data)
def test_incorrect_login(self): tester = app.test_client(self) response = tester.post('/login', data=dict(email="Manny@hdsalkfjal", password="******"), follow_redirects=True) self.assertIn(b'Invalid login', response.data)
def test_main(self): with app.test_client() as client: # send data as POST form to endpoint sent = {'username': '******', 'password': '******'} response = client.post('/login', data=sent) print(response.data) assertTrue(self, response)
def test_index_page(self): tester = app.test_client(self) tester.post('/login', data=dict(email="Manny@hdsalkfjal", password="******"), follow_redirects=True) response = tester.get('/list', content_type='html/text') self.assertTrue(b'Books' in response.data)
def test_index(self): tester = app.test_client(self) tester.post('/login', data=dict(email="Manny@hdsalkfjal", password="******"), follow_redirects=True) response = tester.get('/list', content_type='html/text') self.assertEqual(response.status_code, 200)
def test_main_page(self): with app.test_client() as c: with c.session_transaction() as session: session['logged_in'] = True session['username'] = '******' response = self.app.get('/edit_template/1', follow_redirects=True) assertTrue(self, response) print(response.data)
def test_check_login(self): tester = app.test_client(self) response = tester.post('user/check_login', data=json.dumps( dict(email="Manny@hdsalkfjal", password_candidate="12345678")), follow_redirects=True, content_type='application/json') self.assertEqual(response.content_type, 'application/json')
def test_update_book(self): tester = app.test_client(self) tester.put('/book/14', data=json.dumps( dict(isbn="7926410434", title="Dubmo 2", author="Steven spils", date="1998")), follow_redirects=True, content_type='application/json') response = tester.get('/book/14') self.assertIn(b'"title": "Dubmo 2"', response.data)
def test_create_book(self): tester = app.test_client(self) tester.post('/book', data=json.dumps( dict(isbn="019374692", title="NEW BOOK", author="Steven spils", date="1998", userId="3")), follow_redirects=True, content_type='application/json') response = tester.get('/book/15', follow_redirects=True) self.assertIn(b'"author": "Steven spils"', response.data)
def setUp(self): #import config #from database import db app.config['TESTING'] = True #app.config['WTF_CSRF_ENABLED'] = False #app.config['DEBUG'] = False app.secret_key = 'secret123' self.app = app.test_client() #db.drop_all() #db.create_all() # Disable sending emails during unit testing #mail.init_app(app) self.assertEqual(app.debug, False)
def test_delete_article(self): with app.app_context(): #articles=db.query_db('select * from articles_v') articles = db.Articles().query.all() #for article in articles: #print(article['id']) with app.test_client() as c: #app.config['DATABASE']='blue/site/Test.db' with c.session_transaction() as session: session['logged_in'] = True session['username'] = '******' # send data as POST form to endpoint for article in articles: #print(article['id']) #sent = {'title':'EDIT'+str(article['id']),'body':str(article['body'])+'-EDIT'} response = c.post('/delete_article/' + str(article.id)) print(response.data) assertTrue(self, response)
def test_edit_article(self): #app.config['DATABASE']='blue/site/Test.db' with app.app_context(): articles = db.query_db('select * from articles_v') with app.test_client() as c: with c.session_transaction() as session: session['logged_in'] = True session['username'] = '******' # send data as POST form to endpoint for article in articles: print(article['id'], article['body']) sent = { 'title': 'EDIT' + str(article['id']), 'body': str(article['body']) + '-EDIT' } response = c.post('/edit_article/' + str(article['id']), data=sent) # check result from server with expected data assertTrue(self, response)
def test_open_article(self): with app.app_context(): #articles=db.query_db('select * from articles_v') articles = db.Articles().query.all() #for article in articles: #print(article['id']) with app.test_client() as c: #c.DATABASE = 'Test.db' #app.config['DATABASE']='blue/site/Test.db' #c.config['DATABASE']='Test.db' with c.session_transaction() as session: session['logged_in'] = True session['username'] = '******' # send data as POST form to endpoint for article in articles: print(article.id) print('/article/' + str(article['id'])) response = self.app.get('/article/' + str(article.id), follow_redirects=True) print(response.data) assertTrue(self, response)
def test_add_article(self): #app.config['DATABASE']='blue/site/Test.db' with app.app_context(): for user in db.query_db('select * from users'): print(user['name']) with app.test_client() as c: #app.config['DATABASE']='blue/site/Test.db' with c.session_transaction() as session: session['logged_in'] = True session['username'] = '******' # send data as POST form to endpoint for x in range(5): sent = { 'title': 'test' + str(x), 'body': 'testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest' } response = c.post('/add_article', data=sent) # check result from server with expected data print(response.data) assertTrue(self, response)
def test_register_login(self): #with app.app_context(): #for user in db.query_db('select * from users'): # print(user['name']) with app.test_client() as c: #app.config['DATABASE']='Test.db' #app.config['DATABASE']='blue/site/Test.db' for x in range(1): name = randomString(10) passw = randomString(10) sent = { 'name': 'test' + str(x), 'email': 'email@email' + str(x), 'username': name, 'password': passw } print(sent) response = c.post('/register', data=sent) sent = {'username': name, 'password': passw} request = c.post('/login', data=sent) print(request.data) # check result from server with expected data assertTrue(self, response) assertTrue(self, request)
def test_book_status(self): tester = app.test_client(self) response = tester.get('/book/2') self.assertEqual(response.content_type, 'application/json')
def test_routes_require_login(self): tester = app.test_client(self) response = tester.get('/dashboard', follow_redirects=True) self.assertIn(b'Unathorized, Please Login', response.data)
def test_all_book_status(self): tester = app.test_client(self) response = tester.get('/book?id=2') self.assertEqual(response.content_type, 'text/html; charset=utf-8')
def test_all_books(self): tester = app.test_client(self) response = tester.get('/book?id=2', follow_redirects=True) self.assertIn(b'"author": "Unknown"', response.data)
def test_login(self): tester = app.test_client(self) response = tester.get('/login', content_type='html/text') self.assertEqual(response.status_code, 200)
def test_book(self): tester = app.test_client(self) response = tester.get('/book/2') self.assertIn(b'"title": "Scarlet Letter"', response.data)
def test_index_page(self): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertTrue(b'Welcome To Your Book Wish List' in response.data)