示例#1
0
    def test_create_experiment(self):
        with app.test_client() as c:
            rv = c.post("/projects/unk/experiments", 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}/experiments", json={})
            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}/experiments",
                        json={
                            "name": NAME,
                        })
            result = rv.get_json()
            expected = {
                "message": "an experiment with that name already exists"
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments",
                        json={
                            "name": "test",
                        })
            result = rv.get_json()
            expected = {
                "name": "test",
                "projectId": PROJECT_ID,
                "position": 2,
                "isActive": IS_ACTIVE,
                "operators": [],
            }
            # uuid, created_at, updated_at are machine-generated
            # we assert they exist, but we don't assert their values
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
        """Copy operators for a given experiment"""
        with app.test_client() as c:
            rv = c.post(f"/projects/{PROJECT_ID}/experiments",
                        json={
                            "name": f"{NAME_COPYFROM}",
                            "copy_from": f"{EXPERIMENT_ID}"
                        })
            self.assertEqual(rv.status_code, 200)

            rv = c.post(f"/projects/{PROJECT_ID}/experiments",
                        json={
                            "name": f"TESCOPY",
                            "copy_from": f"4555"
                        })
            self.assertEqual(rv.status_code, 400)
示例#2
0
 def test_ping(self):
     with app.test_client() as c:
         rv = c.get("/")
         result = rv.get_data(as_text=True)
         expected = "pong"
         self.assertEqual(result, expected)
         self.assertEqual(rv.status_code, 200)
示例#3
0
    def test_delete_operator(self):
        with app.test_client() as c:
            rv = c.delete(
                f"/projects/unk/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_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}/experiments/unk/operators/{OPERATOR_ID}"
            )
            result = rv.get_json()
            expected = {"message": "The specified experiment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

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

            rv = c.delete(
                f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_ID}"
            )
            result = rv.get_json()
            expected = {"message": "Operator deleted"}
            self.assertDictEqual(expected, result)
