Skip to content

Commit c222072

Browse files
authored
Refactor test dirs unit integration (#9)
* refactored test dirs /unit and /integration in preparation for next wave of dev. test_ends in /unit should fail Signed-off-by: 2byrds <2byrds@gmail.com>
1 parent 9031ade commit c222072

File tree

5 files changed

+100
-15
lines changed

5 files changed

+100
-15
lines changed

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
3+
4+
def pytest_collection_modifyitems(config, items):
5+
if not config.getoption("-m"):
6+
skip_manual = pytest.mark.skip(reason="need to add -m 'manual' option to run")
7+
for item in items:
8+
if "manual" in item.keywords:
9+
item.add_marker(skip_manual)

tests/regps/integration/test_service.py renamed to tests/integration/test_service_integration.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
# Set the log level to include all messages.
1919
logger.setLevel(logging.DEBUG)
2020

21-
@pytest.fixture(scope='session')
21+
22+
@pytest.fixture(scope="session")
2223
def start_gunicorn():
2324
# Start Gunicorn server in a separate thread
24-
server = simple_server.make_server('0.0.0.0', 8000, service.app)
25+
server = simple_server.make_server("0.0.0.0", 8000, service.app)
2526
server_thread = threading.Thread(target=server.serve_forever)
2627
server_thread.start()
2728
# Give it some time to start up
@@ -30,16 +31,19 @@ def start_gunicorn():
3031
# Stop Gunicorn server after tests have finished
3132
server.shutdown()
3233
server_thread.join()
33-
34-
@pytest.mark.manual
34+
35+
36+
@pytest.mark.manual
3537
def test_service_integration(start_gunicorn):
3638
logger.info("Running test_local so that you can debug the server")
3739
while True:
3840
time.sleep(1)
3941

40-
#currently needs a pre-loaded vlei-verifier populated per signify-ts vlei-verifier test
42+
43+
# TODO use this test as a basis for an integration test (rather than simulated unit test)
44+
# currently needs a pre-loaded vlei-verifier populated per signify-ts vlei-verifier test
4145
@pytest.mark.manual
42-
def test_ends():
46+
def test_ends_integration(start_gunicorn):
4347
# AID and SAID should be the same as what is in credential.cesr for the ECR credential
4448
# see https://trustoverip.github.io/tswg-acdc-specification/#top-level-fields to understand the fields/values
4549
AID = "EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x"
@@ -63,22 +67,26 @@ def test_ends():
6367

6468
app = service.falcon_app()
6569
client = falcon.testing.TestClient(app)
66-
70+
6771
result = client.simulate_get(f"/ping", headers=headers)
6872
assert result.status == falcon.HTTP_200
6973
assert result.text == "Pong"
70-
74+
7175
# result = client.simulate_get(f"/checklogin/{AID}", headers=headers)
7276
# assert result.status == falcon.HTTP_200
73-
74-
with open(f"./data/credential.cesr", 'r') as cfile:
77+
78+
with open(f"./data/credential.cesr", "r") as cfile:
7579
vlei_ecr = cfile.read()
76-
headers['Content-Type'] = 'application/json+cesr'
77-
result = client.simulate_post(f"/login", json={"said": SAID, "vlei": vlei_ecr}, headers=headers)
80+
headers["Content-Type"] = "application/json+cesr"
81+
result = client.simulate_post(
82+
f"/login", json={"said": SAID, "vlei": vlei_ecr}, headers=headers
83+
)
7884
assert result.status == falcon.HTTP_202
79-
85+
8086
result = client.simulate_get(f"/checklogin/{AID}", headers=headers)
8187
assert result.status == falcon.HTTP_200
82-
88+
8389
result = client.simulate_get(f"/status/{AID}", headers=headers)
84-
assert result.status == falcon.HTTP_401 # fail because this signature should not verify
90+
assert (
91+
result.status == falcon.HTTP_401
92+
) # fail because this signature should not verify
File renamed without changes.

tests/unit/test_service.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import falcon
2+
from falcon.testing import create_environ
3+
import logging
4+
import pytest
5+
from regps.app import service
6+
import sys
7+
import time
8+
import threading
9+
from wsgiref import simple_server
10+
11+
# Create a logger object.
12+
logger = logging.getLogger(__name__)
13+
14+
# Configure the logger to write messages to stdout.
15+
handler = logging.StreamHandler(sys.stdout)
16+
logger.addHandler(handler)
17+
18+
# Set the log level to include all messages.
19+
logger.setLevel(logging.DEBUG)
20+
21+
22+
def test_ends():
23+
# AID and SAID should be the same as what is in credential.cesr for the ECR credential
24+
# see https://trustoverip.github.io/tswg-acdc-specification/#top-level-fields to understand the fields/values
25+
AID = "EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x"
26+
SAID = "EElnd1DKvcDzzh7u7jBjsg2X9WgdQQuhgiu80i2VR-gk"
27+
28+
# got these from signify-ts integration test
29+
headers = {
30+
"HOST": "localhost:7676",
31+
"CONNECTION": "keep-alive",
32+
"METHOD": "POST",
33+
"SIGNATURE": 'indexed="?0";signify="0BBbeeBw3lVmQWYBpcFH9KmRXZocrqLH_LZL4aqg5W9-NMdXqIYJ-Sao7colSTJOuYllMXFfggoMhkfpTKnvPhUF"',
34+
"SIGNATURE-INPUT": 'signify=("@method" "@path" "signify-resource" "signify-timestamp");created=1714854033;keyid="BPoZo2b3r--lPBpURvEDyjyDkS65xBEpmpQhHQvrwlBE";alg="ed25519"',
35+
"SIGNIFY-RESOURCE": "EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x",
36+
"SIGNIFY-TIMESTAMP": "2024-05-04T20:20:33.730000+00:00",
37+
"ACCEPT": "*/*",
38+
"ACCEPT-LANGUAGE": "*",
39+
"SEC-FETCH-MODE": "cors",
40+
"USER-AGENT": "node",
41+
"ACCEPT-ENCODING": "gzip, deflate",
42+
}
43+
44+
app = service.falcon_app()
45+
client = falcon.testing.TestClient(app)
46+
47+
result = client.simulate_get(f"/ping", headers=headers)
48+
assert result.status == falcon.HTTP_200
49+
assert result.text == "Pong"
50+
51+
# result = client.simulate_get(f"/checklogin/{AID}", headers=headers)
52+
# assert result.status == falcon.HTTP_200
53+
54+
with open(f"./data/credential.cesr", "r") as cfile:
55+
vlei_ecr = cfile.read()
56+
headers["Content-Type"] = "application/json+cesr"
57+
result = client.simulate_post(
58+
f"/login", json={"said": SAID, "vlei": vlei_ecr}, headers=headers
59+
)
60+
assert result.status == falcon.HTTP_202
61+
62+
result = client.simulate_get(f"/checklogin/{AID}", headers=headers)
63+
assert result.status == falcon.HTTP_200
64+
65+
result = client.simulate_get(f"/status/{AID}", headers=headers)
66+
assert (
67+
result.status == falcon.HTTP_401
68+
) # fail because this signature should not verify
File renamed without changes.

0 commit comments

Comments
 (0)