Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- from flask_testing import TestCase
- from app import app, db, bcrypt
- from app.models import User
- class BaseTestCase(TestCase):
- def create_app(self):
- app.config['TESTING'] = True
- app.config['CSRF_ENABLED'] = False
- app.config['WTF_CSRF_ENABLED'] = False
- app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
- return app
- def setUp(self):
- db.create_all()
- user = User(
- username="admin",
- email="ad@min.com",
- password=bcrypt.generate_password_hash("admin")
- )
- db.session.add(user)
- db.session.commit()
- def tearDown(self):
- db.session.remove()
- db.drop_all()
- class TestLoginMixin(BaseTestCase):
- def login_user(self, login, password):
- with self.app.test_request_context('/account/login/'):
- self.app.preprocess_request()
- data = {'username': login, 'password': password}
- response = self.client.post('/account/login/', data=data)
- return response
- class LoginTest(TestLoginMixin):
- user = {'login': 'admin', 'password': 'admin'}
- def test_change_password(self):
- """TEST: change password"""
- response = self.login_user(**self.user)
- print(response.status_code)
- response = self.client.post('/account/change_password/', data=dict(old='admin', new='newadmin', confirm='newadmin'))
- print(response.data, response.status_code)
- if __name__ == '__main__':
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement