]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/commitdiff
tests: allow fake Kong server to receive PUT requests 23/head
authorPaul Bonaud <paul.bonaud@fretlink.com>
Mon, 12 Oct 2020 15:31:15 +0000 (17:31 +0200)
committerPaul Bonaud <paul.bonaud@fretlink.com>
Wed, 14 Oct 2020 08:05:00 +0000 (10:05 +0200)
tests/kong.py

index a1f9cecee4e17043d4e827a25478c5f3f39c426b..c39542f1bc6bc0a07a0e3798d36214518616dfb4 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 from http.server import HTTPServer, CGIHTTPRequestHandler
+import random
 
 class SimpleHTTPRequestHandler(CGIHTTPRequestHandler):
     def do_GET(self):
@@ -17,6 +18,14 @@ class SimpleHTTPRequestHandler(CGIHTTPRequestHandler):
         self.end_headers()
         self.wfile.write(b'Hello, world!')
 
+    def do_PUT(self):
+        if bool(random.getrandbits(1)):
+            self.send_response(200)
+        else:
+            self.send_response(201)
+        self.end_headers()
+        self.wfile.write(b'Hello, world!')
+
 
 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
 httpd.serve_forever()