1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00

test repository

This commit is contained in:
stefanogoldoni 2021-05-14 00:13:33 +02:00
parent e9922fb483
commit 844445a0fa
2 changed files with 7 additions and 6 deletions

View file

@ -73,12 +73,13 @@ def page_repositories():
return json_success([r.to_json() for r in owner] + [r.repository.to_json() for r in spectator]) return json_success([r.to_json() for r in owner] + [r.repository.to_json() for r in spectator])
elif request.method == "POST": elif request.method == "POST":
# Users will be tolerated if they change parameters they're not supposed to touch. We'll ignore them for now. # Users will be tolerated if they change parameters they're not supposed to touch. We'll ignore them for now.
if not request.json.get("name") or not request.json.get("conditions") or not str(request.json.get("evaluation_mode")): if not request.json.get("name") or not request.json.get("conditions") or not str(
request.json.get("evaluation_mode")):
return json_error("Missing arguments."), 400 return json_error("Missing arguments."), 400
name = request.json.get("name") name = request.json.get("name")
try: try:
evaluation_mode = ConditionMode(request.json['evaluation_mode']) evaluation_mode = ConditionMode(request.json['evaluation_mode'])
except KeyError: except: # KeyError
return json_error("Unknown `type` specified."), 400 return json_error("Unknown `type` specified."), 400
repository = Repository(name=name, owner_id=user.email, is_active=False, evaluation_mode=evaluation_mode) repository = Repository(name=name, owner_id=user.email, is_active=False, evaluation_mode=evaluation_mode)
ext.session.add(repository) ext.session.add(repository)

View file

@ -18,12 +18,12 @@ class TestRepositoryAdd:
'name': 'repo_test', 'name': 'repo_test',
'is_active': True 'is_active': True
}) })
assert r.status_code == 200 assert r.status_code == 201
assert r.json["result"] == "success" assert r.json["result"] == "success"
assert r.json["data"]["is_active"] is True assert r.json["data"]["is_active"] is True
# ne creo un altro come admin # ne creo un altro come admin
def test_for_success(self, flask_client: Client, admin_headers): def test_for_success_admin(self, flask_client: Client, admin_headers):
r = flask_client.post(f'/api/v1/repositories/', headers=admin_headers, json={ r = flask_client.post(f'/api/v1/repositories/', headers=admin_headers, json={
'conditions': [ 'conditions': [
{ {
@ -36,7 +36,7 @@ class TestRepositoryAdd:
'name': 'repo_admin', 'name': 'repo_admin',
'is_active': True 'is_active': True
}) })
assert r.status_code == 200 assert r.status_code == 201
assert r.json["result"] == "success" assert r.json["result"] == "success"
assert r.json["data"]["is_active"] is True assert r.json["data"]["is_active"] is True