Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Test server for pws #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions cms/web/fixtures/user
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"num": 4,
"users": [
{
"username": "gabrfarina",
"first_name": "Gabriele",
"last_name": "Farina",
"tasks_solved": 79,
"mail_hash": "c19a99493ac8185baa01174378f37b54",
"post_count": 12,
"access_level": 5,
"join_date": 1387637721.98562,
"score": 42553,
"institute": {
"province": "Verona",
"city": "Verona",
"region": "Veneto",
"id": 5617,
"name": "Galilei"
}
},
{
"username": "wil93",
"first_name": "William",
"last_name": "Di Luigi",
"tasks_solved": 68,
"mail_hash": "3ac73c99a3aa3ec0c423849fae6c0b26",
"post_count": 64,
"access_level": 5,
"join_date": 1396542418.596289,
"score": 39523,
"institute": {
"province": "Pordenone",
"city": "Pordenone",
"region": "Friuli-Venezia Giulia",
"id": 1260,
"name": "Ls M. Grigoletti"
}
},
{
"username": "veluca",
"first_name": "Luca",
"last_name": "Versari",
"tasks_solved": 79,
"mail_hash": "0d458d930c7587a320754ae69f170b51",
"post_count": 56,
"access_level": 5,
"join_date": 1387044829.31029,
"score": 38924,
"institute": {
"province": "Bergamo",
"city": "Bergamo",
"region": "Lombardia",
"id": 6964,
"name": "Filippo Lussana"
}
},
{
"username": "ellat",
"first_name": "Ella",
"last_name": "Turner",
"tasks_solved": 75,
"mail_hash": "2dd1894ea9d19bf5479992da95713a3a",
"post_count": 23,
"access_level": 5,
"join_date": 1387044828.31029,
"score": 38753,
"institute": {
"province": "Bergamo",
"city": "Bergamo",
"region": "Lombardia",
"id": 6964,
"name": "Filippo Lussana"
}
},
{
"username": "dany89",
"first_name": "Daniel",
"last_name": "Williamson",
"tasks_solved": 68,
"mail_hash": "2dd1894ea9d19bf5479992da95713a3a",
"post_count": 23,
"access_level": 5,
"join_date": 1387044828.31029,
"score": 36012,
"institute": {
"province": "Bergamo",
"city": "Bergamo",
"region": "Lombardia",
"id": 6964,
"name": "Filippo Lussana"
}
},
{
"username": "martuccia",
"first_name": "Marta",
"last_name": "Rossi",
"tasks_solved": 63,
"mail_hash": "2dd1894ea9d19bf5479992da95713a3a",
"post_count": 23,
"access_level": 5,
"join_date": 1387044828.31029,
"score": 35212,
"institute": {
"province": "Bergamo",
"city": "Bergamo",
"region": "Lombardia",
"id": 6964,
"name": "Filippo Lussana"
}
}],
"success": 1
}
61 changes: 61 additions & 0 deletions cms/web/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python

"""
Save this file as server.py
>>> python server.py 0.0.0.0 8001
serving on 0.0.0.0:8001

or simply

>>> python server.py
Serving on localhost:8000

You can use this to test GET and POST methods.

"""

import SimpleHTTPServer
import SocketServer
import logging
import cgi
import sys

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_FIXTURE(self, message):
self.send_response(200)
self.end_headers()
self.wfile.write(message)

def do_GET(self):
logging.info("GET %s" % self.path)
logging.debug(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

def do_POST(self):
logging.info("POST %s" % self.path)
logging.debug(self.headers)

if self.path.endswith('/user'):
logging.warning("Returning /user fixture")
message = open("fixtures/user").read()
return self.do_FIXTURE(message)

SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

if __name__ == '__main__':
if len(sys.argv) > 2:
PORT = int(sys.argv[2])
I = sys.argv[1]
elif len(sys.argv) > 1:
PORT = int(sys.argv[1])
I = ""
else:
PORT = 8000
I = ""

Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)

print "OII-WEB Interface http server (for testing purposes only)"
print "Serving at: http://%(interface)s:%(port)s" % dict(interface = I or "localhost", port = PORT)
httpd.serve_forever()