diff options
author | neodarz <neodarz@neodarz.net> | 2018-06-16 17:52:31 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-06-16 17:52:31 +0200 |
commit | 5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd (patch) | |
tree | f4e72ed3712a148a28a0c11323f1796f7499a336 /src/tests | |
parent | cf29b5d4324b03d826615cfbb7f7345c54da1762 (diff) | |
download | liberationCenter-5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd.tar.xz liberationCenter-5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd.zip |
Add first structure of the application
Diffstat (limited to '')
-rw-r--r-- | src/tests/conftest.py | 34 | ||||
-rw-r--r-- | src/tests/test_api.py | 22 | ||||
-rw-r--r-- | src/tests/test_db.py | 8 | ||||
-rw-r--r-- | src/tests/test_factory.py | 5 | ||||
-rw-r--r-- | src/tests/test_user.py | 15 |
5 files changed, 84 insertions, 0 deletions
diff --git a/src/tests/conftest.py b/src/tests/conftest.py new file mode 100644 index 0000000..6a54ae4 --- /dev/null +++ b/src/tests/conftest.py @@ -0,0 +1,34 @@ +import pytest +from lb_app import create_app +from lb_app.app_db.db import MongoDB + +import pprint + +data = {'username': 'neo'} + +@pytest.fixture +def app(): + app = create_app({ + 'TESTING': True + }) + + app.config.from_mapping( + MONGO_URI= 'mongodb://localhost:27017/test_liberationCenter' + ) + + + with app.app_context(): + db = MongoDB(app) + db.set_up() + mongo = db.connection() + mongo.db.users.insert_one(data) + + yield app + +@pytest.fixture +def client(app): + return app.test_client() + +@pytest.fixture +def runner(app): + return app.test_cli_runner() diff --git a/src/tests/test_api.py b/src/tests/test_api.py new file mode 100644 index 0000000..063f32f --- /dev/null +++ b/src/tests/test_api.py @@ -0,0 +1,22 @@ +import pytest, re + +from flask import session +from bson.json_util import dumps + +from pprint import pprint + +def test_api_get_all_users(client, app): + response = client.get('/api/users') + assert response.status_code == 200 + assert response.is_json + assert re.search('username', str(response.data)) + +@pytest.mark.parametrize(('username', 'message'), ( + ('', b'{"msg": "Username is required."}'), + ('neo', b'{"msg": "User neo is already registered."}'), + ('neodarz', b'{"msg": "done"}') +)) +def test_api_register(client, app, username, message): + response = client.post('/api/user/register', data='{"username": "'+username+'"}') + print(response.data) + assert message in response.data diff --git a/src/tests/test_db.py b/src/tests/test_db.py new file mode 100644 index 0000000..5830f78 --- /dev/null +++ b/src/tests/test_db.py @@ -0,0 +1,8 @@ +import pytest + +from lb_app.app_db.db import MongoDB + +def test_get_close_db(app): + with app.app_context(): + db = MongoDB(app) + assert type(db) is MongoDB diff --git a/src/tests/test_factory.py b/src/tests/test_factory.py new file mode 100644 index 0000000..20a10b4 --- /dev/null +++ b/src/tests/test_factory.py @@ -0,0 +1,5 @@ +from lb_app import create_app + +def test_config(): + assert not create_app().testing + assert create_app({'TESTING': True}).testing diff --git a/src/tests/test_user.py b/src/tests/test_user.py new file mode 100644 index 0000000..3d7ab50 --- /dev/null +++ b/src/tests/test_user.py @@ -0,0 +1,15 @@ +import pytest, re + +from bson.json_util import dumps + +from lb_app.app_db.user import User + +def test_get_all_users(app): + with app.app_context(): + user = User(app) + assert re.search('username', dumps(user.all())) + +def test_register_user(app): + with app.app_context(): + user = User(app) + assert user.register("neodarz") is None |