[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Start outlining the oonibclient object.



commit 7efd771be71e654cf8d961ae33b13bd7a3cad6e5
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Tue Aug 20 16:36:30 2013 +0200

    Start outlining the oonibclient object.
    
    Write the minimum unittests that it must pass to be complete.
---
 ooni/oonibclient.py            |   57 ++++++++++++++++++++++++++++++++++++++++
 ooni/tests/test_oonibclient.py |   48 +++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py
new file mode 100644
index 0000000..28e42a7
--- /dev/null
+++ b/ooni/oonibclient.py
@@ -0,0 +1,57 @@
+import json
+
+from twisted.internet import defer, reactor
+from twisted.web.client import Agent
+
+from ooni.utils.net import BodyReceiver, StringProducer
+
+class InputFile(object):
+    def __init__(self, id, name=None, description=None, 
+                 version=None, author=None, date=None):
+        self.id = id
+        self.name = name
+        self.description = description
+        self.version = version
+        self.author = author
+        self.date = date
+
+        self._file = None
+
+class Deck(object):
+    pass
+
+class OONIBClient(object):
+    def __init__(self, address):
+        self.address = address
+        self.agent = Agent(reactor)
+
+    def queryBackend(self, method, urn, query=None):
+        finished = defer.Deferred()
+
+        bodyProducer = None
+        if query:
+            bodyProducer = StringProducer(json.dumps(query))
+
+        uri = self.address + urn
+        d = self.agent.request(method, uri, bodyProducer)
+        @d.addCallback
+        def cb(response):
+            content_length = response.headers.getRawHeaders('content-length')
+            response.deliverBody(BodyReceiver(finished, content_length, json.loads))
+
+        @d.addErrback
+        def eb(err):
+            finished.errback(err)
+
+        return finished
+
+    def getNettestPolicy(self):
+        pass
+
+    def queryBouncer(self, requested_helpers):
+        pass
+
+    def getInputPolicy(self):
+        pass
+
+
diff --git a/ooni/tests/test_oonibclient.py b/ooni/tests/test_oonibclient.py
new file mode 100644
index 0000000..17259a6
--- /dev/null
+++ b/ooni/tests/test_oonibclient.py
@@ -0,0 +1,48 @@
+from twisted.trial import unittest
+from twisted.internet import defer
+
+from ooni.oonibclient import OONIBClient
+
+input_id = 'e0611ecd28bead38a7afeb4dda8ae3449d0fc2e1ba53fa7355f2799dce9af290'
+
+class TestOONIBClient(unittest.TestCase):
+    def setUp(self):
+        self.oonibclient = OONIBClient('http://127.0.0.1:8888')
+    
+    @defer.inlineCallbacks
+    def test_query(self):
+        res = yield self.oonibclient.queryBackend('GET', '/policy/input')
+        self.assertTrue(isinstance(res, list))
+    
+    def test_get_input_list(self):
+        input_list = yield self.oonibclient.getInputList()
+        self.assertTrue(isinstance(inputList, list))
+
+    def test_get_input_descriptor(self):
+        input_descriptor = yield self.oonibclient.getInput(input_id)
+        for key in ['name', 'description', 
+                    'version', 'author', 'date']:
+            self.assertTrue(key in input_descriptor.keys())
+
+    def test_download_input(self):
+        pass
+
+    def test_get_deck_list(self):
+        input_list = yield self.oonibclient.getInputList()
+        self.assertTrue(isinstance(inputList, list))
+
+    def test_get_deck_descriptor(self):
+        pass
+
+    def test_download_deck(self):
+        pass
+
+    def test_get_nettest_list(self):
+        input_list = yield self.oonibclient.getInputList()
+        self.assertTrue(isinstance(inputList, list))
+
+    def test_get_nettest_descriptor(self):
+        pass
+
+    def test_download_nettest(self):
+        pass



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits