From 3da2a9c6a6cc9cb7326ff46a85144ffc5c5a0f5f Mon Sep 17 00:00:00 2001 From: Annielated Date: Wed, 12 May 2021 20:20:51 +0200 Subject: [PATCH] sistemata fixtures creazione repo, aggiunti primi test sulle repo --- .../test/fixtures/flask_client.py | 14 ++++- .../nest_backend/test/test_zrepository.py | 56 ++++++++++++------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/code/backend/nest_backend/test/fixtures/flask_client.py b/code/backend/nest_backend/test/fixtures/flask_client.py index a760ea3..ef3ee89 100644 --- a/code/backend/nest_backend/test/fixtures/flask_client.py +++ b/code/backend/nest_backend/test/fixtures/flask_client.py @@ -65,9 +65,17 @@ def user_exists(admin_headers, flask_client): @pytest.fixture(scope="package") -def repository_exists(admin_headers, flask_client): - flask_client.post(f'/api/v1/repository/', headers=admin_headers, json={ - 'name': 'repo1' +def repository_exists(user_headers, flask_client): + r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={ + 'conditions': [ + { + 'content': 'PdS2021', + 'id': 0, + 'type': 0 + } + ], + 'evaluation_mode': 0, + 'name': 'repo_1' }) diff --git a/code/backend/nest_backend/test/test_zrepository.py b/code/backend/nest_backend/test/test_zrepository.py index ff61e59..0df6db0 100644 --- a/code/backend/nest_backend/test/test_zrepository.py +++ b/code/backend/nest_backend/test/test_zrepository.py @@ -8,41 +8,55 @@ class TestRepositoryGetAll: r = flask_client.get(f'/api/v1/repositories/', headers=user_headers, json={'owner_id': 'utente_test@nest.com', 'isActive': False}) assert r.json["result"] == "success" - # assert r.json["data"]["email"] == "admin@admin.com" - # assert r.json["data"]["isAdmin"] is True + # assert r.json["data"]["owner"] == "utente_test@nest.com" + # assert r.json["data"]["isAdmin"] is not True def test_get_all_admin_repositories(self, flask_client: Client, admin_headers): r = flask_client.get(f'/api/v1/repositories/', headers=admin_headers, json={'owner_id': 'admin@admin.com', 'isActive': False}) assert r.json["result"] == "success" - # assert r.json["data"]["email"] == "admin@admin.com" + # assert r.json["data"]["owner"] == "admin@admin.com" # assert r.json["data"]["isAdmin"] is True -''' - def test_non_existing_user(self, flask_client: Client, admin_headers): - r = flask_client.get(f'/api/v1/users/ciccio@dev.com', headers=admin_headers) - assert r.json["result"] == "failure" - assert r.json["msg"] == "Could not locate the user." -class TestUserAdd: - def test_for_success(self, flask_client: Client, admin_headers): - r = flask_client.post(f'/api/v1/users/', headers=admin_headers, json={ - 'email': 'utente1_test@nest.com', - 'password': 'password', - 'username': 'utente_test' +class TestRepositoryAdd: + def test_for_success(self, flask_client: Client, user_headers): + r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={ + 'conditions': [ + { + 'content': 'PdS2021', + 'id': 0, + 'type': 0 + } + ], + 'evaluation_mode': 0, + 'name': 'repo_test', + 'is_active': True }) - assert b'success' in r.data + assert r.json["result"] == "success" + assert r.json["data"]["is_active"] is True + + # non vengono passate le condizioni necessarie, in questo caso il nome della repository def test_for_failure(self, flask_client: Client, user_headers): - r = flask_client.post(f'/api/v1/users/', headers=user_headers, json={ - 'email': 'utente_test@nest.com', - 'password': 'password', - 'username': 'utente_test' + r = flask_client.post(f'/api/v1/repositories/', headers=user_headers, json={ + 'conditions': [ + { + 'content': 'PdS2021', + 'id': 0, + 'type': 0 + } + ], + 'evaluation_mode': 0, + + 'is_active': True }) - assert b'failure' in r.data - + assert r.json["msg"] == "Missing arguments." + assert r.json["result"] == "failure" + +''' class TestUserDelete: def test_for_success(self, flask_client: Client, admin_headers): r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=admin_headers)