From 844445a0fa14378412ccd0e97dd2489d1bbd40b0 Mon Sep 17 00:00:00 2001 From: stefanogoldoni Date: Fri, 14 May 2021 00:13:33 +0200 Subject: [PATCH] test repository --- nest_backend/routes/repository/repositories.py | 7 ++++--- nest_backend/test/test_zrepository.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/nest_backend/routes/repository/repositories.py b/nest_backend/routes/repository/repositories.py index eea48bc..796484a 100644 --- a/nest_backend/routes/repository/repositories.py +++ b/nest_backend/routes/repository/repositories.py @@ -70,15 +70,16 @@ def page_repositories(): spectator = spectator.filter(not Repository.is_active) owner = owner.all() spectator = spectator.all() - 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": # 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 name = request.json.get("name") try: evaluation_mode = ConditionMode(request.json['evaluation_mode']) - except KeyError: + except: # KeyError return json_error("Unknown `type` specified."), 400 repository = Repository(name=name, owner_id=user.email, is_active=False, evaluation_mode=evaluation_mode) ext.session.add(repository) diff --git a/nest_backend/test/test_zrepository.py b/nest_backend/test/test_zrepository.py index 950aee0..8987536 100644 --- a/nest_backend/test/test_zrepository.py +++ b/nest_backend/test/test_zrepository.py @@ -18,12 +18,12 @@ class TestRepositoryAdd: 'name': 'repo_test', 'is_active': True }) - assert r.status_code == 200 + assert r.status_code == 201 assert r.json["result"] == "success" assert r.json["data"]["is_active"] is True # 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={ 'conditions': [ { @@ -36,7 +36,7 @@ class TestRepositoryAdd: 'name': 'repo_admin', 'is_active': True }) - assert r.status_code == 200 + assert r.status_code == 201 assert r.json["result"] == "success" assert r.json["data"]["is_active"] is True