diff options
| author | Mitsuo Tokumori <[email protected]> | 2023-10-29 06:59:37 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2023-10-29 06:59:37 -0500 |
| commit | 9baa55436bc5a98d118a17656bbf25e563522964 (patch) | |
| tree | daa01118bd11f5cf13d386d2c727a384563df1da /tests/conftest.py | |
| parent | 71e7d6516608486f67afad5aad1f7b7f9a45886f (diff) | |
| download | ustayml-9baa55436bc5a98d118a17656bbf25e563522964.tar.gz ustayml-9baa55436bc5a98d118a17656bbf25e563522964.tar.bz2 ustayml-9baa55436bc5a98d118a17656bbf25e563522964.zip | |
Add unit tests
Diffstat (limited to 'tests/conftest.py')
| -rw-r--r-- | tests/conftest.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..45079a9 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,61 @@ +"""contains setup functions called fixtures that each test will use""" + +import os +import tempfile + +import pytest +from flaskr import create_app +from flaskr.db import get_db, init_db + +with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f: + _data_sql = f.read().decode('utf8') + + +def app(): + db_fd, db_path = tempfile.mkstemp() + + app = create_app({ + 'TESTING': True, + 'DATABASE': db_path, + }) + + with app.app_context(): + init_db() + get_db().executescript(_data_sql) + + yield app + + os.close(db_fd) + os.unlink(db_path) + + +def client(app): + """can make requests to the app without running the server""" + return app.test_client() + + +def runner(app): + """can all the Click commands registered with the application""" + return app.test_cli_runner() + + +class AuthActions(object): + def __init__(self, client): + self._client = client + + def login(self, username='test', password='test'): + return self._client.post( + '/auth/login', + data={'username': username, 'password': password} + ) + + def logout(self): + return self._client.get('/auth/logout') + + +def auth(client): + return AuthActions(client)
\ No newline at end of file |
