PageRenderTime 66ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/weiqi/test/__init__.py

https://gitlab.com/Xylol/weiqi.gs
Python | 42 lines | 17 code | 7 blank | 18 comment | 0 complexity | 3ab0aa58bc714c6bbaa0f6eed9593633 MD5 | raw file
  1. # weiqi.gs
  2. # Copyright (C) 2016 Michael Bitzi
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import os
  17. from sqlalchemy.orm import scoped_session
  18. from weiqi import settings
  19. from weiqi.db import Session, create_db, create_schema
  20. settings.DEBUG = False
  21. settings.DB_URL = os.environ.get('WEIQI_TEST_DB', 'sqlite://')
  22. settings.RECAPTCHA['backend'] = 'dummy'
  23. settings.MAILER['backend'] = 'console'
  24. create_db()
  25. create_schema()
  26. session = scoped_session(Session)
  27. # Patch the `weiqi.db.sessions` contextmanager to use the same session as other parts of the testing framework, such as
  28. # in factory boy.
  29. # This is mainly used to test tornado request handlers.
  30. from contextlib import contextmanager
  31. @contextmanager
  32. def _patched_session():
  33. yield session
  34. from weiqi import db
  35. db.session = _patched_session