diff options
author | Frederick Muriuki Muriithi | 2023-01-18 14:59:35 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-01-18 14:59:35 +0300 |
commit | 4cc328ef78c7b8108d7623fdd4fcae5294317f2e (patch) | |
tree | 5fff59d3a57bb6e0ec044373f205ed4503d8b47a /tests/unit/auth/test_token.py | |
parent | e97703817628e6b781c5b883ed3aa7fbf9967628 (diff) | |
download | genenetwork3-4cc328ef78c7b8108d7623fdd4fcae5294317f2e.tar.gz |
auth: Fix tests after enforcing FOREIGN KEY constraint
Fix a number of tests and fixtures that were not conforming to the FOREIGN KEY
constraints:
* Each test that creates a new "object" needs to clean up after itself
* Each fixture that sets up test data needs to clean up after itself
Diffstat (limited to 'tests/unit/auth/test_token.py')
-rw-r--r-- | tests/unit/auth/test_token.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/unit/auth/test_token.py b/tests/unit/auth/test_token.py index a1709bf..76316ea 100644 --- a/tests/unit/auth/test_token.py +++ b/tests/unit/auth/test_token.py @@ -2,6 +2,8 @@ import pytest +from gn3.auth import db + SUCCESS_RESULT = { "status_code": 200, "result": { @@ -42,7 +44,7 @@ def test_token(fxtr_app, fxtr_oauth2_clients, test_data, expected): back c) TODO: when user tries to use wrong client, we get error message back """ - _conn, oa2clients = fxtr_oauth2_clients + conn, oa2clients = fxtr_oauth2_clients email, password, client_idx = test_data data = { "grant_type": "password", "scope": "profile nonexistent-scope", @@ -50,8 +52,11 @@ def test_token(fxtr_app, fxtr_oauth2_clients, test_data, expected): "client_secret": oa2clients[client_idx].client_secret, "username": email, "password": password} - with fxtr_app.test_client() as client: + with fxtr_app.test_client() as client, db.cursor(conn) as cursor: res = client.post("/api/oauth2/token", data=data) + # cleanup db + cursor.execute("DELETE FROM oauth2_tokens WHERE access_token=?", + (gen_token(None, None, None, None),)) assert res.status_code == expected["status_code"] for key in expected["result"]: assert res.json[key] == expected["result"][key] |