Browse Source

added server accessibility test

master
Vašek Šraier 6 years ago
parent
commit
008bf24294
  1. 21
      register.py

21
register.py

@ -1,6 +1,7 @@
from swagger_client.api.admin_api import AdminApi from swagger_client.api.admin_api import AdminApi
from swagger_client.api.user_api import UserApi from swagger_client.api.user_api import UserApi
from swagger_client.api.organization_api import OrganizationApi 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.api_client import ApiClient
from swagger_client.models import CreateUserOption, Team, User, Organization from swagger_client.models import CreateUserOption, Team, User, Organization
from swagger_client.rest import ApiException from swagger_client.rest import ApiException
@ -12,10 +13,7 @@ from bs4 import BeautifulSoup as bs
import random import random
import string import string
# load configuration # load configuration
from typing import List
try: try:
import config import config
except ImportError: except ImportError:
@ -41,6 +39,14 @@ def text_orange(text) -> str:
return termcolor.colored(text, 'yellow') 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: def does_user_exist(user_api: UserApi, username: str) -> bool:
try: try:
user = user_api.user_get(username) 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 ADMIN_TOKEN = admin_token if admin_token is not None else ADMIN_TOKEN
api_client = ApiClient() api_client = ApiClient()
api_client.configuration.host = host if host is not None else HOST api_client.configuration.host = HOST
api_client.configuration.api_key = {'token': admin_token if admin_token is not None else ADMIN_TOKEN} api_client.configuration.api_key = {'token': ADMIN_TOKEN}
admin_api = AdminApi(api_client) admin_api = AdminApi(api_client)
user_api = UserApi(api_client) user_api = UserApi(api_client)
org_api = OrganizationApi(api_client) org_api = OrganizationApi(api_client)
misc_api = MiscellaneousApi(api_client)
# kontrola predpokladu o stavu systemu # 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: 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_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')) print(text_green('Zakladni predpoklady pro uspesne zalozeni uctu splneny!\n'))
# nasbirame vsechny potrebne informace # nasbirame vsechny potrebne informace

Loading…
Cancel
Save