support/testing: add python-treq tests
authorRicardo Martincoski <ricardo.martincoski@gmail.com>
Fri, 16 Nov 2018 03:57:34 +0000 (01:57 -0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Fri, 23 Nov 2018 21:05:46 +0000 (22:05 +0100)
Use a simple script to check the basic usage. The target has no https
server, so a connection from in the target to localhost must not
succeed.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
.gitlab-ci.yml
support/testing/tests/package/sample_python_treq.py [new file with mode: 0644]
support/testing/tests/package/test_python_treq.py [new file with mode: 0644]

index 743f4edc06880d4bf5c99ee7e324c03c65ccb19f..61a6997178f7e82ffc2138b19812071be61b44d3 100644 (file)
@@ -348,6 +348,8 @@ tests.package.test_python_pyyaml.TestPythonPy3Pyyaml: *runtime_test
 tests.package.test_python_service_identity.TestPythonPy2ServiceIdentity: *runtime_test
 tests.package.test_python_service_identity.TestPythonPy3ServiceIdentity: *runtime_test
 tests.package.test_python_subprocess32.TestPythonPy2Subprocess32: *runtime_test
+tests.package.test_python_treq.TestPythonPy2Treq: *runtime_test
+tests.package.test_python_treq.TestPythonPy3Treq: *runtime_test
 tests.package.test_python_twisted.TestPythonPy2Twisted: *runtime_test
 tests.package.test_python_twisted.TestPythonPy3Twisted: *runtime_test
 tests.package.test_python_txaio.TestPythonPy2Txaio: *runtime_test
diff --git a/support/testing/tests/package/sample_python_treq.py b/support/testing/tests/package/sample_python_treq.py
new file mode 100644 (file)
index 0000000..974fdcd
--- /dev/null
@@ -0,0 +1,16 @@
+from twisted.internet import reactor
+import treq
+
+
+def done(response):
+    print(response.code)
+    reactor.stop()
+
+
+def err(fail):
+    print(fail.value)
+    reactor.stop()
+
+
+treq.get("https://localhost").addCallback(done).addErrback(err)
+reactor.run()
diff --git a/support/testing/tests/package/test_python_treq.py b/support/testing/tests/package/test_python_treq.py
new file mode 100644 (file)
index 0000000..7108b95
--- /dev/null
@@ -0,0 +1,29 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonTreq(TestPythonPackageBase):
+    sample_scripts = ["tests/package/sample_python_treq.py"]
+
+    def run_sample_scripts(self):
+        cmd = self.interpreter + " sample_python_treq.py"
+        output, exit_code = self.emulator.run(cmd, timeout=20)
+        self.assertIn("Connection refused", output[0])
+        self.assertEqual(exit_code, 0)
+
+
+class TestPythonPy2Treq(TestPythonTreq):
+    __test__ = True
+    config = TestPythonTreq.config + \
+        """
+        BR2_PACKAGE_PYTHON=y
+        BR2_PACKAGE_PYTHON_TREQ=y
+        """
+
+
+class TestPythonPy3Treq(TestPythonTreq):
+    __test__ = True
+    config = TestPythonTreq.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_TREQ=y
+        """