Permalink
Browse files

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
  • Loading branch information...
1 parent 676ef78 commit 032c6279123e2eb1b623f7f9783bdbe34b34e773 @a8 a8 committed Jun 21, 2012
Showing with 39 additions and 0 deletions.
  1. +39 −0 tools/save_single_result_via_api.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+# -*- coding: utf-8 -*-
+
+"""
+Submit a single result via the RESTful API using requests
+
+Note, that is just an example. You need to add an user
+to get the apikey via the /admin
+All resources in the result_data dict need to exist.
+"""
+import json
+import requests
+
+def get_data():
+ result_data = {
+ 'commitid': '/api/v1/revision/2/',
+ 'branch': '/api/v1/branch/1/', # Always use default for trunk/master/tip
+ 'project': '/api/v1/project/2/',
+ 'executable': '/api/v1/executable/1/',
+ 'benchmark': '/api/v1/benchmark/1/',
+ 'environment': '/api/v1/environment/2/',
+ 'result_value': 4000,
+ }
+ headers = {'content-type': 'application/json',
+ 'Authorization': 'ApiKey apiuser2:2ee0fa1a175ccc3b88b245e799d70470e5d53430'}
+ url = 'http://localhost:8000/api/v1/benchmark-result/'
+ return(url, result_data, headers)
+
+
+def main():
+ url, result_data, headers = get_data()
+ print "{0}: {1}".format(url, result_data)
+ r = requests.post(url, data=json.dumps(result_data), headers=headers)
+ print r
+
+
+if __name__ == "__main__":
+ main()

0 comments on commit 032c627

Please sign in to comment.