Adding `requests` to the python container
- Add the requests module to the python container
- Add tests to assert that module installation for the python container works as expected.
Solves #1190
diff --git a/tests/src/actionContainers/PythonActionContainerTests.scala b/tests/src/actionContainers/PythonActionContainerTests.scala
index b7f6bad..4891f63 100644
--- a/tests/src/actionContainers/PythonActionContainerTests.scala
+++ b/tests/src/actionContainers/PythonActionContainerTests.scala
@@ -23,6 +23,7 @@
import spray.json.JsObject
import spray.json.JsString
import common.WskActorSystem
+import spray.json.JsNumber
@RunWith(classOf[JUnitRunner])
class PythonActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
@@ -129,4 +130,52 @@
e shouldBe empty
})
}
+
+ it should "error when importing a not-supported package" in {
+ val (out, err) = withActionContainer() { c =>
+ val code = """
+ |import iamnotsupported
+ |def main(args):
+ | return { "error": "not reaching here" }
+ """.stripMargin
+
+ val (initCode, res) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.run(runPayload(JsObject()))
+ runCode should be(502)
+ }
+
+ checkStreams(out, err, {
+ case (o, e) =>
+ o shouldBe empty
+ e should include("Traceback")
+ })
+ }
+
+ it should "be able to import additional packages as installed in the image" in {
+ val (out, err) = withActionContainer() { c =>
+ val code = """
+ |import requests
+ |def main(args):
+ | r = requests.get("https://httpbin.org/status/418")
+ | return { "status": r.status_code }
+ """.stripMargin
+
+ val (initCode, _) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.run(runPayload(JsObject()))
+ runCode should be(200) // action writer returning an error is OK
+
+ runRes shouldBe defined
+ runRes should be(Some(JsObject("status" -> JsNumber(418))))
+ }
+
+ checkStreams(out, err, {
+ case (o, e) =>
+ o shouldBe empty
+ e shouldBe empty
+ })
+ }
}