aboutsummaryrefslogtreecommitdiffstats
path: root/mockshoutbox.py
diff options
context:
space:
mode:
authorjantuomi <jans.tuomi@gmail.com>2016-07-19 14:20:36 +0300
committerjantuomi <jans.tuomi@gmail.com>2016-07-19 14:20:36 +0300
commit50779b5ecc55f906bcfd46e54dad70b2c74d3a98 (patch)
treec3627888448c9e49f32df8670596758f347427b4 /mockshoutbox.py
parenteacb313e19805fd8d4bbba1b3515aa9adcd897cf (diff)
Code cleanup
Diffstat (limited to 'mockshoutbox.py')
-rw-r--r--mockshoutbox.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/mockshoutbox.py b/mockshoutbox.py
index da8e48a..4a64406 100644
--- a/mockshoutbox.py
+++ b/mockshoutbox.py
@@ -8,40 +8,49 @@ import json
import time
-'''
-Mock HTTP server to test
-shoutbox api requests.
-'''
class MyHandler(SimpleHTTPRequestHandler):
+ """
+ Mock shoutbox HTTP server to test
+ shoutbox API requests.
+ """
def do_HEAD(self):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
def do_GET(self):
- """Respond to a GET request."""
+ """
+ Respond to a GET with a JSON array containing one object
+ that contains the following:
+
+ test user: test message
+ """
+
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
+ timestamp = str(round(time.time()))
body = json.dumps([{
"user": "test user",
"text": "test message",
- "timestamp": str(time.time()),
- "id": time.time(),
+ "timestamp": timestamp,
+ "id": timestamp,
"ip": "1.2.3.4"
}])
self.wfile.write(body.encode())
def do_POST(self):
+ """
+ Respond to a POST by printing the message contents to console
+ """
content_len = int(self.headers.get('Content-Length'))
post_data = self.rfile.read(content_len)
try:
message = json.loads(post_data.decode('utf-8'))
print("{}: {}".format(message["user"], message["text"]))
- # Begin the response
self.send_response(200)
except: