-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
631cd16
commit 4694748
Showing
8 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from flask import Flask | ||
|
||
|
||
def create_basic_user(app: Flask): | ||
client = app.test_client() | ||
client.post( | ||
"/api/auth/register/new-account", | ||
json={ | ||
"email": "[email protected]", | ||
"username": "super_username", | ||
"password": "123secret", | ||
"public_key": "PGP_PUBLIC_KEY", | ||
"private_key": "PGP_SECRET_KEY", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask import Flask | ||
from ._utils import create_basic_user | ||
|
||
|
||
def test_valid_login(app: Flask): | ||
create_basic_user(app) | ||
client = app.test_client() | ||
res = client.post("/api/auth/session/login", json={"email": "[email protected]", "password": "123secret"}) | ||
assert res.json["id"] is not None | ||
|
||
headers = " ".join(res.headers.getlist("Set-Cookie")) | ||
|
||
# Check that a session coookie is created | ||
assert "session=" in headers | ||
|
||
|
||
def test_invalid_login(app: Flask): | ||
create_basic_user(app) | ||
client = app.test_client() | ||
res = client.post("/api/auth/session/login", json={"email": "[email protected]", "password": "wrong"}) | ||
assert res.status_code == 401 | ||
|
||
|
||
def test_logout(app: Flask): | ||
create_basic_user(app) | ||
client = app.test_client() | ||
|
||
# Check we cannot logout without being authenticated | ||
res = client.post("/api/auth/session/logout") | ||
assert res.status_code == 401 | ||
|
||
# Login and Logout | ||
client.post("/api/auth/session/login", json={"email": "[email protected]", "password": "123secret"}) | ||
res = client.post("/api/auth/session/logout") | ||
assert res.status_code == 204 | ||
print(" ".join(res.headers.getlist("Set-Cookie"))) | ||
assert "session=;" in " ".join(res.headers.getlist("Set-Cookie")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from flask import Flask | ||
from pyneutrino import create_app | ||
|
||
|
||
def test_wait_db_command_success(app: Flask): | ||
runner = app.test_cli_runner() | ||
result = runner.invoke(args=["wait-db", "--timeout", "1"]) | ||
assert "The database is available" in result.output | ||
|
||
|
||
def test_wait_db_command_failure(): | ||
app = create_app( | ||
{ | ||
"TESTING": True, | ||
"SQLALCHEMY_DATABASE_URI": "postgresql://127.0.0.2:5432/nope?connect_timeout=1", | ||
} | ||
) | ||
runner = app.test_cli_runner() | ||
result = runner.invoke(args=["wait-db", "--timeout", "0"]) | ||
assert "Failed to connect to the database" in result.output |