Esempio n. 1
0
    def test_get_deployment(self):
        with app.test_client() as c:
            rv = c.get(f"/projects/foo/deployments/{DEPLOYMENT_ID}")
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/projects/{PROJECT_ID}/deployments/foo")
            result = rv.get_json()
            expected = {"message": "The specified deployment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}")
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": EXPERIMENT_ID,
                "isActive": IS_ACTIVE,
                "name": NAME,
                "operators": result['operators'],
                "position": POSITION,
                "projectId": PROJECT_ID,
                "status": None,
                "updatedAt": result['updatedAt'],
                "uuid": DEPLOYMENT_ID,
            }
            self.assertDictEqual(expected, result)
Esempio n. 2
0
 def test_get_training(self):
     with app.test_client() as c:
         rv = c.get(
             f"/projects/1/experiments/{MOCKED_TRAINING_ID}/runs/latest")
         result = rv.get_json()
         self.assertIn("operators", result)
         self.assertEqual(rv.status_code, 200)
Esempio n. 3
0
 def test_list_figures(self):
     with app.test_client() as c:
         rv = c.get(
             f"/projects/1/experiments/{EXPERIMENT_ID}/runs/{RUN_ID}/operators/{OPERATOR_ID}/figures"
         )
         result = rv.get_json()
         self.assertIsInstance(result, list)
Esempio n. 4
0
 def test_index(self):
     with app.test_client() as c:
         rv = c.get("/")
         result = rv.get_data(as_text=True)
         expected = "{\"message\":\"PlatIAgro Pipelines v0.2.0\"}\n"
         self.assertEqual(result, expected)
         self.assertEqual(rv.status_code, 200)
Esempio n. 5
0
 def test_terminate_training(self):
     with app.test_client() as c:
         rv = c.delete(f"/projects/1/experiments/{MOCKED_TRAINING_ID}/runs")
         result = rv.get_json()
         expected = {"message": "Training deleted."}
         self.assertDictEqual(expected, result)
         self.assertEqual(rv.status_code, 200)
Esempio n. 6
0
 def test_delete_deployment(self):
     with app.test_client() as c:
         rv = c.delete(
             f"/projects/1/deployments/{MOCKED_DEPLOYMENT_ID}/runs")
         result = rv.get_json()
         expected = {"message": "Deployment deleted."}
         self.assertDictEqual(expected, result)
         self.assertEqual(rv.status_code, 200)
Esempio n. 7
0
 def test_list_metrics(self):
     with app.test_client() as c:
         rv = c.get(
             f"/projects/1/experiments/{EXPERIMENT_ID}/runs/{RUN_ID}/operators/{OPERATOR_ID}/metrics"
         )
         result = rv.get_json()
         self.assertIsInstance(result, list)
         self.assertEquals(result, [{"accuracy": 1.0}])
Esempio n. 8
0
    def test_list_deployments(self):
        with app.test_client() as c:
            rv = c.get("/projects/unk/deployments")
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/projects/{PROJECT_ID}/deployments")
            result = rv.get_json()
            self.assertIsInstance(result, list)
Esempio n. 9
0
    def test_get_deployment(self):
        with app.test_client() as c:
            rv = c.get("/projects/1/deployments/foo/runs")
            result = rv.get_json()
            expected = {"message": "Deployment not found."}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/projects/1/deployments/{MOCKED_DEPLOYMENT_ID}/runs")
            result = rv.get_json()
            self.assertIsInstance(result, dict)
            self.assertEqual(result['experimentId'], MOCKED_DEPLOYMENT_ID)
Esempio n. 10
0
    def test_update_deployment(self):
        with app.test_client() as c:
            rv = c.patch(f"/projects/foo/deployments/{DEPLOYMENT_ID}", json={})
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/foo", json={})
            result = rv.get_json()
            expected = {"message": "The specified deployment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}", json={
                "name": NAME_2,
            })
            result = rv.get_json()
            expected = {"message": "a deployment with that name already exists"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}", json={
                "unk": "bar",
            })
            self.assertEqual(rv.status_code, 400)

            # update deployment using the same name
            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}", json={
                "name": NAME,
            })
            self.assertEqual(rv.status_code, 200)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}", json={
                "name": "bar",
            })
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": EXPERIMENT_ID,
                "isActive": IS_ACTIVE,
                "name": "bar",
                "operators": result['operators'],
                "position": POSITION,
                "projectId": PROJECT_ID,
                "status": None,
                "updatedAt": result['updatedAt'],
                "uuid": DEPLOYMENT_ID
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)
Esempio n. 11
0
    def test_get_deployment_log(self):
        with app.test_client() as c:
            rv = c.get("/projects/1/deployments/foo/runs/latest/logs")
            result = rv.get_json()
            expected = {"message": "The specified deployment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(
                f"/projects/1/deployments/{MOCKED_DEPLOYMENT_ID}/runs/latest/logs"
            )
            result = rv.get_json()
            self.assertIsInstance(result, list)
            self.assertEqual(rv.status_code, 200)
