GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mesh-client/tests/helpers.py at develop · NHSDigital/mesh-client

Expand file tree

/

helpers.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
69 lines (56 loc) · 2.28 KB
/

helpers.py

Copy path

File metadata and controls

69 lines (56 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import contextlib
import json
import os
from collections.abc import Mapping
from werkzeug import Response
from mesh_client import Endpoint
_PACKAGE_DIR = os.path.dirname(__file__)
MOCK_CA_CERT = os.path.join(_PACKAGE_DIR, "ca.cert.pem")
MOCK_CERT = os.path.join(_PACKAGE_DIR, "client.cert.pem")
MOCK_KEY = os.path.join(_PACKAGE_DIR, "client.key.pem")
MOCK_SSL_OPTS = {"verify": MOCK_CA_CERT, "cert": (MOCK_CERT, MOCK_KEY)}
"""
Usable default values for verify and cert, providing certificates and keys
which should work with mock_server. Note that these certs will not work with
any NHS England test environments - such certs must be obtained from
NHS England.
"""
default_ssl_opts = MOCK_SSL_OPTS
LOCAL_MOCK_ENDPOINT = Endpoint("https://localhost:8000", MOCK_CA_CERT, (MOCK_CERT, MOCK_KEY), False, False)
LOCAL_FAKE_ENDPOINT = Endpoint("https://localhost:8829", MOCK_CA_CERT, (MOCK_CERT, MOCK_KEY), False, False)
SANDBOX_ENDPOINT = Endpoint("https://localhost:8701", MOCK_CA_CERT, (MOCK_CERT, MOCK_KEY), False, False)
@contextlib.contextmanager
def temp_env_vars(**kwargs):
"""
Temporarily set the process environment variables.
>>> with temp_env_vars(PLUGINS_DIR=u'test/plugins'):
... "PLUGINS_DIR" in os.environ
True
>>> "PLUGINS_DIR" in os.environ
"""
old_environ = dict(os.environ)
kwargs = {k: str(v) for k, v in kwargs.items()}
os.environ.update(**kwargs)
try:
yield
finally:
os.environ.clear()
os.environ.update(old_environ)
def json_response(
response: dict,
status: int = 200,
content_type: str = "application/vnd.mesh.v2+json",
headers: Mapping[str, str] | None = None,
) -> Response:
return Response(response=json.dumps(response), status=status, content_type=content_type, headers=headers)
def bytes_response(
response: bytes,
status: int = 200,
content_type: str = "application/octet-stream",
headers: Mapping[str, str] | None = None,
) -> Response:
return Response(response=response, status=status, content_type=content_type, headers=headers)
def plain_response(
response: str, status: int = 200, content_type: str = "text/plain", headers: Mapping[str, str] | None = None
) -> Response:
return Response(response=response, status=status, content_type=content_type, headers=headers)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.