Skip to content

Commit

Permalink
test: add support for PUT requests in HttpServerMock
Browse files Browse the repository at this point in the history
  • Loading branch information
jkloetzke committed Jan 1, 2024
1 parent 72d2982 commit 081db92
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/unit/mocks/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,38 @@ def do_GET(self):
self.wfile.write(f.read())
f.close()

def do_PUT(self):
self.stats.putRequests += 1
if args.get('noResponse'):
self.close_connection = True
return
if args.get('retries') > 0:
self.send_error(500, "internal error")
self.end_headers()
args['retries'] = args.get('retries') - 1
return

path = repoPath + self.path
if os.path.exists(path) and ("If-None-Match" in self.headers):
self.send_response(412)
self.end_headers()
return

os.makedirs(os.path.dirname(path), exist_ok=True)
length = int(self.headers['Content-Length'])
with open(path, "wb") as f:
f.write(self.rfile.read(length))
self.send_response(200)
self.end_headers()

return Handler

class HttpServerStats:
def __init__(self, port):
self.port = port
self.headRequests = 0
self.getRequests = 0
self.putRequests = 0

class HttpServerMock():
def __init__(self, repoPath, noResponse=False, retries=0):
Expand Down

0 comments on commit 081db92

Please sign in to comment.