Esempio n. 12
0
    def test_update_deployment_operator(self):
        with app.test_client() as c:
            rv = c.patch(f"/projects/foo/deployments/{DEPLOYMENT_ID}/operators/{OPERATOR_ID}", json={})
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/foo/operators/{OPERATOR_ID}", json={})
            result = rv.get_json()
            expected = {"message": "The specified deployment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}/operators/foo", json={})
            result = rv.get_json()
            expected = {"message": "The specified operator does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}/operators/{OPERATOR_ID}", json={
                "unk": "bar",
            })
            self.assertEqual(rv.status_code, 400)

            rv = c.patch(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}/operators/{OPERATOR_ID}", json={
                "parameters": {
                    "additionalProp1": "string",
                }
            })
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": None,
                "dependencies": [],
                "deploymentId": DEPLOYMENT_ID,
                "parameters": {'additionalProp1': 'string'},
                "positionX": None,
                "positionY": None,
                "taskId": TASK_ID,
                "updatedAt": result['updatedAt'],
                "uuid": OPERATOR_ID
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)
Esempio n. 13
0
    def test_delete_deployment(self):
        with app.test_client() as c:
            rv = c.delete(f"/projects/foo/deployments/{DEPLOYMENT_ID}")
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.delete(f"/projects/{PROJECT_ID}/deployments/unk")
            result = rv.get_json()
            expected = {"message": "The specified deployment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.delete(f"/projects/{PROJECT_ID}/deployments/{DEPLOYMENT_ID}")
            result = rv.get_json()
            expected = {"message": "Deployment deleted"}
            self.assertDictEqual(expected, result)
Esempio n. 14
0
    def test_post_training(self):
        with app.test_client() as c:
            rv = c.post(f"/projects/notExist/experiments/{EX_ID_1}/runs")
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments/notExist/runs")
            result = rv.get_json()
            expected = {"message": "The specified experiment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments/{EX_ID_2}/runs")
            result = rv.get_json()
            expected = {"message": "Necessary at least one operator"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments/{EX_ID_3}/runs")
            result = rv.get_json()
            expected = {"message": "Invalid dependency."}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments/{EX_ID_4}/runs")
            result = rv.get_json()
            expected = {"message": "The given pipeline has cycles."}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments/{EX_ID_1}/runs")
            result = rv.get_json()
            expected = {"message": "Pipeline running."}

            # uuid is machine-generated
            # we assert they exist, but we don't assert their values
            self.assertIn("runId", result)
            del result["runId"]
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)
Esempio n. 15
0
    def test_create_deployment(self):
        with app.test_client() as c:
            rv = c.post("/projects/unk/deployments", json={})
            result = rv.get_json()
            expected = {"message": "The specified project does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={})
            result = rv.get_json()
            expected = {"message": "The specified experiment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
            })
            result = rv.get_json()
            expected = {"message": "name is required"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": NAME,
            })
            result = rv.get_json()
            expected = {"message": "a deployment with that name already exists"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": NAME,
                "status": 'status'
            })
            result = rv.get_json()
            expected = {"message": "invalid status"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test task is required",
                "operators": [{}]
            })
            result = rv.get_json()
            expected = {"message": "taskId is required"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test task not exist",
                "operators": [{"taskId": "unk"}]
            })
            result = rv.get_json()
            expected = {"message": "The specified task does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test invalid parameters",
                "operators": [{
                        "parameters": [{"name": "coef", "value": 0.1}],
                        "taskId": TASK_ID,
                    }
                ]
            })
            result = rv.get_json()
            expected = {"message": "The specified parameters are not valid"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test create without parameters and dependencies",
                "operators": [{"taskId": TASK_ID,}]
            })
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": EXPERIMENT_ID,
                "isActive": IS_ACTIVE,
                "name": "test create without parameters and dependencies",
                "operators": result['operators'],
                "position": 2,
                "projectId": PROJECT_ID,
                'status': None,
                "updatedAt": result['updatedAt'],
                "uuid": result['uuid']
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test create without dependencies",
                "operators": [
                    {
                        "parameters": {"additionalProp1": "string"},
                        "taskId": TASK_ID,
                    }
                ]
            })
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": EXPERIMENT_ID,
                "isActive": IS_ACTIVE,
                "name": "test create without dependencies",
                "operators": result['operators'],
                "position": 3,
                "projectId": PROJECT_ID,
                'status': None,
                "updatedAt": result['updatedAt'],
                "uuid": result['uuid']
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)

            rv = c.post(f"/projects/{PROJECT_ID}/deployments", json={
                "experimentId": EXPERIMENT_ID,
                "name": "test create with parameters and dependencies",
                "operators": [
                    {
                        "dependencies": [TASK_ID],
                        "parameters": {"additionalProp1": "string"},
                        "taskId": TASK_ID,
                    }
                ]
            })
            result = rv.get_json()
            expected = {
                "createdAt": result['createdAt'],
                "experimentId": EXPERIMENT_ID,
                "isActive": IS_ACTIVE,
                "name": "test create with parameters and dependencies",
                "operators": result['operators'],
                "position": 4,
                "projectId": PROJECT_ID,
                'status': None,
                "updatedAt": result['updatedAt'],
                "uuid": result['uuid']
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)
Esempio n. 16
0
 def test_logger_request(self):
     with app.test_client() as c:
         rv = c.post(f"/seldon/logger/{TRAINING_ID}", json={"data": {"ndarray": [[1, 2], [1]]}})
         self.assertEqual(rv.status_code, 200)
