-
Notifications
You must be signed in to change notification settings - Fork 0
/
doeServeTest.py
68 lines (58 loc) · 2.01 KB
/
doeServeTest.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
doeTest (c) University of Manchester 2019
doeTest is licensed under the MIT License.
To view a copy of this license, visit <http://opensource.org/licenses/MIT/>.
Created on Wed May 1 09:54:39 2019
@author: Pablo Carbonell, SYNBIOCHEM
@description: Test the DoE server
"""
import requests
import json
import os
import csv
#url = 'http://127.0.0.1:8989/REST'
url = 'http://optbiodes.synbiochem.co.uk/REST'
def testApp(url=url):
r = requests.get( url )
res = json.loads( r.content.decode('utf-8') )
print( res )
def testUpload(url=url):
example = os.path.join( 'test', 'DoE_sheet.csv' )
files = { 'file': open(example, 'rb' ) }
values = {'size': 48, 'format': 'csv'}
r = requests.post( os.path.join(url, 'Query' ), files=files, data=values )
res = json.loads( r.content.decode('utf-8') )
M = res['data']['M']
out = os.path.join( 'test', 'DoE_run.csv')
with open(out, 'w') as h:
cw = csv.writer(h)
cw.writerow( res['data']['names'] )
for row in M:
cw.writerow( row )
print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] )
def testUploadSbol(url=url):
parts = os.path.join( 'test', 'RefParts.csv' )
genes = os.path.join( 'test', 'GeneParts.csv' )
files = {
'parts': open(parts, 'rb' ),
'genes': open(genes, 'rb')
}
values = {'size': 48}
r = requests.post( os.path.join(url, 'Parts' ), files=files, data=values )
res = json.loads( r.content.decode('utf-8') )
M = res['data']['M']
out = os.path.join( 'test', 'DoE_run2.csv')
with open(out, 'w') as h:
cw = csv.writer(h)
cw.writerow( res['data']['names'] )
for row in M:
cw.writerow( row )
out2 = os.path.join('test', 'out.sbol')
open(out2, 'w').write(res['data']['sbol'])
print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] )
if __name__ == '__main__':
testApp()
testUpload()
testUploadSbol()