def mock_config(monkeypatch): """Patch get_config and return the mock it returns.""" mock = Mock() monkeypatch.setattr(settings, Config.__name__, Mock(return_value=mock)) monkeypatch.setattr(settings, _load_config.__name__, Mock(return_value=mock)) cfg = get_config() return cfg
def set_workspace(choice): config = get_config() settings = get_internal_settings() batch_file = get_workspace_batch_file_location() relative_path = config.WORKSPACES_BASE / choice scripts_dir = get_project_root() workspace_env = f"SET {settings.dfl_workspace_key}={relative_path}" scripts_env = f"SET {settings.scripts_env_key}={str(scripts_dir)}" with open(batch_file, 'w') as file: file.write(workspace_env) file.write(os.linesep) file.write(scripts_env) internal_settings = get_internal_settings() internal_settings.current_workspace = choice logger.info(f"Current workspace changed to: {choice}")
""" Definition of listing and filtering/formatting functions """ # pylint: disable=too-few-public-methods from typing import NamedTuple, List from decimal import Decimal from utils.logger import logger from utils.functions import format_time from config.settings import get_config DATETIME_FORMAT = get_config('datetime_format') class Listing(NamedTuple): """ Basic Listing class. Setting defaults to fields we don't operate on, just in case they don't get passed by upstream API. """ sellprice: str starrating: str outbounddep: str inbounddep: str flightnetprice: str = None hotelnetprice: str = None brochurecode: str = None ourhtlid: str = None boardbasis: str = None roomtype: str = None resortname: str = None hotelname: str = None duration: str = None inboundfltnum: str = None
def get_workspace_batch_file_location() -> Path: config = get_config() internal = config.INTERNAL_PATH return internal / SET_SPACE_FILENAME
def get_dfl_setenv_batch_file() -> Path: config = get_config() internal = config.INTERNAL_PATH return internal / SET_ENV_FILENAME
def get_workspace_choices() -> List[Path]: config = get_config() workspaces = config.WORKSPACES_BASE.iterdir() return [space for space in workspaces if space.is_dir()]
# pylint: disable=invalid-name,unused-argument,too-few-public-methods,no-self-use,bad-continuation import decimal from decimal import Decimal import simplejson import falcon from falcon.status_codes import HTTP_200, HTTP_400 from falcon.http_error import HTTPError from falcondocs import FalconDocumentationResource, FalconDocumentationRouter from utils.functions import json_handler, format_time from utils.logger import logger from config.settings import get_config from api.xml_parser import XmlParser from api.listings import prepare_search_results, search_listings TIME_FORMAT = get_config('time_format') def check_types(req, resp, params): """ Checks for well-formatted dates. :param req: request object :param resp: response object :param params: dict of query params :return: HTTP Error **400** or pass through upon successful validation """ types = (('earliest_departure_time', format_time), ('earliest_return_time', format_time), ('max_price', Decimal), ('min_price', Decimal), ('star_rating', int)) try:
from models import company, employee, goods from config.settings import BASE_DIR, get_config, config_path DSN = 'postgresql://{user}:{password}@{host}:{port}/{database}' ADMIN_DB_URL = DSN.format(user='******', password='******', database='postgres', host='postgres', port=5432) admin_engine = create_engine(ADMIN_DB_URL, isolation_level='AUTOCOMMIT') USER_CONFIG_PATH = BASE_DIR / 'config' / 'api.yaml' USER_CONFIG = get_config(config_path) USER_DB_URL = DSN.format(**USER_CONFIG['postgres']) user_engine = create_engine(USER_DB_URL) # # TEST_CONFIG_PATH = BASE_DIR / 'config' / 'polls_test.yaml' # TEST_CONFIG = get_config(['-c', TEST_CONFIG_PATH.as_posix()]) # TEST_DB_URL = DSN.format(**TEST_CONFIG['postgres']) # test_engine = create_engine(TEST_DB_URL) def check_db(engine=user_engine): conn = engine.connect() if conn: return True else: return False
def get_base_workspaces_path() -> Path: config = get_config() return config.WORKSPACES_BASE
""" XMLParser """ # pylint: disable=too-few-public-methods,invalid-name import re import urllib from typing import List, NamedTuple from datetime import date from xml.parsers.expat import ExpatError import requests import xmltodict from config.settings import get_config from utils.logger import logger from .listings import Listing API_URL = get_config('api_endpoint') DATE_FORMAT = get_config('date_format') class Params(NamedTuple): """Class for representing query parameters for upstream API """ countryid: int page: str platform: str depart: str regionid: int areaid: int resortid: int depdate: str flex: int adults: int children: int