Esempio n. 17
0
 def test_list_training_runs(self):
     with app.test_client() as c:
         rv = c.get(f"/projects/1/experiments/{MOCKED_TRAINING_ID}/runs")
         result = rv.get_json()
         self.assertIsInstance(result, object)
         self.assertEqual(rv.status_code, 200)
Esempio n. 18
0
    def test_get_dataset(self):
        with app.test_client() as c:
            rv = c.get(
                f"/projects/1/experiments/unk/runs/{RUN_ID}/operators/{OP_ID_1_1}/datasets"
            )
            result = rv.get_json()
            expected = {"message": "The specified experiment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/unk/datasets"
            )
            result = rv.get_json()
            expected = {"message": "The specified operator does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            # operators without dataset paramater
            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_2}/runs/{RUN_ID}/operators/{OP_ID_2_2}/datasets"
            )
            self.assertEqual(rv.status_code, 404)

            # dataset without run_id in metadata
            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_3}/runs/{RUN_ID}/operators/{OP_ID_3_1}/datasets"
            )
            self.assertEqual(rv.status_code, 404)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/{OP_ID_1_1}/datasets"
            )
            result = rv.get_json()
            expected = {
                "columns": ["col0", "col1", "col2", "col3", "col4", "col5"],
                "data": [["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"]],
                "total":
                3
            }
            self.assertDictEqual(expected, result)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/{OP_ID_1_2}/datasets"
            )
            result = rv.get_json()
            expected = {
                "columns": ["col0", "col1", "col2", "col3", "col4", "col5"],
                "data": [["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"]],
                "total":
                3
            }
            self.assertDictEqual(expected, result)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/{OP_ID_1_1}/datasets?page_size=-1"
            )
            result = rv.get_json()
            expected = {
                "columns": ["col0", "col1", "col2", "col3", "col4", "col5"],
                "data": [["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
                         ["01/01/2000", 5.1, 3.5, 1.4, 0.2, "Iris-setosa"]],
            }
            self.assertDictEqual(expected, result)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/{OP_ID_1_1}/datasets",
                headers={'Accept': 'application/csv'})
            result = rv.data
            expected = b'col0,col1,col2,col3,col4,col5\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n'
            self.assertEquals(expected, result)

            rv = c.get(
                f"/projects/1/experiments/{EXP_ID_1}/runs/{RUN_ID}/operators/{OP_ID_1_1}/datasets?page_size=-1",
                headers={'Accept': 'application/csv'})
            result = rv.data
            expected = b'col0,col1,col2,col3,col4,col5\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n01/01/2000,5.1,3.5,1.4,0.2,Iris-setosa\n'
            self.assertEquals(expected, result)
Esempio n. 19
0
 def test_logger_response(self):
     with app.test_client() as c:
         rv = c.post(f"/seldon/logger/{TRAINING_ID}",
                     json={"data": {"names": ["proba"], "ndarray": [[0.1951846770138402]]}, "meta": {}})
         self.assertEqual(rv.status_code, 200)