import pytest
import json
from utils.checks import CheckStatusCode, CheckHeaders
from api.api_client import ApiClient

checkHeaders = CheckHeaders()
checkStatusCode = CheckStatusCode()

apiClient = ApiClient(host='httpbin.org')


@pytest.mark.parametrize('header', [{
    'Testheader': 'some value'
}],
                         ids=['Testheader:someValue'])
def test_headers(header):
    response = apiClient.getHeaders(headers=header)

    checkStatusCode.isSuccess(response=response)

    checkHeaders.checkHeaderIn(header=header, response=response)


@pytest.mark.parametrize(
    'code, method, check',
    [(200, apiClient.getStatus, checkStatusCode.isSuccess),
     (202, apiClient.putStatus, checkStatusCode.isAccepted),
     (204, apiClient.postStatus, checkStatusCode.isNoContent),
     (400, apiClient.patchStatus, checkStatusCode.isClientError),
     (500, apiClient.deleteStatus, checkStatusCode.isServerError)],
    ids=['200 get', '202 put', '204 post', '400 patch', '500 delete'])
Example #2
0
from aiogram.utils.callback_data import CallbackData

from api.api_client import ApiClient, ApiClientError
from api.models import Answer, User, ExpertQuestion
from phrases.phrase_handler import PhraseHandler
from phrases.phrase_types import PhraseTypes
from settings import setup_bot
from utils import bot_typing

DEBUG = int(os.getenv("DEBUG", "0")) == 1

bot, dispatcher = setup_bot(os.getenv("API_TOKEN"))

phrase_handler = PhraseHandler()
api_client = ApiClient(
    api_url=f"http://{os.getenv('API_HOST')}:{os.getenv('API_PORT')}",
    loop=bot.loop)

redis = bot.loop.run_until_complete(
    aioredis.create_redis_pool(
        f'redis://{os.getenv("REDIS_HOST")}:{os.getenv("REDIS_PORT")}'))

support_chat_id = int(os.getenv("SUPPORT_CHAT_ID"))

predictors = bot.loop.run_until_complete(api_client.get_all_predictors())

answer_cb = CallbackData('answer_callback', 'id', 'rating', 'predictor')


@dispatcher.message_handler(commands=["start"])
async def send_welcome(message: types.Message):
Example #3
0
 def api_client(self):
     username = '******'
     password = '******'
     email = '*****@*****.**'
     return ApiClient(username, password, email)
def api_client(config):
    user = '******'
    password = '******'
    return ApiClient(config.URL, user, password)
Example #5
0
def api_client(username, password, email):
    return ApiClient(username, password, email)
def api_client(config_api):
    user = '******'
    password = '******'
    client = ApiClient(config_api.URL, user, password)
    return client