File tree Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 1212import json
1313from collections .abc import Callable
1414
15+ import jsf
1516from common .base_user import OsparcWebUserBase
1617from locust import events , task
1718from locust .argument_parser import LocustArgumentParser
@@ -36,7 +37,19 @@ def _(parser: LocustArgumentParser) -> None:
3637 "--body" ,
3738 type = str ,
3839 default = "" ,
39- help = "The optional HTTP body as json string" ,
40+ help = "Optional HTTP body as json string" ,
41+ )
42+ parser .add_argument (
43+ "--body-json-schema" ,
44+ type = str ,
45+ default = "" ,
46+ help = "Optional JSON schema for the request body. If specified, the request data will be randomly generated from this schema." ,
47+ )
48+ parser .add_argument (
49+ "--headers" ,
50+ type = str ,
51+ default = "" ,
52+ help = "Optional HTTP headers as json string" ,
4053 )
4154
4255
@@ -52,4 +65,11 @@ def get_endpoint(self) -> None:
5265 kwargs = {}
5366 if len (self .environment .parsed_options .body ) > 0 :
5467 kwargs ["json" ] = json .loads (self .environment .parsed_options .body )
68+ if len (self .environment .parsed_options .body_json_schema ) > 0 :
69+ faker = jsf .JSF (
70+ json .loads (self .environment .parsed_options .body_json_schema )
71+ )
72+ kwargs ["json" ] = faker .generate ()
73+ if len (self .environment .parsed_options .headers ) > 0 :
74+ kwargs ["headers" ] = json .loads (self .environment .parsed_options .headers )
5575 method (self .environment .parsed_options .endpoint , ** kwargs )
Original file line number Diff line number Diff line change 1+ jsf
12locust
23locust-plugins[dashboards]
34pydantic
Original file line number Diff line number Diff line change 11annotated-types==0.7.0
22 # via pydantic
3+ attrs==25.3.0
4+ # via
5+ # jsonschema
6+ # referencing
37bidict==0.23.1
48 # via python-socketio
59blinker==1.9.0
@@ -18,6 +22,8 @@ configargparse==1.7.1
1822 # via
1923 # locust
2024 # locust-cloud
25+ faker==37.6.0
26+ # via jsf
2127flask==3.1.1
2228 # via
2329 # flask-cors
@@ -44,6 +50,12 @@ itsdangerous==2.2.0
4450 # via flask
4551jinja2==3.1.6
4652 # via flask
53+ jsf==0.11.2
54+ # via -r requirements/_test.in
55+ jsonschema==4.25.1
56+ # via jsf
57+ jsonschema-specifications==2025.4.1
58+ # via jsonschema
4759locust==2.37.5
4860 # via
4961 # -r requirements/_test.in
@@ -70,6 +82,7 @@ psycopg2-binary==2.9.10
7082pydantic==2.11.7
7183 # via
7284 # -r requirements/_test.in
85+ # jsf
7386 # pydantic-settings
7487pydantic-core==2.33.2
7588 # via pydantic
@@ -83,29 +96,46 @@ python-socketio==5.13.0
8396 # via locust-cloud
8497pyzmq==26.4.0
8598 # via locust
99+ referencing==0.36.2
100+ # via
101+ # jsonschema
102+ # jsonschema-specifications
86103requests==2.32.4
87104 # via
88105 # locust
89106 # python-socketio
107+ # smart-open
108+ rpds-py==0.27.1
109+ # via
110+ # jsonschema
111+ # referencing
112+ rstr==3.2.2
113+ # via jsf
90114setuptools==80.9.0
91115 # via
92116 # locust
93117 # zope-event
94118 # zope-interface
95119simple-websocket==1.1.0
96120 # via python-engineio
121+ smart-open==7.3.0.post1
122+ # via jsf
97123tenacity==9.1.2
98124 # via -r requirements/_test.in
99125typing-extensions==4.14.1
100126 # via
127+ # jsf
101128 # locust-plugins
102129 # pydantic
103130 # pydantic-core
131+ # referencing
104132 # typing-inspection
105133typing-inspection==0.4.1
106134 # via
107135 # pydantic
108136 # pydantic-settings
137+ tzdata==2025.2
138+ # via faker
109139urllib3==2.5.0
110140 # via
111141 # geventhttpclient
@@ -118,6 +148,8 @@ werkzeug==3.1.3
118148 # flask-cors
119149 # flask-login
120150 # locust
151+ wrapt==1.17.3
152+ # via smart-open
121153wsproto==1.2.0
122154 # via simple-websocket
123155zope-event==5.0
You can’t perform that action at this time.
0 commit comments