-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_server.py
executable file
·50 lines (43 loc) · 1.6 KB
/
test_server.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
#!/usr/bin/env python
'''
Tests.
'''
__author__ = 'Aditya Viswanathan'
__email__ = '[email protected]'
import requests
import semantics_pb2 as semantics
import subprocess
import threading
import time
import unittest
from flask import request
from server import app
class ServerSanity(unittest.TestCase):
@classmethod
def setUpClass(self):
# TODO(aditya): Make tests work by background launching the server here.
# Temporarily we need to run the server in a separate process and then
# run tests.
# self.server_process = subprocess.Popen(['python', 'server.py'])
pass
@classmethod
def tearDownClass(self):
# self.server_process.terminate()
pass
def testServerUp(self):
headers = {'Content-Type': 'application/octet-stream'}
input_text = semantics.InputText()
input_text.text = 'Hello how are you doing?'
resp = requests.post('http://localhost:8080/',
headers=headers, data=input_text.SerializeToString())
parse_tree = semantics.ParseTree()
parse_tree.ParseFromString(resp.content)
# TODO(aditya): Decide on testing strategy for parse trees here.
# Goldens-based validation can work but every improvement/modification
# to parser code will require an overwrite of the goldens. Or we can
# just do a baseline check here that ensures a valid semantics proto is
# returned by the HTTP server, but that doesn't really guarantee much
# about this service.
print(parse_tree)
if __name__ == '__main__':
unittest.main()