def test_register(self): tester = app.test_client(self) response = tester.post('/register', data=dict(login='******', password='******'), follow_redirects=True) statuscode = response.status_code assert statuscode == 200
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = app.config['TEST_SQLALCHEMY_DATABASE_URI'] self.app = app.test_client() db.drop_all() db.create_all()
def test_logout(self): tester = app.test_client(self) response1 = tester.post('/login', data=dict(login='******', password='******'), follow_redirects=True) statuscode1 = response1.status_code assert statuscode1 == 200 response = tester.get('/logout') statuscode = response.status_code assert statuscode == 302
def test_posts(self): tester = app.test_client(self) article = Article(title='test_title', intro='test_intro', text='test_text', user=self.new_user) db.session.add(article) db.session.commit() response = tester.get(f'/post/{article.id}') statuscode = response.status_code assert statuscode == 200
def test_create(self): tester = app.test_client(self) response1 = tester.post('/login', data=dict(login='******', password='******'), follow_redirects=True) statuscode1 = response1.status_code assert statuscode1 == 200 response = tester.post('/create', data=dict(title='test_title', intro='test_intro', text='test_text', user=self.new_user), follow_redirects=True) statuscode = response.status_code assert statuscode == 200
def test_update_get(self): tester = app.test_client(self) response1 = tester.post('/login', data=dict(login='******', password='******'), follow_redirects=True) statuscode1 = response1.status_code assert statuscode1 == 200 article = Article(title='test_title', intro='test_intro', text='test_text', user=self.new_user) db.session.add(article) db.session.commit() response = tester.get(f'/post/{article.id}/update') statuscode = response.status_code assert statuscode == 200
def login(self): client = app.test_client() login_data = { 'username': registration_data['username'], 'password': registration_data['password'] } res = client.post('/login', data=login_data) # Assert that the user was redirected to the home assert res.status_code == 302 with client.session_transaction() as sess: user_id = sess['user_id'] # Assert that a session has been created for the user assert user_id == "1"
def register(self): client = app.test_client() res = client.post('/register', data=registration_data) # Assert that the user was redirected to the login page assert res.status_code == 302 user = User.query.filter_by(username=registration_data['username'], email=registration_data['email'], mobile=str(0) + registration_data['mobile']).first() # Assert that the user was found self.assertTrue(user) # Assert that the password recieved the same hash self.assertTrue(user.password == registration_data['password'])
def test_db(): """ The procedure to run the database testing functions and write to file :return: void """ i = 1 app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db') test_app = app.test_client() db.create_all() db.session.commit() for test in db_tests: clear_all_tables() write_output("Database Schema Test " + str(i) + "\n----------") tester(test) i += 1
def test_funcs(): """ The procedure to run the search query function tests and write to file :return: void """ i = 1 app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db') test_app = app.test_client() db.create_all() db.engine.execute("DROP TABLE IF EXISTS usersfts") db.engine.execute("CREATE VIRTUAL TABLE usersfts USING FTS5(username, first_name, last_name, email, school, state)") db.session.commit() from create_test_users import run run() for test in func_tests: write_output("Search Query Test " + str(i) + "\n----------") tester(test) i += 1
def test__change_is_not_full(self): tester = app.test_client(self) response = tester.post('/change', data=dict(password="******"), follow_redirects=True) self.assertIn(b'please fill all fields', response.data)
def fake_client(): app.debug = True return app.test_client()
def test_post(self): tester = app.test_client(self) response = tester.get('/post') statuscode = response.status_code assert statuscode == 200
def test_user(self): tester = app.test_client(self) response = tester.get(f'/post/{self.user}') statuscode = response.status_code assert statuscode == 200
def test_register_get(self): tester = app.test_client(self) response = tester.get('/register') statuscode = response.status_code assert statuscode == 200
def test_registration_page(self): client = app.test_client() res = client.get('/register') assert res.status_code == 200
def test_incorrect_login(self): tester = app.test_client(self) response = tester.post('/login', data=dict(login="******", password="******"), follow_redirects=True) self.assertIn(b'Login or password is not correct', response.data)
def client(): app_client = app.test_client() app_context = app.app_context() app_context.push() yield app_client app_context.pop()
def test_login_page(self): client = app.test_client() res = client.get('/login') assert res.status_code == 200
def test_change1(self): tester = app.test_client(self) response = tester.get('/change') statuscode = response.status_code assert statuscode == 200