From 008bf242941e8880238b3bc51df62e126aeabd5d Mon Sep 17 00:00:00 2001 From: Vasek Sraier Date: Mon, 1 Apr 2019 18:13:04 +0200 Subject: [PATCH] added server accessibility test --- register.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/register.py b/register.py index 2aabf01..dc46f6a 100644 --- a/register.py +++ b/register.py @@ -1,6 +1,7 @@ from swagger_client.api.admin_api import AdminApi from swagger_client.api.user_api import UserApi from swagger_client.api.organization_api import OrganizationApi +from swagger_client.api.miscellaneous_api import MiscellaneousApi from swagger_client.api_client import ApiClient from swagger_client.models import CreateUserOption, Team, User, Organization from swagger_client.rest import ApiException @@ -12,10 +13,7 @@ from bs4 import BeautifulSoup as bs import random import string - # load configuration -from typing import List - try: import config except ImportError: @@ -41,6 +39,14 @@ def text_orange(text) -> str: return termcolor.colored(text, 'yellow') +def is_server_accesible(misc_api: MiscellaneousApi) -> bool: + try: + _ = misc_api.get_version() + return True + except: + return False + + def does_user_exist(user_api: UserApi, username: str) -> bool: try: user = user_api.user_get(username) @@ -163,17 +169,20 @@ def register(username: str, seminar: str, fullname: str, email: str, host, admin ADMIN_TOKEN = admin_token if admin_token is not None else ADMIN_TOKEN api_client = ApiClient() - api_client.configuration.host = host if host is not None else HOST - api_client.configuration.api_key = {'token': admin_token if admin_token is not None else ADMIN_TOKEN} + api_client.configuration.host = HOST + api_client.configuration.api_key = {'token': ADMIN_TOKEN} admin_api = AdminApi(api_client) user_api = UserApi(api_client) org_api = OrganizationApi(api_client) + misc_api = MiscellaneousApi(api_client) # kontrola predpokladu o stavu systemu + validate(lambda: is_server_accesible(misc_api), "Server je dostupny...") validate(lambda: not does_user_exist(user_api, username), "Uzivatelske jmeno je volne...") validate(lambda: does_organization_exist(org_api, seminar), "Organizace pro seminar existuje...") - validate(lambda: does_organization_have_team_with_name(org_api, seminar, 'org'), "V danem seminari existuje team 'org'...") + validate(lambda: does_organization_have_team_with_name(org_api, seminar, 'org'), + "V danem seminari existuje team 'org'...") print(text_green('Zakladni predpoklady pro uspesne zalozeni uctu splneny!\n')) # nasbirame vsechny potrebne informace