|
41 | 41 | WORKER_PATH = pathlib.Path(__file__).parent.parent.parent |
42 | 42 | WORKER_CONFIG = WORKER_PATH / '.testconfig' |
43 | 43 |
|
| 44 | +SECRETS_TEMPLATE = """\ |
| 45 | +{ |
| 46 | + "masterKey": { |
| 47 | + "name": "master", |
| 48 | + "value": "testMasterKey", |
| 49 | + "encrypted": false |
| 50 | + }, |
| 51 | + "functionKeys": [ |
| 52 | + { |
| 53 | + "name": "default", |
| 54 | + "value": "testFunctionKey", |
| 55 | + "encrypted": false |
| 56 | + } |
| 57 | + ], |
| 58 | + "systemKeys": [ |
| 59 | + { |
| 60 | + "name": "eventgridextensionconfig_extension", |
| 61 | + "value": "testSystemKey", |
| 62 | + "encrypted": false |
| 63 | + } |
| 64 | + ], |
| 65 | + "hostName": null, |
| 66 | + "instanceId": "0000000000000000000000001C69C103", |
| 67 | + "source": "runtime" |
| 68 | +} |
| 69 | +""" |
| 70 | + |
44 | 71 |
|
45 | 72 | class AsyncTestCaseMeta(type(unittest.TestCase)): |
46 | 73 |
|
@@ -413,7 +440,11 @@ def __init__(self, proc, addr): |
413 | 440 |
|
414 | 441 | def request(self, meth, funcname, *args, **kwargs): |
415 | 442 | request_method = getattr(requests, meth.lower()) |
416 | | - return request_method(self._addr + '/api/' + funcname, *args, **kwargs) |
| 443 | + params = dict(kwargs.pop('params', {})) |
| 444 | + if 'code' not in params: |
| 445 | + params['code'] = 'testFunctionKey' |
| 446 | + return request_method(self._addr + '/api/' + funcname, |
| 447 | + *args, params=params, **kwargs) |
417 | 448 |
|
418 | 449 | def close(self): |
419 | 450 | if self._proc.stdout: |
@@ -449,6 +480,12 @@ def popen_webhost(*, stdout, stderr, script_root=FUNCS_PATH, port=None): |
449 | 480 | if not dll: |
450 | 481 | dll = DEFAULT_WEBHOST_DLL_PATH |
451 | 482 |
|
| 483 | + secrets = SECRETS_TEMPLATE |
| 484 | + |
| 485 | + os.makedirs(dll.parent / 'Secrets', exist_ok=True) |
| 486 | + with open(dll.parent / 'Secrets' / 'host.json', 'w') as f: |
| 487 | + f.write(secrets) |
| 488 | + |
452 | 489 | if not dll or not pathlib.Path(dll).exists(): |
453 | 490 | raise RuntimeError('\n'.join([ |
454 | 491 | f'Unable to locate Azure Functions Host binary.', |
@@ -533,7 +570,8 @@ def start_webhost(*, script_dir=None, stdout=None): |
533 | 570 |
|
534 | 571 | for n in range(10): |
535 | 572 | try: |
536 | | - r = requests.get(f'{addr}/api/ping') |
| 573 | + r = requests.get(f'{addr}/api/ping', |
| 574 | + params={'code': 'testFunctionKey'}) |
537 | 575 | if 200 <= r.status_code < 300: |
538 | 576 | # Give the host a bit more time to settle |
539 | 577 | time.sleep(1) |
|
0 commit comments