Skip to content

Commit d5b87ed

Browse files
committed
Add unit test for metadata creation and querying
1 parent 8af2e88 commit d5b87ed

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/pbench/test/unit/server/test_user_auth.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pbench.server.database.models.users import User
44
from pbench.server.database.models.active_tokens import ActiveTokens
55
from pbench.server.database.database import Database
6+
from pbench.server.api.resources.models import MetadataModel
67

78

89
def register_user(
@@ -423,3 +424,50 @@ def test_delete_user(client, server_config):
423424
data = response.json
424425
assert data["message"] == "Successfully deleted."
425426
assert response.status_code == 200
427+
428+
429+
class TestMetadataSession:
430+
@staticmethod
431+
def test_registration(client, server_config, pytestconfig):
432+
client.config["SESSION_FILE_DIR"] = pytestconfig.cache.get("TMP", None)
433+
""" Test for user registration """
434+
with client:
435+
response = register_user(
436+
client,
437+
server_config,
438+
username="user",
439+
firstname="firstname",
440+
lastname="lastName",
441+
442+
password="12345",
443+
)
444+
data = response.json
445+
assert data["status"] == "success"
446+
447+
response = login_user(client, server_config, "user", "12345")
448+
data_login = response.json
449+
assert data_login["status"] == "success"
450+
451+
response = client.post(
452+
f"{server_config.rest_uri}/user/metadata",
453+
json={"config": "config1", "description": "description1"},
454+
headers=dict(Authorization="Bearer " + data_login["auth_token"])
455+
)
456+
data = response.json
457+
assert data["status"] == "success"
458+
459+
response = client.post(
460+
f"{server_config.rest_uri}/user/metadata",
461+
json={"config": "config2", "description": "description2"},
462+
headers=dict(Authorization="Bearer " + data_login["auth_token"])
463+
)
464+
data = response.json
465+
assert data["status"] == "success"
466+
467+
response = client.get(
468+
f"{server_config.rest_uri}/user/metadata",
469+
headers=dict(Authorization="Bearer " + data_login["auth_token"])
470+
)
471+
data = response.json
472+
assert data["status"] == "success"
473+
assert response.status_code == 200

0 commit comments

Comments
 (0)