Advertisement
Guest User

Untitled

a guest
Jun 8th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. import unittest
  2.  
  3. from flask_testing import TestCase
  4. from app import app, db, bcrypt
  5. from app.models import User
  6.  
  7.  
  8. class BaseTestCase(TestCase):
  9.  
  10.     def create_app(self):
  11.         app.config['TESTING'] = True
  12.         app.config['CSRF_ENABLED'] = False
  13.         app.config['WTF_CSRF_ENABLED'] = False
  14.         app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
  15.         return app
  16.  
  17.     def setUp(self):
  18.         db.create_all()
  19.         user = User(
  20.                 username="admin",
  21.                 email="ad@min.com",
  22.                 password=bcrypt.generate_password_hash("admin")
  23.             )
  24.         db.session.add(user)
  25.         db.session.commit()
  26.  
  27.     def tearDown(self):
  28.         db.session.remove()
  29.         db.drop_all()
  30.  
  31.  
  32. class TestLoginMixin(BaseTestCase):
  33.  
  34.     def login_user(self, login, password):
  35.  
  36.         with self.app.test_request_context('/account/login/'):
  37.             self.app.preprocess_request()
  38.             data = {'username': login, 'password': password}
  39.             response = self.client.post('/account/login/', data=data)
  40.  
  41.             return response
  42.  
  43.  
  44. class LoginTest(TestLoginMixin):
  45.  
  46.     user = {'login': 'admin', 'password': 'admin'}
  47.  
  48.     def test_change_password(self):
  49.         """TEST: change password"""
  50.  
  51.         response = self.login_user(**self.user)
  52.         print(response.status_code)
  53.         response = self.client.post('/account/change_password/', data=dict(old='admin', new='newadmin', confirm='newadmin'))
  54.         print(response.data, response.status_code)
  55.  
  56. if __name__ == '__main__':
  57.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement