dankventskalender migrate to flask
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1KB

  1. import os
  2. import tempfile
  3. import pytest
  4. from calender import create_app
  5. from calender.db import get_db, init_db
  6. with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f:
  7. _data_sql = f.read().decode('utf8')
  8. @pytest.fixture
  9. def app():
  10. db_fd, db_path = tempfile.mkstemp()
  11. app = create_app({
  12. 'TESTING': True,
  13. 'DATABASE': db_path,
  14. })
  15. with app.app_context():
  16. init_db()
  17. get_db().executescript(_data_sql)
  18. yield app
  19. os.close(db_fd)
  20. os.unlink(db_path)
  21. @pytest.fixture
  22. def client(app):
  23. return app.test_client()
  24. @pytest.fixture
  25. def runner(app):
  26. return app.test_cli_runner()
  27. class AuthActions(object):
  28. def __init__(self, client):
  29. self._client = client
  30. def login(self, username='test', password='test'):
  31. return self._client.post(
  32. '/auth/login',
  33. data={'username': username, 'password': password}
  34. )
  35. def logout(self):
  36. return self._client.get('/auth/logout')
  37. @pytest.fixture
  38. def auth(client):
  39. return AuthActions(client)