示例#4
0
    def test_get_project(self):
        with app.test_client() as c:
            rv = c.get("/projects/foo")
            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}")
            result = rv.get_json()
            result_experiments = result.pop("experiments")
            expected = {
                "uuid": PROJECT_ID,
                "name": NAME,
                "createdAt": CREATED_AT_ISO,
                "updatedAt": UPDATED_AT_ISO,
                "description": DESCRIPTION,
            }
            self.assertDictEqual(expected, result)

            expected = {
                "uuid": EXPERIMENT_ID,
                "name": EXPERIMENT_NAME,
                "projectId": PROJECT_ID,
                "position": 0,
                "isActive": True,
                "operators": [],
            }
            self.assertEqual(len(result_experiments), 1)
            machine_generated = ["createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result_experiments[0])
                del result_experiments[0][attr]
            self.assertDictEqual(expected, result_experiments[0])
示例#5
0
 def test_delete_projects(self):
     with app.test_client() as c:
         rv = c.post("/projects/deleteprojects", json=[{"uuid": "1234"}])
         result = rv.get_json()
         expected = {"message": "The specified project does not exist"}
         self.assertDictEqual(expected, result)
         self.assertEqual(rv.status_code, 404)
示例#6
0
    def test_update_template(self):
        with app.test_client() as c:
            rv = c.patch("/templates/foo", json={})
            result = rv.get_json()
            expected = {"message": "The specified template does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.patch(f"/templates/{TEMPLATE_ID}", json={
                "unk": "bar",
            })
            result = rv.get_json()
            self.assertEqual(rv.status_code, 400)

            rv = c.patch(f"/templates/{TEMPLATE_ID}", json={
                "name": "bar",
            })
            result = rv.get_json()
            expected = {
                "uuid": TEMPLATE_ID,
                "name": "bar",
                "operators": OPERATORS,
                "createdAt": CREATED_AT_ISO,
            }
            machine_generated = ["updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
示例#7
0
    def test_update_project(self):
        with app.test_client() as c:
            rv = c.patch("/projects/foo", 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}", json={
                "name": NAME_2,
            })
            result = rv.get_json()
            expected = {"message": "a project with that name already exists"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

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

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

            rv = c.patch(f"/projects/{PROJECT_ID}", json={
                "name": "bar",
            })
            result = rv.get_json()
            result_experiments = result.pop("experiments")
            expected = {
                "uuid": PROJECT_ID,
                "name": "bar",
                "createdAt": CREATED_AT_ISO,
                "description": DESCRIPTION,
            }
            machine_generated = ["updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)

            expected = {
                "uuid": EXPERIMENT_ID,
                "name": EXPERIMENT_NAME,
                "projectId": PROJECT_ID,
                "dataset": None,
                "target": None,
                "position": 0,
                "isActive": True,
                "operators": [],
            }
            self.assertEqual(len(result_experiments), 1)
            machine_generated = ["createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result_experiments[0])
                del result_experiments[0][attr]
            self.assertDictEqual(expected, result_experiments[0])
示例#8
0
    def test_get_experiment(self):
        with app.test_client() as c:
            rv = c.get(f"/projects/foo/experiments/{EXPERIMENT_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}/experiments/foo")
            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/{PROJECT_ID}/experiments/{EXPERIMENT_ID}")
            result = rv.get_json()
            expected = {
                "uuid": EXPERIMENT_ID,
                "name": NAME,
                "projectId": PROJECT_ID,
                "dataset": DATASET,
                "target": TARGET,
                "position": POSITION,
                "isActive": IS_ACTIVE,
                "operators": OPERATORS,
                "createdAt": CREATED_AT_ISO,
                "updatedAt": UPDATED_AT_ISO,
            }
            self.assertDictEqual(expected, result)
示例#9
0
    def test_get_task(self):
        with app.test_client() as c:
            rv = c.get("/tasks/foo")
            result = rv.get_json()
            expected = {"message": "The specified task does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/tasks/{TASK_ID}")
            result = rv.get_json()
            expected = {
                "uuid": TASK_ID,
                "name": "name foo",
                "description": DESCRIPTION,
                "image": IMAGE,
                "commands": COMMANDS,
                "arguments": ARGUMENTS,
                "tags": TAGS,
                "experimentNotebookPath": EXPERIMENT_NOTEBOOK_PATH,
                "deploymentNotebookPath": DEPLOYMENT_NOTEBOOK_PATH,
                "isDefault": IS_DEFAULT,
                "parameters": PARAMETERS,
                "createdAt": CREATED_AT_ISO,
                "updatedAt": UPDATED_AT_ISO,
            }
            self.assertDictEqual(expected, result)
示例#10
0
 def test_list_metrics(self):
     with app.test_client() as c:
         rv = c.get(
             f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_ID}/metrics"
         )
         result = rv.get_json()
         self.assertIsInstance(result, list)
示例#11
0
 def test_update_dependencies(self):
     with app.test_client() as c:
         rv = c.post(f"/projects/{PROJECT_ID}/experiments",
                     json={
                         "name": "test2",
                         "copy_from": f"{EXPERIMENT_ID}"
                     })
         self.assertEqual(rv.status_code, 200)
示例#12
0
    def test_list_experiments(self):
        with app.test_client() as c:
            rv = c.get("/projects/unk/experiments")
            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}/experiments")
            result = rv.get_json()
            self.assertIsInstance(result, list)
示例#13
0
    def test_list_parameters(self):
        with app.test_client() as c:
            rv = c.get("/tasks/unk/parameters")
            result = rv.get_json()
            expected = {"message": "The specified task does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/tasks/{TASK_ID}/parameters")
            result = rv.get_json()
            self.assertIsInstance(result, list)
示例#14
0
    def test_update_compare_result(self):
        with app.test_client() as c:
            rv = c.patch(f"/projects/foo/comparisons/{COMPARE_RESULT_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}/comparisons/foo", json={})
            result = rv.get_json()
            expected = {
                "message": "The specified compare result does not exist"
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

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

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

            rv = c.patch(
                f"/projects/{PROJECT_ID}/comparisons/{COMPARE_RESULT_ID}",
                json={
                    "experimentId": EXPERIMENT_ID,
                })
            result = rv.get_json()
            expected = {
                "uuid": COMPARE_RESULT_ID,
                "projectId": PROJECT_ID,
                "experimentId": EXPERIMENT_ID,
                "operatorId": None,
                "runId": None,
                "createdAt": CREATED_AT_ISO,
            }
            machine_generated = ["updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 200)
示例#15
0
    def test_delete_template(self):
        with app.test_client() as c:
            rv = c.delete("/templates/unk")
            result = rv.get_json()
            expected = {"message": "The specified template does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.delete(f"/templates/{TEMPLATE_ID}")
            result = rv.get_json()
            expected = {"message": "Template deleted"}
            self.assertDictEqual(expected, result)
示例#16
0
    def test_delete_project(self):
        with app.test_client() as c:
            rv = c.delete("/projects/unk")
            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}")
            result = rv.get_json()
            expected = {"message": "Project deleted"}
            self.assertDictEqual(expected, result)
示例#17
0
    def test_delete_component(self):
        with app.test_client() as c:
            rv = c.delete("/components/unk")
            result = rv.get_json()
            expected = {"message": "The specified component does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.delete(f"/components/{COMPONENT_ID}")
            result = rv.get_json()
            expected = {"message": "Component deleted"}
            self.assertDictEqual(expected, result)
示例#18
0
    def test_create_project(self):
        with app.test_client() as c:
            rv = c.post("/projects", json={})
            result = rv.get_json()
            expected = {"message": "name is required"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

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

            project_name = str(uuid_alpha())

            rv = c.post("/projects", json={
                "name": project_name,
                "description": "description"
            })
            result = rv.get_json()
            result_experiments = result.pop("experiments")
            expected = {
                "name": project_name,
                "description": "description",
            }
            # uuid, created_at, updated_at are machine-generated
            # we assert they exist, but we don't assert their values
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)

            expected = {
                "name": EXPERIMENT_NAME,
                "dataset": None,
                "target": None,
                "position": 0,
                "isActive": True,
                "operators": [],
            }
            self.assertEqual(len(result_experiments), 1)
            machine_generated = ["uuid", "projectId", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result_experiments[0])
                del result_experiments[0][attr]
            self.assertDictEqual(expected, result_experiments[0])
示例#19
0
    def test_list_tasks(self):
        with app.test_client() as c:
            rv = c.get("/tasks")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get("/tasks?order=uuid asc")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get("/tasks?order=uuid desc")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get("/tasks?page=1&order=uuid asc")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get(f"/tasks?name={NAME}&page=1&order=uuid asc")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get(
                f"/tasks?name={NAME}&page=1&page_size=10&order=name desc")
            result = rv.get_json()
            self.assertIsInstance(result["tasks"], list)
            self.assertIsInstance(result["total"], int)

            rv = c.get(f"/tasks?order=foo")
            result = rv.get_json()
            expected = {
                "message":
                "It was not possible to sort with the specified parameter"
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.get(f"/tasks?order=foo bar")
            result = rv.get_json()
            expected = {
                "message":
                "It was not possible to sort with the specified parameter"
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)
示例#20
0
    def test_get_template(self):
        with app.test_client() as c:
            rv = c.get("/templates/foo")
            result = rv.get_json()
            expected = {"message": "The specified template does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/templates/{TEMPLATE_ID}")
            result = rv.get_json()
            expected = {
                "uuid": TEMPLATE_ID,
                "name": NAME,
                "operators": OPERATORS,
                "createdAt": CREATED_AT_ISO,
                "updatedAt": UPDATED_AT_ISO,
            }
            self.assertDictEqual(expected, result)
示例#21
0
    def test_create_template(self):
        with app.test_client() as c:
            rv = c.post("/templates", json={})
            result = rv.get_json()
            expected = {"message": "name is required"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post("/templates", json={
                "name": "foo",
            })
            result = rv.get_json()
            expected = {"message": "experimentId is required"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post("/templates",
                        json={
                            "name": "foo",
                            "experimentId": "UNK",
                        })
            result = rv.get_json()
            expected = {"message": "The specified experiment does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.post("/templates",
                        json={
                            "name": "foo",
                            "experimentId": EXPERIMENT_ID,
                        })
            result = rv.get_json()
            expected = {
                "name": "foo",
                "operators": OPERATORS,
            }
            # uuid, created_at, updated_at are machine-generated
            # we assert they exist, but we don't assert their values
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
示例#22
0
    def test_get_dataset(self):
        with app.test_client() as c:
            rv = c.get(f"/projects/unk/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_ID}/datasets")
            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}/experiments/unk/operators/{OPERATOR_ID}/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/{PROJECT_ID}/experiments/{EXPERIMENT_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)

            rv = c.get(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_ID2}/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"],
                ]
            }
            self.assertDictEqual(expected, result)

            rv = c.get(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}/operators/{OPERATOR_ID}/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"],
                ]
            }
            self.assertDictEqual(result, expected)
示例#23
0
    def test_delete_task(self):
        with app.test_client() as c:
            # task is none
            rv = c.delete("/tasks/unk")
            result = rv.get_json()
            expected = {"message": "The specified task does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            # jupyter file is not none
            rv = c.delete(f"/tasks/{TASK_ID}")
            result = rv.get_json()
            expected = {"message": "Task deleted"}
            self.assertDictEqual(expected, result)

            # jupyter file is none
            rv = c.delete(f"/tasks/{TASK_ID_2}")
            result = rv.get_json()
            expected = {"message": "Task deleted"}
            self.assertDictEqual(expected, result)
示例#24
0
    def test_delete_compare_result(self):
        with app.test_client() as c:
            rv = c.delete(f"/projects/foo/comparisons/{COMPARE_RESULT_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}/comparisons/unk")
            result = rv.get_json()
            expected = {
                "message": "The specified compare result does not exist"
            }
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.delete(
                f"/projects/{PROJECT_ID}/comparisons/{COMPARE_RESULT_ID}")
            result = rv.get_json()
            expected = {"message": "Compare result deleted"}
            self.assertDictEqual(expected, result)
示例#25
0
    def test_create_compare_result(self):
        with app.test_client() as c:
            rv = c.post("/projects/unk/comparisons")
            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}/comparisons")
            result = rv.get_json()
            expected = {
                "projectId": PROJECT_ID,
                "experimentId": None,
                "operatorId": None,
                "runId": None,
            }
            # uuid, created_at, updated_at are machine-generated
            # we assert they exist, but we don't assert their values
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
示例#26
0
    def test_get_component(self):
        with app.test_client() as c:
            rv = c.get("/components/foo")
            result = rv.get_json()
            expected = {"message": "The specified component does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 404)

            rv = c.get(f"/components/{COMPONENT_ID}")
            result = rv.get_json()
            expected = {
                "uuid": COMPONENT_ID,
                "name": "foo",
                "description": DESCRIPTION,
                "tags": TAGS,
                "trainingNotebookPath": TRAINING_NOTEBOOK_PATH,
                "inferenceNotebookPath": INFERENCE_NOTEBOOK_PATH,
                "isDefault": IS_DEFAULT,
                "parameters": PARAMETERS,
                "createdAt": CREATED_AT_ISO,
                "updatedAt": UPDATED_AT_ISO,
            }
            self.assertDictEqual(expected, result)
示例#27
0
    def test_create_experiment(self):
        with app.test_client() as c:
            rv = c.post("/projects/unk/experiments", 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}/experiments", json={})
            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}/experiments",
                        json={
                            "name": "test",
                            "dataset": DATASET,
                            "target": TARGET,
                        })
            result = rv.get_json()
            expected = {
                "name": "test",
                "projectId": PROJECT_ID,
                "dataset": DATASET,
                "target": TARGET,
                "position": 1,
                "isActive": IS_ACTIVE,
                "operators": [],
            }
            # uuid, created_at, updated_at are machine-generated
            # we assert they exist, but we don't assert their values
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
示例#28
0
 def test_list_projects(self):
     with app.test_client() as c:
         rv = c.get("/projects")
         result = rv.get_json()
         self.assertIsInstance(result, list)
示例#29
0
    def test_update_experiment(self):
        with app.test_client() as c:
            rv = c.patch(f"/projects/foo/experiments/{EXPERIMENT_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}/experiments/foo", 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.patch(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}",
                         json={
                             "unk": "bar",
                         })
            result = rv.get_json()
            self.assertEqual(rv.status_code, 400)

            rv = c.patch(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}",
                         json={
                             "name": "bar",
                         })
            result = rv.get_json()
            expected = {
                "uuid": EXPERIMENT_ID,
                "name": "bar",
                "projectId": PROJECT_ID,
                "dataset": DATASET,
                "target": TARGET,
                "position": POSITION,
                "isActive": IS_ACTIVE,
                "operators": OPERATORS,
                "createdAt": CREATED_AT_ISO,
            }
            machine_generated = ["updatedAt"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)

            rv = c.patch(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}",
                         json={
                             "templateId": "unk",
                         })
            result = rv.get_json()
            expected = {"message": "The specified template does not exist"}
            self.assertDictEqual(expected, result)
            self.assertEqual(rv.status_code, 400)

            rv = c.patch(f"/projects/{PROJECT_ID}/experiments/{EXPERIMENT_ID}",
                         json={
                             "templateId": TEMPLATE_ID,
                         })
            result = rv.get_json()
            expected = {
                "uuid": EXPERIMENT_ID,
                "name": "bar",
                "projectId": PROJECT_ID,
                "dataset": DATASET,
                "target": TARGET,
                "position": POSITION,
                "isActive": IS_ACTIVE,
                "createdAt": CREATED_AT_ISO,
            }
            result_operators = result["operators"]
            machine_generated = ["updatedAt", "operators"]
            for attr in machine_generated:
                self.assertIn(attr, result)
                del result[attr]
            self.assertDictEqual(expected, result)
            expected = [{
                "componentId": COMPONENT_ID,
                "experimentId": EXPERIMENT_ID,
                "position": POSITION,
                "parameters": {},
            }]
            machine_generated = ["uuid", "createdAt", "updatedAt"]
            for attr in machine_generated:
                for operator in result_operators:
                    self.assertIn(attr, operator)
                    del operator[attr]
            self.assertListEqual(expected, result_operators)
示例#30
0
 def test_list_templates(self):
     with app.test_client() as c:
         rv = c.get("/templates")
         result = rv.get_json()
         self.assertIsInstance(result, list)