From d94552270b4682601fe5c2ee58beeb5117cae0f3 Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Mon, 3 Jun 2013 14:50:19 +0100 Subject: [PATCH] storing data in the database of pushlog info --- bisectcloud/base/test/pushlog.json | 3 +++ bisectcloud/base/test/test_tasks.py | 22 ++++++++++++++++++++++ bisectcloud/site/tasks.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 bisectcloud/base/test/pushlog.json create mode 100644 bisectcloud/base/test/test_tasks.py create mode 100644 bisectcloud/site/tasks.py diff --git a/bisectcloud/base/test/pushlog.json b/bisectcloud/base/test/pushlog.json new file mode 100644 index 0000000..762ab01 --- /dev/null +++ b/bisectcloud/base/test/pushlog.json @@ -0,0 +1,3 @@ +{"28834": {"branch_name": "Mozilla-Inbound", "revisions": ["71cd8f642cfa"]}, "28835": {"branch_name": "Mozilla-Inbound", +"revisions": ["b5b3993fd079"]}, "28836": {"branch_name": "Mozilla-Inbound", "revisions": ["b8122753e0b3", +"121b620c7e49"]}} diff --git a/bisectcloud/base/test/test_tasks.py b/bisectcloud/base/test/test_tasks.py new file mode 100644 index 0000000..fd223ef --- /dev/null +++ b/bisectcloud/base/test/test_tasks.py @@ -0,0 +1,22 @@ +import os +import json + + +import test_utils +import bisectcloud.site.tasks as task +from bisectcloud.site.models import * + +class TaskTests(test_utils.TestCase): + + def test_we_can_call_tasks(self): + pass + + def test_we_can_store_json_blob_in_datastore(self): + with open(os.path.join(os.path.dirname(__file__),'pushlog.json'), 'r') as f: + jsonblob = f.read() + + task._store_pushlog_in_datastore(json.loads(jsonblob)) + + self.assertEqual(4, len(Revisions.objects.all())) + self.assertEqual(3, len(Pushlog.objects.all())) + diff --git a/bisectcloud/site/tasks.py b/bisectcloud/site/tasks.py new file mode 100644 index 0000000..afe727e --- /dev/null +++ b/bisectcloud/site/tasks.py @@ -0,0 +1,17 @@ +import requests +from models import Pushlog, Revisions + +def get_pushlog(): + pass + +def _store_pushlog_in_datastore(push_json): + for k, v in push_json.items(): + pushlog = Pushlog(push_id = k, + branch_name=push_json[k]['branch_name']) + pushlog.save() + for revision in push_json[k]['revisions']: + revisions = Revisions(revisions=revision, + pushlog=pushlog) + revisions.save() + +