summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/config/opteng_config.yaml25
-rwxr-xr-xtest/functest/simulators/simulated-config/opteng_config.yaml25
-rw-r--r--test/optengine-tests/test_modelapi_invalid.json13
-rw-r--r--test/optengine-tests/test_modelapi_valid.json13
-rw-r--r--test/optengine-tests/test_optengine_invalid.json18
-rw-r--r--test/optengine-tests/test_optengine_invalid2.json15
-rw-r--r--test/optengine-tests/test_optengine_invalid_solver.json15
-rw-r--r--test/optengine-tests/test_optengine_modelId.json19
-rw-r--r--test/optengine-tests/test_optengine_no_modelid.json24
-rw-r--r--test/optengine-tests/test_optengine_no_optdata.json15
-rw-r--r--test/optengine-tests/test_optengine_solverid.json15
-rw-r--r--test/optengine-tests/test_optengine_valid.json20
-rw-r--r--test/optengine-tests/test_py_optengine_valid.json15
-rw-r--r--test/test_model_api.py71
-rw-r--r--test/test_optim_engine.py78
15 files changed, 381 insertions, 0 deletions
diff --git a/test/config/opteng_config.yaml b/test/config/opteng_config.yaml
new file mode 100755
index 0000000..4a7e57d
--- /dev/null
+++ b/test/config/opteng_config.yaml
@@ -0,0 +1,25 @@
+# Policy Platform -- requires Authorization
+policyPlatformUrl: https://policy-xacml-pdp:6969/policy/pdpx/decision/v1 # Policy Dev platform URL
+
+# AAF Authentication config
+is_aaf_enabled: False
+aaf_cache_expiry_mins: 5
+aaf_url: https://aaftest.simpledemo.onap.org:8095
+aaf_user_roles:
+ - '/optmodel:org.onap.oof.access|*|read ALL'
+ - '/optengine:org.onap.oof.access|*|read ALL'
+
+# Secret Management Service from AAF
+aaf_sms_url: https://aaf-sms.onap:10443
+aaf_sms_timeout: 30
+secret_domain: osdf
+aaf_ca_certs: ssl_certs/aaf_root_ca.cer
+
+osdfDatabaseHost: localhost
+osdfDatabaseSchema: osdf
+osdfDatabaseUsername: osdf
+osdfDatabasePassword: osdf
+osdfDatabasePort: 3306
+
+#key
+appkey: os35@rrtky400fdntc#001t5 \ No newline at end of file
diff --git a/test/functest/simulators/simulated-config/opteng_config.yaml b/test/functest/simulators/simulated-config/opteng_config.yaml
new file mode 100755
index 0000000..4a7e57d
--- /dev/null
+++ b/test/functest/simulators/simulated-config/opteng_config.yaml
@@ -0,0 +1,25 @@
+# Policy Platform -- requires Authorization
+policyPlatformUrl: https://policy-xacml-pdp:6969/policy/pdpx/decision/v1 # Policy Dev platform URL
+
+# AAF Authentication config
+is_aaf_enabled: False
+aaf_cache_expiry_mins: 5
+aaf_url: https://aaftest.simpledemo.onap.org:8095
+aaf_user_roles:
+ - '/optmodel:org.onap.oof.access|*|read ALL'
+ - '/optengine:org.onap.oof.access|*|read ALL'
+
+# Secret Management Service from AAF
+aaf_sms_url: https://aaf-sms.onap:10443
+aaf_sms_timeout: 30
+secret_domain: osdf
+aaf_ca_certs: ssl_certs/aaf_root_ca.cer
+
+osdfDatabaseHost: localhost
+osdfDatabaseSchema: osdf
+osdfDatabaseUsername: osdf
+osdfDatabasePassword: osdf
+osdfDatabasePort: 3306
+
+#key
+appkey: os35@rrtky400fdntc#001t5 \ No newline at end of file
diff --git a/test/optengine-tests/test_modelapi_invalid.json b/test/optengine-tests/test_modelapi_invalid.json
new file mode 100644
index 0000000..a58258e
--- /dev/null
+++ b/test/optengine-tests/test_modelapi_invalid.json
@@ -0,0 +1,13 @@
+{
+ "requestInfo": {
+ "transactinId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt"
+ },
+ "modelInfo": {
+ "modelId": "model2",
+ "solver": "mzn",
+ "description": "graph coloring problem for australia",
+ "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];"
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_modelapi_valid.json b/test/optengine-tests/test_modelapi_valid.json
new file mode 100644
index 0000000..1fbca5b
--- /dev/null
+++ b/test/optengine-tests/test_modelapi_valid.json
@@ -0,0 +1,13 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt"
+ },
+ "modelInfo": {
+ "modelId": "model2",
+ "solver": "mzn",
+ "description": "graph coloring problem for australia",
+ "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];"
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_invalid.json b/test/optengine-tests/test_optengine_invalid.json
new file mode 100644
index 0000000..9a0267a
--- /dev/null
+++ b/test/optengine-tests/test_optengine_invalid.json
@@ -0,0 +1,18 @@
+{
+ "requestInfo": {
+ "transactioId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "mzn",
+ "solverArgs": {
+ "solver": "geocode"
+ },
+ "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];",
+ "optData": {
+ "nc": 3
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_invalid2.json b/test/optengine-tests/test_optengine_invalid2.json
new file mode 100644
index 0000000..23c5a8e
--- /dev/null
+++ b/test/optengine-tests/test_optengine_invalid2.json
@@ -0,0 +1,15 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+
+ "solverArgs": {
+ "solver": "cbc"
+ },
+ "modelContent": "% Baking cakes for the school fete (with data file)\r\n\r\nint: flour; %no. grams of flour available\r\nint: banana; %no. of bananas available\r\nint: sugar; %no. grams of sugar available\r\nint: butter; %no. grams of butter available\r\nint: cocoa; %no. grams of cocoa available\r\n\r\nconstraint assert(flour >= 0,\"Invalid datafile: \" ++\r\n \"Amount of flour should be non-negative\");\r\nconstraint assert(banana >= 0,\"Invalid datafile: \" ++\r\n \"Amount of banana should be non-negative\");\r\nconstraint assert(sugar >= 0,\"Invalid datafile: \" ++\r\n \"Amount of sugar should be non-negative\");\r\nconstraint assert(butter >= 0,\"Invalid datafile: \" ++\r\n \"Amount of butter should be non-negative\");\r\nconstraint assert(cocoa >= 0,\"Invalid datafile: \" ++\r\n \"Amount of cocoa should be non-negative\");\r\n\r\nvar 0..100: b; % no. of banana cakes\r\nvar 0..100: c; % no. of chocolate cakes\r\n\r\n% flour\r\nconstraint 250*b + 200*c <= flour;\r\n% bananas\r\nconstraint 2*b <= banana;\r\n% sugar\r\nconstraint 75*b + 150*c <= sugar;\r\n% butter\r\nconstraint 100*b + 150*c <= butter;\r\n% cocoa\r\nconstraint 75*c <= cocoa;\r\n\r\n% maximize our profit\r\nsolve maximize 400*b + 450*c;\r\n\r\noutput [\"no. of banana cakes = \\(b)\\n\",\r\n \"no. of chocolate cakes = \\(c)\\n\"];"
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_invalid_solver.json b/test/optengine-tests/test_optengine_invalid_solver.json
new file mode 100644
index 0000000..a967c16
--- /dev/null
+++ b/test/optengine-tests/test_optengine_invalid_solver.json
@@ -0,0 +1,15 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "apy",
+ "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n",
+ "optData": {
+ "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; "
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_modelId.json b/test/optengine-tests/test_optengine_modelId.json
new file mode 100644
index 0000000..b676d91
--- /dev/null
+++ b/test/optengine-tests/test_optengine_modelId.json
@@ -0,0 +1,19 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "modelId": "test",
+ "solverArgs": {
+ "solver": "geocode"
+ },
+ "optData": {
+ "json": {
+ "nc": 3
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_no_modelid.json b/test/optengine-tests/test_optengine_no_modelid.json
new file mode 100644
index 0000000..9a8c3a4
--- /dev/null
+++ b/test/optengine-tests/test_optengine_no_modelid.json
@@ -0,0 +1,24 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "mzn",
+ "solverArgs": {
+ "solver": "cbc"
+ },
+ "modelContent": "% Baking cakes for the school fete (with data file)\r\n\r\nint: flour; %no. grams of flour available\r\nint: banana; %no. of bananas available\r\nint: sugar; %no. grams of sugar available\r\nint: butter; %no. grams of butter available\r\nint: cocoa; %no. grams of cocoa available\r\n\r\nconstraint assert(flour >= 0,\"Invalid datafile: \" ++\r\n \"Amount of flour should be non-negative\");\r\nconstraint assert(banana >= 0,\"Invalid datafile: \" ++\r\n \"Amount of banana should be non-negative\");\r\nconstraint assert(sugar >= 0,\"Invalid datafile: \" ++\r\n \"Amount of sugar should be non-negative\");\r\nconstraint assert(butter >= 0,\"Invalid datafile: \" ++\r\n \"Amount of butter should be non-negative\");\r\nconstraint assert(cocoa >= 0,\"Invalid datafile: \" ++\r\n \"Amount of cocoa should be non-negative\");\r\n\r\nvar 0..100: b; % no. of banana cakes\r\nvar 0..100: c; % no. of chocolate cakes\r\n\r\n% flour\r\nconstraint 250*b + 200*c <= flour;\r\n% bananas\r\nconstraint 2*b <= banana;\r\n% sugar\r\nconstraint 75*b + 150*c <= sugar;\r\n% butter\r\nconstraint 100*b + 150*c <= butter;\r\n% cocoa\r\nconstraint 75*c <= cocoa;\r\n\r\n% maximize our profit\r\nsolve maximize 400*b + 450*c;\r\n\r\noutput [\"no. of banana cakes = \\(b)\\n\",\r\n \"no. of chocolate cakes = \\(c)\\n\"];",
+ "optData": {
+ "json": {
+ "flour": 4000,
+ "banana": 6,
+ "sugar": 2000,
+ "butter": 500,
+ "cocoa": 500
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_no_optdata.json b/test/optengine-tests/test_optengine_no_optdata.json
new file mode 100644
index 0000000..f6645c8
--- /dev/null
+++ b/test/optengine-tests/test_optengine_no_optdata.json
@@ -0,0 +1,15 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "mzn",
+ "solverArgs": {
+ "solver": "geocode"
+ },
+ "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];"
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_solverid.json b/test/optengine-tests/test_optengine_solverid.json
new file mode 100644
index 0000000..bfd446c
--- /dev/null
+++ b/test/optengine-tests/test_optengine_solverid.json
@@ -0,0 +1,15 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "py",
+ "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n",
+ "optData": {
+ "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; "
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_optengine_valid.json b/test/optengine-tests/test_optengine_valid.json
new file mode 100644
index 0000000..8de2b71
--- /dev/null
+++ b/test/optengine-tests/test_optengine_valid.json
@@ -0,0 +1,20 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "mzn",
+ "solverArgs": {
+ "solver": "geocode"
+ },
+ "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];",
+ "optData": {
+ "json": {
+ "nc": 3
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/optengine-tests/test_py_optengine_valid.json b/test/optengine-tests/test_py_optengine_valid.json
new file mode 100644
index 0000000..bfd446c
--- /dev/null
+++ b/test/optengine-tests/test_py_optengine_valid.json
@@ -0,0 +1,15 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestID": "yyy-yyy-yyyy",
+ "sourceId": "cmopt",
+ "timeout": 600
+ },
+ "optimInfo": {
+ "solver": "py",
+ "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n",
+ "optData": {
+ "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; "
+ }
+ }
+} \ No newline at end of file
diff --git a/test/test_model_api.py b/test/test_model_api.py
new file mode 100644
index 0000000..2a1cecf
--- /dev/null
+++ b/test/test_model_api.py
@@ -0,0 +1,71 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2020 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import json
+import os
+
+import pytest
+from mock import patch
+from schematics.exceptions import DataError
+
+from runtime.model_api import create_model_data, get_model_data, delete_model_data, retrieve_all_models
+from runtime.models.api.model_request import OptimModelRequestAPI
+from runtime.optim_engine import validate_request
+
+BASE_DIR = os.path.dirname(__file__)
+
+ret_val = {'modelId': 'test', 'description': 'desc', 'solver': 'mzn'}
+
+
+class TestModelApi():
+
+ def test_valid_mapi_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_modelapi_valid.json").read())
+
+ assert OptimModelRequestAPI(req_json).validate() is None
+
+ def test_invalid_mapi_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_modelapi_invalid.json").read())
+ with pytest.raises(DataError):
+ validate_request(req_json)
+
+ @patch('runtime.model_api.build_model_dict')
+ @patch('mysql.connector.connect')
+ @patch('runtime.model_api.osdf_config')
+ def test_create_model(self, config, conn, model_data):
+ model_data.return_value = ret_val
+ req_json = json.loads(open("./test/optengine-tests/test_modelapi_valid.json").read())
+
+ create_model_data(req_json)
+
+ @patch('runtime.model_api.build_model_dict')
+ @patch('mysql.connector.connect')
+ @patch('runtime.model_api.osdf_config')
+ def test_retrieve_model(self, config, conn, model_data):
+ model_data.return_value = ret_val
+ get_model_data('test')
+
+ @patch('mysql.connector.connect')
+ @patch('runtime.model_api.osdf_config')
+ def test_delete_model(self, config, conn):
+ delete_model_data('test')
+
+ @patch('mysql.connector.connect')
+ @patch('runtime.model_api.osdf_config')
+ def test_retrieve_all_model(self, config, conn):
+ retrieve_all_models()
diff --git a/test/test_optim_engine.py b/test/test_optim_engine.py
new file mode 100644
index 0000000..e1756f8
--- /dev/null
+++ b/test/test_optim_engine.py
@@ -0,0 +1,78 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2020 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import json
+import os
+
+import pytest
+from mock import patch
+from schematics.exceptions import DataError
+
+from osdf.operation.exceptions import BusinessException
+from runtime.optim_engine import validate_request, process_request
+
+BASE_DIR = os.path.dirname(__file__)
+
+
+class TestOptimEngine():
+
+ def test_valid_optim_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_valid.json").read())
+
+ assert validate_request(req_json) == True
+
+ def test_invalid_optim_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid.json").read())
+ with pytest.raises(DataError):
+ validate_request(req_json)
+
+ def test_invalid_optim_request_without_modelid(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid2.json").read())
+ with pytest.raises(BusinessException):
+ validate_request(req_json)
+
+ def test_invalid_optim_request_no_optdata(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_no_optdata.json").read())
+ with pytest.raises(BusinessException):
+ validate_request(req_json)
+
+ def test_process_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_valid.json").read())
+
+ res = process_request(req_json)
+ assert res.status_code == 400
+
+ def test_py_process_request(self):
+ req_json = json.loads(open("./test/optengine-tests/test_py_optengine_valid.json").read())
+
+ res = process_request(req_json)
+ assert res.status_code == 200
+
+ def test_invalid_solver(self):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid_solver.json").read())
+
+ with pytest.raises(BusinessException):
+ process_request(req_json)
+
+ @patch('runtime.optim_engine.get_model_data')
+ def test_process_solverid_request(self, mocker):
+ req_json = json.loads(open("./test/optengine-tests/test_optengine_modelId.json").read())
+
+ data = 200, ('junk', '', '', 'py')
+ mocker.return_value = data
+ process_request(req_json)