1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-16 17:12:21 +03:00

Merge pull request #1246 from norohind/enhancement/1096/CAPI-pretend-down-CL-arg

Add CL arg `--capi-pretend-down` in order to pretend that CAPI is down
This commit is contained in:
Athanasius 2021-08-16 13:34:57 +01:00 committed by GitHub
commit be6e54dfef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -127,8 +127,19 @@ if __name__ == '__main__': # noqa: C901
nargs='*'
)
parser.add_argument(
'--capi-pretend-down',
help='Force to raise ServerError on any CAPI query',
action='store_true'
)
args = parser.parse_args()
if args.capi_pretend_down:
import config as conf_module
logger.info('Pretending CAPI is down')
conf_module.capi_pretend_down = True
level_to_set: Optional[int] = None
if args.trace or args.trace_on:
level_to_set = logging.TRACE # type: ignore # it exists

View File

@ -24,6 +24,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, OrderedDic
import requests
import config as conf_module
from config import appname, appversion, config
from edmc_data import companion_category_map as category_map
from EDMCLogging import get_main_logger
@ -563,8 +564,11 @@ class Session(object):
logger.error('cannot make a query when unauthorized')
raise CredentialsError('cannot make a query when unauthorized')
logger.trace_if('capi.query', 'Trying...')
if conf_module.capi_pretend_down:
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
try:
logger.trace_if('capi.query', 'Trying...')
r = self.session.get(self.server + endpoint, timeout=timeout) # type: ignore
except requests.ConnectionError as e:

View File

@ -45,6 +45,7 @@ debug_senders: List[str] = []
# *all* if only interested in some things.
trace_on: List[str] = []
capi_pretend_down: bool = False
# This must be done here in order to avoid an import cycle with EDMCLogging.
# Other code should use EDMCLogging.get_main_logger
if os.getenv("EDMC_NO_UI"):