-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestingDemo.py
executable file
·85 lines (68 loc) · 2.18 KB
/
TestingDemo.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
""" Test API for Fibonacci and GCD functions
"""
import cherrypy
import fibonacci as fib
import gcdVersions as gcd
# import test_fibonacci
# import test_gcdVersions
class Fib_GCD_API(object):
""" Main Application Class for Fibonacci and GCD testing system
"""
@cherrypy.expose
def index(self):
return \
"""
<html><head></head>
<!-- Add HTML Comment -->
<body>
<h1>Choose a Function API</h1>
<p><a href="FibonacciAPI">Fibonacci API</a></p>
<p><a href="gcdAPI">Greatest Common Divisor API</a></p>
</body>
</html>
"""
@cherrypy.expose
def FibonacciAPI(self, fibx=0):
""" Path should be https://[ADDRESS]:[PORT]/FibonacciAPI?fibx=[INTEGER]
"""
if fibx is None:
return "Error: Specify a value for fibx"
fibx = int(fibx) # cast URL string to int...
if (fibx < 0):
return "Error: Input value must be >= 0"
if (fibx > 1000):
return "Error: Use a value <= 1000"
fib_string = str(fib.fibonacciSequencer(fibx))
return fib_string
@cherrypy.expose
def gcdAPI(self, a_value=1, b_value=1):
""" Path should be https://[ADDRESS]:[PORT]/gcdAPI?a_value=[INTEGER]&b_value=[INTEGER]
"""
if a_value is None or b_value is None:
return "Error: Specify values for a_value and b_value"
a_value = int(a_value)
b_value = int(b_value)
if a_value < 0 and b_value < 0 :
return "Error: values must be greater than zero"
gcd_string = str(gcd.gcd_lame(a_value, b_value))
return gcd_string
if __name__ == "__main__":
import os as os
conf = {
'global': {
'server.socket_host': '0.0.0.0',
'server.socket_port': int(os.environ.get('PORT', 8080))
},
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '/public'
}
}
""" Starts internal httpd and listens at whatever Heroku returns...
"""
cherrypy.quickstart(Fib_GCD_API(), '/', conf)