-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestRequest.py
More file actions
70 lines (57 loc) · 2.01 KB
/
Copy pathtestRequest.py
File metadata and controls
70 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import os
import smtplib
from datetime import datetime
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)
class Application(tornado.web.Application):
fields = [ 'FogBugz Cases:', 'Changes/Features:', 'System impact:', 'Tests written:', 'What needs testing:']
def __init__(self):
handlers = [
(r"/", IndexHandler),
]
settings = dict(
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
debug = True,
)
tornado.web.Application.__init__(self, handlers, **settings)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html', fields = Application.fields, error_message = "")
def post(self):
sender = ''
receivers = ['']
message = """From:
To:
Subject: Request for testing
"""
try:
message += "From: " + self.get_argument('from') +"\n\n"
except:
self.render('index.html', fields = Application.fields, error_message = "All fields are required.")
for field in Application.fields:
try:
arg = self.get_argument(field.replace(' ', '-'))
except:
self.render('index.html', fields = Application.fields, error_message = "All fields are required.")
line = field + "\n" + arg + '\n\n'
message += line
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print("Successfully sent email")
except SMTPException:
print("Error: unable to send email")
self.render('index.html', fields = Application.fields, error_message="")
if __name__ == '__main__':
# Parse the command line options defined with define() statements, this comes from the
# tornado.options package
tornado.options.parse_command_line()
# Boilerplate
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()