Skip to content

Commit 032c627

Browse files
committed
Added an example to save a single result
- Using requests it saves a single result. Note, models like benchmark, environment etc. are not created automatically. That has to be done via the api beforehand. Change-Id: I07e57d03e91fa206a1bf0667c8c43e54c8a7e258
1 parent 676ef78 commit 032c627

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
# -*- coding: utf-8 -*-
4+
5+
"""
6+
Submit a single result via the RESTful API using requests
7+
8+
Note, that is just an example. You need to add an user
9+
to get the apikey via the /admin
10+
All resources in the result_data dict need to exist.
11+
"""
12+
import json
13+
import requests
14+
15+
def get_data():
16+
result_data = {
17+
'commitid': '/api/v1/revision/2/',
18+
'branch': '/api/v1/branch/1/', # Always use default for trunk/master/tip
19+
'project': '/api/v1/project/2/',
20+
'executable': '/api/v1/executable/1/',
21+
'benchmark': '/api/v1/benchmark/1/',
22+
'environment': '/api/v1/environment/2/',
23+
'result_value': 4000,
24+
}
25+
headers = {'content-type': 'application/json',
26+
'Authorization': 'ApiKey apiuser2:2ee0fa1a175ccc3b88b245e799d70470e5d53430'}
27+
url = 'http://localhost:8000/api/v1/benchmark-result/'
28+
return(url, result_data, headers)
29+
30+
31+
def main():
32+
url, result_data, headers = get_data()
33+
print "{0}: {1}".format(url, result_data)
34+
r = requests.post(url, data=json.dumps(result_data), headers=headers)
35+
print r
36+
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)