[tor-commits] [ooni-probe/master] Add two basic unittests

art at torproject.org art at torproject.org
Mon Sep 19 12:14:24 UTC 2016


commit ae5d78b838fd910d042bdddd65ff96fbc8a1103f
Author: Arturo Filastò <arturo at filasto.net>
Date:   Tue Jul 26 12:39:40 2016 +0200

    Add two basic unittests
---
 ooni/tests/test_resources.py | 41 +++++++++++++++++++++++++++++++++++++++++
 ooni/tests/test_socks.py     | 10 ++++++++++
 2 files changed, 51 insertions(+)

diff --git a/ooni/tests/test_resources.py b/ooni/tests/test_resources.py
new file mode 100644
index 0000000..92961ea
--- /dev/null
+++ b/ooni/tests/test_resources.py
@@ -0,0 +1,41 @@
+from ooni.resources import get_out_of_date_resources, check_for_update
+from ooni.tests.bases import ConfigTestCase
+
+SAMPLE_CURRENT_MANIFEST = {
+    "resources": [
+        {
+            "version": 0,
+            "path": "some/file-to-update.txt"
+        },
+        {
+            "version": 0,
+            "path": "some/file-stays-stame.txt"
+        },
+        {
+            "version": 0,
+            "path": "some/file-to-delete.txt"
+        }
+    ]
+}
+
+SAMPLE_NEW_MANIFEST = {
+    "resources": [
+        {
+            "version": 1,
+            "path": "some/file-to-update.txt"
+        },
+        {
+            "version": 0,
+            "path": "some/file-stays-stame.txt"
+        }
+    ]
+}
+class TestResourceUpdate(ConfigTestCase):
+    def test_check_for_updates(self):
+        return check_for_update()
+
+    def test_resources_out_of_date(self):
+        paths_to_update, paths_to_delete = get_out_of_date_resources(
+            SAMPLE_CURRENT_MANIFEST, SAMPLE_NEW_MANIFEST)
+        self.assertEqual(paths_to_update[0]["path"], "some/file-to-update.txt")
+        self.assertEqual(paths_to_delete[0]["path"], "some/file-to-delete.txt")
diff --git a/ooni/tests/test_socks.py b/ooni/tests/test_socks.py
new file mode 100644
index 0000000..2d2cdd8
--- /dev/null
+++ b/ooni/tests/test_socks.py
@@ -0,0 +1,10 @@
+from twisted.trial import unittest
+
+from twisted.internet.endpoints import TCP4ClientEndpoint
+from twisted.internet import reactor
+from ooni.utils.socks import TrueHeadersSOCKS5Agent
+
+class TestSocks(unittest.TestCase):
+    def test_create_agent(self):
+        proxyEndpoint = TCP4ClientEndpoint(reactor, '127.0.0.1', 9050)
+        agent = TrueHeadersSOCKS5Agent(reactor, proxyEndpoint=proxyEndpoint)





More information about the tor-commits mailing list