Exemple #1
0
    def test_change_settings_no_role(self, delete_session):
        """ Тест попытки изменения настроек гостиницы без авторизационного токена """
        # Задаем данные, на которые нужно изменить настройки
        day_change_time = "13:00:00"
        hello_message_EN = "english text hello_message"
        hello_message_RU = "russian text hello_message"
        memo_EN = "english text memo"
        memo_RU = "russian text memo"
        promo_on_startup_enabled = False

        with allure.step('Запрос на изменение настроек'):
            r = Settings(day_change_time=day_change_time,
                         hello_message_EN=hello_message_EN,
                         hello_message_RU=hello_message_RU,
                         memo_EN=memo_EN,
                         memo_RU=memo_RU,
                         promo_on_startup_enabled=promo_on_startup_enabled
                         ).put_settings()

        with allure.step(
                'Проверки, что без авторизационного токена нельзя выполнить данный метод'
        ):
            assert_that(r.status_code, equal_to(401))
            assert_that(r.json()["error_code"], equal_to(1))
            assert_that(r.json()["description"],
                        equal_to("No 'session_id' header was provided"))
    def _test_change_settings_by_admin_hotel(self, use_session_admin_hotel):
        """ Тест изменения настроек администратором гостиницы """
        # Задаем данные, на которые нужно изменить настройки
        with allure.step('Задаем данные, на которые нужно изменить настройки'):
            day_change_time = "13:00:00"
            hello_message_EN = "english text hello_message"
            hello_message_RU = "russian text hello_message"
            memo_EN = "english text memo"
            memo_RU = "russian text memo"
            promo_on_startup_enabled = False

        with allure.step('Запрос на изменение настроек гостиницы'):
            r = Settings(day_change_time=day_change_time,
                         hello_message_EN=hello_message_EN,
                         hello_message_RU=hello_message_RU,
                         memo_EN=memo_EN,
                         memo_RU=memo_RU,
                         promo_on_startup_enabled=promo_on_startup_enabled
                         ).put_settings()

        with allure.step('Проверка на успешный ответ от сервера'):
            assert_that(r.status_code, equal_to(200))
            assert_that(r.json()["success"], is_(True))

        with allure.step('Получаем список настроек в HTM'):
            r = Settings().get_settings()

        with allure.step('Проверяем, что изменения применились'):
            assert_that(r.json()["day_change_time"], equal_to(day_change_time))
            assert_that(r.json()["memo"], has_entries("EN", equal_to(memo_EN)))
            assert_that(r.json()["hello_message"],
                        has_entries("EN", equal_to(hello_message_EN)))
            assert_that(r.json()["promo_on_startup_enabled"], is_(False))
    def test_get_rooms_by_admin_rt(self, use_session_admin_rt):
        """ Тест попытки получения настроек гостиницы """
        with allure.step('Запрос на получение настроек гостиницы'):
            r = Settings().get_settings()

        with allure.step(
                'Проверки, что администратор Ростелеком не может получить настройки гостиницы'
        ):
            assert_that(r.status_code, equal_to(403))
            assert_that(r.json()["error_code"], equal_to(403))
            assert_that(r.json()["description"], equal_to("Forbidden"))
Exemple #4
0
    def test_get_settings_no_role(self, delete_session):
        """ Тест попытки получения настроек гостиницы без авторизационного токена """
        with allure.step('Запрос на получение настроек гостиницы'):
            r = Settings().get_settings()

        with allure.step(
                'Проверки, что без авторизационного токена нельзя выполнить данный метод'
        ):
            assert_that(r.status_code, equal_to(401))
            assert_that(r.json()["error_code"], equal_to(1))
            assert_that(r.json()["description"],
                        equal_to("No 'session_id' header was provided"))
Exemple #5
0
    def test_change_settings_by_admin_rt(self, use_session_admin_rt):
        """ Тест попытки изменения настроек гостиницы """
        with allure.step('Задаем данные, на которые нужно изменить настройки'):
            day_change_time = "13:00:00"
            hello_message_EN = "english text hello_message"
            hello_message_RU = "russian text hello_message"
            memo_EN = "english text memo"
            memo_RU = "russian text memo"
            promo_on_startup_enabled = False

        with allure.step('Запрос на изменение настроек гостиницы'):
            r = Settings(day_change_time=day_change_time,
                         hello_message_EN=hello_message_EN,
                         hello_message_RU=hello_message_RU,
                         memo_EN=memo_EN,
                         memo_RU=memo_RU,
                         promo_on_startup_enabled=promo_on_startup_enabled
                         ).put_settings()

        with allure.step('Запрос на изменение настроек гостиницы'):
            assert_that(r.status_code, equal_to(403))
            assert_that(r.json()["error_code"], equal_to(403))
            assert_that(r.json()["description"], equal_to("Forbidden"))
def config_rollback():
    original_path = "/repo/api/tests/data/config-x86-openvino.ini"
    config_sample_path_to_modify = "/repo/api/tests/data/config-x86-openvino_TEMPORARY.ini"
    shutil.copyfile(original_path, config_sample_path_to_modify)

    config = ConfigEngine(config_sample_path_to_modify)
    Settings(config=config)

    # Import ProcessorAPI after Settings has been initialized with a config.
    from api.processor_api import ProcessorAPI

    app_instance = ProcessorAPI()
    api = app_instance.app
    client = TestClient(api)
    yield client, config_sample_path_to_modify

    os.remove(config_sample_path_to_modify)
Exemple #7
0
def config_rollback_base(option="JUST_CAMERAS"):
    original_path = ""
    if option == "EMPTY":
        """
        Empty template with no camera or area.
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_EMPTY.ini"
    elif option == "JUST_CAMERAS":
        """
        Here there are charged only 2 cameras:
            camera_example (ID: 49)
            camera_example_2 (ID: 50)
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_JUST_CAMERAS.ini"
    elif option == "METRICS":
        """
        Here there are charged 4 cameras and two areas:
            camera_example (ID: 49), Area 5
            camera_example_2 (ID: 50), Area 5
            camera_example_3 (ID: 51), Area 6
            camera_example_4 (ID: 52), Area 6
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_METRICS.ini"
    config_sample_path_to_modify = "/repo/api/tests/data/config-x86-openvino_TEMPORARY.ini"
    shutil.copyfile(original_path, config_sample_path_to_modify)

    config = ConfigEngine(config_sample_path_to_modify)
    Settings(config=config)

    # Import ProcessorAPI after Settings has been initialized with a config.
    from api.processor_api import ProcessorAPI

    app_instance = ProcessorAPI()
    api = app_instance.app
    client = TestClient(api)
    return client, config_sample_path_to_modify
Exemple #8
0
    def _test_get_rooms_by_admin_hotel(self, use_session_admin_hotel):
        """ Тест получения настроек гостиницы администратором гостиницы """
        with allure.step('Запрос на получение настроек гостиницы'):
            r = Settings().get_settings()

        with allure.step(
                'Проверки: успешный ответ от сервера, текст памятки и приветственного сообщения на разных'
                'языках в ответе'):
            assert_that(r.status_code, equal_to(200))
            assert_that(r.json()["day_change_time"], equal_to("13:00:00"))
            assert_that(
                r.json()["memo"],
                has_entries(
                    "EN", equal_to("english text memo"), "RU",
                    string_contains_in_order("Как включить приставку")))
            assert_that(
                r.json()["hello_message"],
                has_entries("EN", equal_to("english text hello_message"), "RU",
                            equal_to("Guest")))
            assert_that(r.json()["promo_on_startup_enabled"], is_(False))
Exemple #9
0
from fastapi import HTTPException
from fastapi.responses import StreamingResponse
from sh import docker_compose
import os
import yaml
import pathlib
import shutil
import docker
import io
import zipfile

from api.settings import Settings
from api.utils.compose import find_yml_files

settings = Settings()
"""
Runs an action on the specified compose project.
"""


def compose_action(name, action):
    files = find_yml_files(settings.COMPOSE_DIR)
    compose = get_compose(name)
    env = os.environ.copy()
    if action == "up":
        try:
            _action = docker_compose(
                action,
                "-d",
                _cwd=os.path.dirname(compose["path"]),
                _env=check_dockerhost(env),
def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)
    Settings(config=config)
    start_api(config)
Exemple #11
0
def make_app():
    app = web.Application()
    app['settings'] = Settings()
    setup_routes(app)
    mongo.setup(app)
    return app
Exemple #12
0
logging.basicConfig()
logging.getLogger('sqlalchemy').setLevel(logging.ERROR)


def background_task(settings: Settings) -> None:
    logging.info("background task is running")
    asyncio.ensure_future(periodic.every_nsec(settings))


def create_app(settings: Settings, debug=False) -> Starlette:
    """Application factory
    setup: routes, database(engine, create tables), periodic background task"""
    database_url = build_pg_url(settings)
    app = Starlette(
        debug=debug,
        routes=routes,
        middleware=middleware,
        on_startup=[init(database_url), lambda: background_task(settings)],
        on_shutdown=[terminate])
    logging.info("Twitter Starlette app is running")
    return app


dev_app = create_app(SettingsDev(), debug=True)
prod_app = create_app(Settings())

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(dev_app, host="0.0.0.0", port=8000)