@@ -89,69 +89,66 @@ class MockRequestHandler(BaseHTTPRequestHandler):
8989 def do_GET (self ):
9090 u = urlparse (self .path )
9191 params = parse_qs (u .query )
92- match u .path :
93- case "/projects/1/jobs" :
94- self .send_response (HTTPStatus .OK )
95- self .send_header ("Content-Type" , "application/json" )
96- self .end_headers ()
97- payload = job_list
98- if params .get ("sort" ) == ["id:1" ]:
99- payload = sorted (job_list , key = lambda p : p ["id" ])
100- elif params .get ("q" ) == ["name:foo" ]:
101- payload = [p for p in job_list if p ["name" ] == "foo" ]
102- self .wfile .write (json .dumps (payload ).encode ())
103- case "/projects/1/jobs/1" :
104- self .send_response (HTTPStatus .OK )
105- self .send_header ("Content-Type" , "application/json" )
106- self .end_headers ()
107- payload = job_list [- 1 ]
108- self .wfile .write (json .dumps (payload ).encode ())
109- case "/projects/1/jobs/1/status" :
110- global poll_count
111- poll_count += 1
112- if poll_count < 3 :
113- self .send_response (HTTPStatus .ACCEPTED )
114- payload = deepcopy (new_job )
115- payload ["state" ] = "started"
116- else :
117- self .send_response (HTTPStatus .CREATED )
118- payload = deepcopy (new_job )
119- payload .update ({
120- "state" : "success" ,
121- "assets" : [asset_json ],
122- })
123- self .send_header ("Content-Type" , "application/json" )
124- self .end_headers ()
125- self .wfile .write (json .dumps (payload ).encode ())
126- case _:
127- self .send_error (HTTPStatus .NOT_FOUND )
128-
129- def do_POST (self ):
130- match self .path :
131- case "/projects/1/jobs" :
92+ if u .path == "/projects/1/jobs" :
93+ self .send_response (HTTPStatus .OK )
94+ self .send_header ("Content-Type" , "application/json" )
95+ self .end_headers ()
96+ payload = job_list
97+ if params .get ("sort" ) == ["id:1" ]:
98+ payload = sorted (job_list , key = lambda p : p ["id" ])
99+ elif params .get ("q" ) == ["name:foo" ]:
100+ payload = [p for p in job_list if p ["name" ] == "foo" ]
101+ self .wfile .write (json .dumps (payload ).encode ())
102+ elif u .path == "/projects/1/jobs/1" :
103+ self .send_response (HTTPStatus .OK )
104+ self .send_header ("Content-Type" , "application/json" )
105+ self .end_headers ()
106+ payload = job_list [- 1 ]
107+ self .wfile .write (json .dumps (payload ).encode ())
108+ elif u .path == "/projects/1/jobs/1/status" :
109+ global poll_count
110+ poll_count += 1
111+ if poll_count < 3 :
132112 self .send_response (HTTPStatus .ACCEPTED )
133- self .send_header ("Content-Type" , "application/json" )
134- self .end_headers ()
113+ payload = deepcopy (new_job )
114+ payload ["state" ] = "started"
115+ else :
116+ self .send_response (HTTPStatus .CREATED )
135117 payload = deepcopy (new_job )
136118 payload .update ({
137- "state" : "pending " ,
138- "link " : "http://localhost:8000/projects/1/jobs/1/status" ,
119+ "state" : "success " ,
120+ "assets " : [ asset_json ] ,
139121 })
140- self .wfile .write (json .dumps (payload ).encode ())
141- case _:
142- self .send_error (HTTPStatus .NOT_FOUND )
122+ self .send_header ("Content-Type" , "application/json" )
123+ self .end_headers ()
124+ self .wfile .write (json .dumps (payload ).encode ())
125+ else :
126+ self .send_error (HTTPStatus .NOT_FOUND )
127+
128+ def do_POST (self ):
129+ if self .path == "/projects/1/jobs" :
130+ self .send_response (HTTPStatus .ACCEPTED )
131+ self .send_header ("Content-Type" , "application/json" )
132+ self .end_headers ()
133+ payload = deepcopy (new_job )
134+ payload .update ({
135+ "state" : "pending" ,
136+ "link" : "http://localhost:8000/projects/1/jobs/1/status" ,
137+ })
138+ self .wfile .write (json .dumps (payload ).encode ())
139+ else :
140+ self .send_error (HTTPStatus .NOT_FOUND )
143141
144142 def do_PATCH (self ):
145- match self .path :
146- case "/projects/1/jobs/1" :
147- self .send_response (HTTPStatus .OK )
148- self .send_header ("Content-Type" , "application/json" )
149- self .end_headers ()
150- payload = deepcopy (job_list [- 1 ])
151- payload ["name" ] = "baz"
152- self .wfile .write (json .dumps (payload ).encode ())
153- case _:
154- self .send_error (HTTPStatus .NOT_FOUND )
143+ if self .path == "/projects/1/jobs/1" :
144+ self .send_response (HTTPStatus .OK )
145+ self .send_header ("Content-Type" , "application/json" )
146+ self .end_headers ()
147+ payload = deepcopy (job_list [- 1 ])
148+ payload ["name" ] = "baz"
149+ self .wfile .write (json .dumps (payload ).encode ())
150+ else :
151+ self .send_error (HTTPStatus .NOT_FOUND )
155152
156153
157154@pytest .fixture (scope = "module" )
0 commit comments