1- import random
2-
31from locust import HttpUser , events , task
42
5-
6- class QueryParams :
7- LDAP_UNIQUE_IDENTIFIER = "ldap_unique_identifier"
8- DEVICE_ID = "device_id"
9- DEVICE_KEY = "device_key"
10- PARTY_KEY = "party_key"
11- INTERACTION_ID = "interaction_id"
12- ODS_CODE = "ods_code"
13-
14-
15- unique_identifiers = ["1234567" , "7654321" ]
16-
17- device_keys = ["D81631:200000035358" ]
18-
19- device_ids = ["3b9ced88-e2c2-4496-8ade-7fc3d5a8aba5" ]
20-
21- interaction_ids = [
22- "https://fhir.nhs.uk/Id/nhsServiceInteractionId|urn:nhs:names:services:lrs:REPC_IN010000UK01"
23- ]
24-
25- party_keys = ["https://fhir.nhs.uk/Id/nhsMhsPartyKey|5NR-801831" ]
26-
27- ods_codes = ["https://fhir.nhs.uk/Id/ods-organization-code|5NR" ]
28-
29-
30- sds_accredited_system_query_combinations = [
31- {QueryParams .INTERACTION_ID , QueryParams .ODS_CODE , QueryParams .PARTY_KEY },
32- {QueryParams .INTERACTION_ID , QueryParams .ODS_CODE },
33- ]
34-
35- sds_mhs_query_combinations = [
36- {QueryParams .INTERACTION_ID , QueryParams .ODS_CODE , QueryParams .PARTY_KEY },
37- {QueryParams .INTERACTION_ID , QueryParams .PARTY_KEY },
38- {QueryParams .INTERACTION_ID , QueryParams .ODS_CODE },
39- {QueryParams .PARTY_KEY , QueryParams .ODS_CODE },
3+ queries = [
4+ {
5+ "params" : {
6+ "organization" : ["https://fhir.nhs.uk/Id/ods-organization-code|E82652" ],
7+ "identifier" : [
8+ "https://fhir.nhs.uk/Id/nhsServiceInteractionId|urn:nhs:names:services:gpconnect:fhir:operation:gpc.getcarerecord" ,
9+ "https://fhir.nhs.uk/Id/nhsMhsPartyKey|E82652-826971" ,
10+ ],
11+ },
12+ "path" : "/Device" ,
13+ }
4014]
4115
4216
@@ -57,6 +31,14 @@ def _(parser):
5731 required = True ,
5832 help = "apikey for hitting desired host" ,
5933 )
34+ parser .add_argument (
35+ "--usecpm" ,
36+ choices = ["TRUE" , "FALSE" ],
37+ default = "FALSE" ,
38+ env_var = "USE_CPM" ,
39+ required = False ,
40+ help = "use_cpm for hitting cpm" ,
41+ )
6042
6143
6244def _get_headers (version : str , apikey : str ):
@@ -67,72 +49,18 @@ def _get_headers(version: str, apikey: str):
6749
6850class CPMUser (HttpUser ):
6951 @task
70- def read_device_by_id (self ):
71- device_id = random .choice (device_ids )
72- url_path = f"/Device/{ device_id } "
73- APIKEY = self .environment .parsed_options .apikey
52+ def search (self ):
53+ apikey = self .environment .parsed_options .apikey
7454 API_VERSION = self .environment .parsed_options .api_version
75-
76- self .client .get (
77- url = url_path , headers = _get_headers (version = API_VERSION , apikey = APIKEY )
78- )
79-
80- # @task
81- # def search_cpm_for_unique_identifier(self):
82- # unique_identifier = random.choice(unique_identifiers)
83- # url_path = f"/Device?{QueryParams.LDAP_UNIQUE_IDENTIFIER}={unique_identifier}"
84- # apikey = self.environment.parsed_options.apikey
85- # API_VERSION = self.environment.parsed_options.api_version
86-
87- # self.client.get(
88- # url=url_path,
89- # headers=_get_headers(version=API_VERSION, apikey=apikey)
90- # )
91-
92- # @task
93- # def search_cpm_for_accredited_system(self):
94- # selected_combination = random.choice(sds_accredited_system_query_combinations)
95- # selected_values = {}
96- # if QueryParams.INTERACTION_ID in selected_combination:
97- # selected_values['interaction'] = random.choice(interaction_ids)
98-
99- # if QueryParams.ODS_CODE in selected_combination:
100- # selected_values['code'] = random.choice(ods_codes)
101-
102- # if QueryParams.PARTY_KEY in selected_combination:
103- # selected_values['key'] = random.choice(party_keys)
104-
105- # query_params = urlencode(selected_values)
106- # url_path = f"/Device?{query_params}"
107-
108- # apikey = self.environment.parsed_options.apikey
109- # API_VERSION = self.environment.parsed_options.api_version
110-
111- # self.client.get(
112- # url=url_path,
113- # headers=_get_headers(version=API_VERSION, apikey=apikey)
114- # )
115-
116- # @task
117- # def search_cpm_for_mhs(self):
118- # selected_combination = random.choice(sds_mhs_query_combinations)
119- # selected_values = {}
120- # if QueryParams.INTERACTION_ID in selected_combination:
121- # selected_values['interaction'] = random.choice(interaction_ids)
122-
123- # if QueryParams.ODS_CODE in selected_combination:
124- # selected_values['code'] = random.choice(ods_codes)
125-
126- # if QueryParams.PARTY_KEY in selected_combination:
127- # selected_values['key'] = random.choice(party_keys)
128-
129- # query_params = urlencode(selected_values)
130- # url_path = f"/Device?{query_params}"
131-
132- # apikey = self.environment.parsed_options.apikey
133- # API_VERSION = self.environment.parsed_options.api_version
134-
135- # self.client.get(
136- # url=url_path,
137- # headers=_get_headers(version=API_VERSION, apikey=apikey)
138- # )
55+ USE_CPM = self .environment .parsed_options .usecpm
56+ for query in queries :
57+ params = query ["params" ].copy ()
58+ if USE_CPM == "TRUE" :
59+ params ["use_cpm" ] = "iwanttogetdatafromcpm"
60+
61+ url_path = f"{ query ['path' ]} "
62+ self .client .get (
63+ url = url_path ,
64+ params = params ,
65+ headers = _get_headers (version = API_VERSION , apikey = apikey ),
66+ )
0 commit comments