mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 11:52:27 +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:
commit
be6e54dfef
@ -127,8 +127,19 @@ if __name__ == '__main__': # noqa: C901
|
|||||||
nargs='*'
|
nargs='*'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--capi-pretend-down',
|
||||||
|
help='Force to raise ServerError on any CAPI query',
|
||||||
|
action='store_true'
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
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
|
level_to_set: Optional[int] = None
|
||||||
if args.trace or args.trace_on:
|
if args.trace or args.trace_on:
|
||||||
level_to_set = logging.TRACE # type: ignore # it exists
|
level_to_set = logging.TRACE # type: ignore # it exists
|
||||||
|
@ -24,6 +24,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, OrderedDic
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import config as conf_module
|
||||||
from config import appname, appversion, config
|
from config import appname, appversion, config
|
||||||
from edmc_data import companion_category_map as category_map
|
from edmc_data import companion_category_map as category_map
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
@ -563,8 +564,11 @@ class Session(object):
|
|||||||
logger.error('cannot make a query when unauthorized')
|
logger.error('cannot make a query when unauthorized')
|
||||||
raise CredentialsError('cannot make a query when unauthorized')
|
raise CredentialsError('cannot make a query when unauthorized')
|
||||||
|
|
||||||
try:
|
|
||||||
logger.trace_if('capi.query', 'Trying...')
|
logger.trace_if('capi.query', 'Trying...')
|
||||||
|
if conf_module.capi_pretend_down:
|
||||||
|
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
|
||||||
|
|
||||||
|
try:
|
||||||
r = self.session.get(self.server + endpoint, timeout=timeout) # type: ignore
|
r = self.session.get(self.server + endpoint, timeout=timeout) # type: ignore
|
||||||
|
|
||||||
except requests.ConnectionError as e:
|
except requests.ConnectionError as e:
|
||||||
|
@ -45,6 +45,7 @@ debug_senders: List[str] = []
|
|||||||
# *all* if only interested in some things.
|
# *all* if only interested in some things.
|
||||||
trace_on: List[str] = []
|
trace_on: List[str] = []
|
||||||
|
|
||||||
|
capi_pretend_down: bool = False
|
||||||
# This must be done here in order to avoid an import cycle with EDMCLogging.
|
# This must be done here in order to avoid an import cycle with EDMCLogging.
|
||||||
# Other code should use EDMCLogging.get_main_logger
|
# Other code should use EDMCLogging.get_main_logger
|
||||||
if os.getenv("EDMC_NO_UI"):
|
if os.getenv("EDMC_NO_UI"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user