Esempio n. 1
0
def test_move_files(app, default_user, _get_user_mock):
    """Test move_files view."""
    with app.test_client() as client:
        with patch(
            "reana_server.rest.workflows.current_rwc_api_client",
            make_mock_api_client("reana-workflow-controller")(),
        ):
            res = client.put(
                url_for("workflows.move_files", workflow_id_or_name="1"),
                query_string={
                    "user": default_user.id_,
                    "source": "source.txt",
                    "target": "target.txt",
                },
            )
            assert res.status_code == 403

            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = dict(key="value")
            with patch(
                "reana_server.rest.workflows.current_rwc_api_client",
                make_mock_api_client("reana-workflow-controller")(
                    mock_http_response=mock_response
                ),
            ):
                res = client.put(
                    url_for("workflows.move_files", workflow_id_or_name="1"),
                    query_string={
                        "access_token": default_user.access_token,
                        "source": "source.txt",
                        "target": "target.txt",
                    },
                )
                assert res.status_code == 200
Esempio n. 2
0
def test_get_files(app, default_user, _get_user_mock):
    """Test get_files view."""
    with app.test_client() as client:
        with patch("reana_server.rest.workflows.current_rwc_api_client",
                   make_mock_api_client("reana-workflow-controller")()):
            res = client.get(
                url_for("workflows.get_files", workflow_id_or_name="1"))
            assert res.status_code == 403

            res = client.get(
                url_for("workflows.get_files", workflow_id_or_name="1"),
                query_string={"access_token": default_user.access_token})
            assert res.status_code == 500

            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = dict(key='value')
            with patch(
                    "reana_server.rest.workflows.current_rwc_api_client",
                    make_mock_api_client("reana-workflow-controller")(
                        mock_http_response=mock_response),
            ):
                res = client.get(
                    url_for("workflows.get_files", workflow_id_or_name="1"),
                    query_string={"access_token": default_user.access_token})
                assert res.status_code == 200
Esempio n. 3
0
def test_upload_file(create_yaml_workflow_schema):
    """Test upload file."""
    status_code = 200
    reana_token = '000000'
    file = 'file.txt'
    response = [file]
    env = {'REANA_SERVER_URL': 'localhost'}
    message = 'was successfully uploaded.'
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            with runner.isolated_filesystem():
                with open(file, 'w') as f:
                    f.write('test')
                with open('reana.yaml', 'w') as reana_schema:
                    reana_schema.write(create_yaml_workflow_schema)
                result = runner.invoke(cli, [
                    'upload', '-at', reana_token, '--workflow', 'mytest.1',
                    file
                ])
                assert result.exit_code == 0
                assert message in result.output
Esempio n. 4
0
def test_get_workflows(app, default_user, _get_user_mock):
    """Test get_workflows view."""
    with app.test_client() as client:
        with patch(
            "reana_server.rest.workflows.current_rwc_api_client",
            make_mock_api_client("reana-workflow-controller")(),
        ):
            res = client.get(
                url_for("workflows.get_workflows"), query_string={"type": "batch"},
            )
            assert res.status_code == 401

            res = client.get(
                url_for("workflows.get_workflows"),
                query_string={"access_token": "wrongtoken", "type": "batch"},
            )
            assert res.status_code == 403

            res = client.get(
                url_for("workflows.get_workflows"),
                query_string={
                    "access_token": default_user.access_token,
                    "type": "batch",
                },
            )
            assert res.status_code == 200
def test_open_interactive_session(interactive_session_type):
    """Test opening an interactive session."""
    status_code = 200
    workflow_id = "d9304bdf-0d19-45d9-ae87-d5fd18059193"
    response = {"path": "/{}".format(workflow_id)}
    reana_server_url = "http://localhost"
    env = {"REANA_SERVER_URL": reana_server_url}
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            expected_message = "{reana_server_url}/{workflow_id}".format(
                reana_server_url=reana_server_url, workflow_id=workflow_id)
            result = runner.invoke(
                cli,
                [
                    "open",
                    "-t",
                    reana_token,
                    "-w",
                    workflow_id,
                    interactive_session_type,
                ],
            )
            assert expected_message in result.output
def test_create_workflow_from_json(create_yaml_workflow_schema):
    """Test create workflow from json specification."""
    status_code = 201
    response = {
        "message": "The workflow has been successfully created.",
        "workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac",
        "workflow_name": "mytest",
    }
    env = {"REANA_SERVER_URL": "localhost"}
    reana_token = "000000"
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    workflow_json = yaml.load(create_yaml_workflow_schema,
                              Loader=yaml.FullLoader)
    with patch.dict("os.environ", env):
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = create_workflow_from_json(
                workflow_json=workflow_json["workflow"],
                name=response["workflow_name"],
                access_token=reana_token,
                parameters=workflow_json["inputs"],
                workflow_engine="serial",
            )
            assert response["workflow_name"] == result["workflow_name"]
            assert response["message"] == result["message"]
def test_workflows_without_include_workspace_size():
    """Test workflows command without --include-workspace-size flag."""
    response = {
        "items": [{
            "status": "running",
            "created": "2018-06-13T09:47:35.66097",
            "user": "******",
            "name": "mytest.1",
            "id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
            "size": {
                "human_readable": "",
                "raw": -1
            },
        }]
    }
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost"}
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(cli, ["list", "-t", reana_token])
            assert result.exit_code == 0
            assert "SIZE" not in result.output
def test_workflows_sessions():
    """Test list command for getting interactive sessions."""
    response = {
        "items": [{
            "created": "2019-03-19T14:37:58",
            "id": "29136cd0-b259-4d48-8c1e-afe3572df408",
            "name": "workflow.1",
            "session_type": "jupyter",
            "session_uri": "/29136cd0-b259-4d48-8c1e-afe3572df408",
            "size": {
                "raw": 0,
                "human_readable": "0 Bytes"
            },
            "status": "created",
            "user": "******",
        }]
    }
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost", "REANA_WORKON": "mytest.1"}
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(cli,
                                   ["list", "-t", reana_token, "--sessions"])
            message = "RUN_NUMBER"
            assert result.exit_code == 0
            assert message in result.output
def test_workflows_server_ok():
    """Test workflows command when server is reachable."""
    response = [{
        "status": "running",
        "created": "2018-06-13T09:47:35.66097",
        "user": "******",
        "name": "mytest.1",
        "id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
    }]
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {'REANA_SERVER_URL': 'localhost', 'REANA_WORKON': 'mytest.1'}
    reana_token = '000000'
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = runner.invoke(cli, ['list', '-at', reana_token])
            message = 'RUN_NUMBER'
            assert result.exit_code == 0
            assert message in result.output
Esempio n. 10
0
def test_move_file_running_workflow():
    """Test move files when workflow is running."""
    status_code = 200
    reana_token = "000000"
    src_file = "file11"
    target = "file2"
    response = {"status": "running", "logs": "", "name": "mytest.1"}
    message = "File(s) could not be moved for running workflow"
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost"}
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(
                cli,
                [
                    "mv", "-t", reana_token, "--workflow", "mytest.1",
                    src_file, target
                ],
            )
            assert result.exit_code == 1
            assert message in result.output
Esempio n. 11
0
def test_delete_non_existing_file():
    """Test delete non existing file."""
    status_code = 200
    reana_token = "000000"
    filename = "file11"
    response = {"deleted": {}, "failed": {}}
    message = "{} did not match any existing file.".format(filename)
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost"}
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            with runner.isolated_filesystem():
                result = runner.invoke(cli, [
                    "rm", "-t", reana_token, "--workflow", "mytest.1", filename
                ])
                assert result.exit_code == 0
                assert message in result.output
Esempio n. 12
0
def test_get_workflow_specification(app, default_user, _get_user_mock,
                                    sample_yadage_workflow_in_db):
    """Test get_workflow_specification view."""
    with app.test_client() as client:
        with patch("reana_server.rest.workflows.current_rwc_api_client",
                   make_mock_api_client("reana-workflow-controller")()):
            res = client.get(
                url_for("workflows.get_workflow_specification",
                        workflow_id_or_name="1"))
            assert res.status_code == 403

            res = client.get(
                url_for("workflows.get_workflow_specification",
                        workflow_id_or_name=sample_yadage_workflow_in_db.id_),
                headers={"Content-Type": "application/json"},
                query_string={"access_token": default_user.access_token},
                data=json.dumps(None))
            parsed_res = json.loads(res.data)
            assert res.status_code == 200
            assert parsed_res['workflow']['specification'] == \
                sample_yadage_workflow_in_db.get_specification()
            assert parsed_res['inputs']['parameters'] == \
                sample_yadage_workflow_in_db.get_input_parameters()
            assert parsed_res['workflow']['type'] == \
                sample_yadage_workflow_in_db.type_
Esempio n. 13
0
def test_download_file():
    """Test file downloading."""
    status_code = 200
    response = 'Content of file to download'
    env = {'REANA_SERVER_URL': 'localhost'}
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    reana_token = '000000'
    response_md5 = hashlib.md5(mock_response.encode('utf-8')).hexdigest()
    file = 'dummy_file.txt'
    message = 'File {0} downloaded to'.format(file)
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = runner.invoke(cli, [
                'download', '-t', reana_token, '--workflow', 'mytest.1', file
            ])
            assert result.exit_code == 0
            assert os.path.isfile(file) is True
            file_md5 = hashlib.md5(open(file, 'rb').read()).hexdigest()
            assert file_md5 == response_md5
            assert message in result.output
            os.remove(file)
Esempio n. 14
0
def test_move_file_running_workflow():
    """Test move files when workflow is running."""
    status_code = 200
    reana_token = '000000'
    src_file = 'file11'
    target = 'file2'
    response = {"status": "running", "logs": "", "name": "mytest.1"}
    message = 'File(s) could not be moved for running workflow'
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    env = {'REANA_SERVER_URL': 'localhost'}
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = runner.invoke(cli, [
                'mv', '-t', reana_token, '--workflow', 'mytest.1', src_file,
                target
            ])
            assert result.exit_code == 1
            assert message in result.output
Esempio n. 15
0
def test_download_file(app, default_user):
    """Test download_file view."""
    with app.test_client() as client:
        with patch(
                "reana_server.rest.workflows.current_rwc_api_client",
                make_mock_api_client("reana-workflow-controller")(),
        ):
            res = client.get(
                url_for("workflows.download_file",
                        workflow_id_or_name="1",
                        file_name="test_download"),
                query_string={
                    "user_id": default_user.id_,
                    "file_name": "test_upload.txt"
                },
            )
            assert res.status_code == 302

            res = client.get(
                url_for("workflows.download_file",
                        workflow_id_or_name="1",
                        file_name="test_download"),
                query_string={"access_token": default_user.access_token},
            )
            assert res.status_code == 200
Esempio n. 16
0
def test_create_workflow_from_json(create_yaml_workflow_schema):
    """Test create workflow from json specification."""
    status_code = 201
    response = {
        "message": "The workflow has been successfully created.",
        "workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac",
        "workflow_name": "mytest.1"
    }
    env = {'REANA_SERVER_URL': 'localhost'}
    reana_token = '000000'
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    workflow_json = yaml.load(create_yaml_workflow_schema,
                              Loader=yaml.FullLoader)
    with patch.dict('os.environ', env):
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = create_workflow_from_json(
                workflow_json=workflow_json['workflow'],
                name=response['workflow_name'],
                access_token=reana_token,
                parameters=workflow_json['inputs'],
                workflow_engine='serial')
            assert response['workflow_name'] == result['workflow_name']
            assert response['message'] == result['message']
Esempio n. 17
0
def test_workflow_input_parameters():
    """Test if not existing input parameters from CLI are applied."""
    status_code = 200
    response = {
        'id': 'd9304bdf-0d19-45d9-ae87-d5fd18059193',
        'name': 'workflow.19',
        'type': 'serial',
        'parameters': {
            'helloworld': 'code/helloworld.py',
            'inputfile': 'data/names.txt',
            'outputfile': 'results/greetings.txt',
            'sleeptime': 2
        }
    }
    env = {'REANA_SERVER_URL': 'localhost'}
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    reana_token = '000000'
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            parameter = "Debug"
            expected_message = '{0}, is not in reana.yaml'.format(parameter)
            result = runner.invoke(cli, [
                'start', '-at', reana_token, '-w workflow.19',
                '-p {0}=True'.format(parameter)
            ])
            assert expected_message in result.output
Esempio n. 18
0
def test_list_disk_usage_with_invalid_filter():
    """Test list disk usage info with invalid filter."""
    status_code = 200
    response = {
        "disk_usage_info": [],
        "user": "******",
        "workflow_id": "7767678-766787",
        "workflow_name": "workflow",
    }
    env = {"REANA_SERVER_URL": "localhost"}
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(
                cli,
                [
                    "du",
                    "-t",
                    reana_token,
                    "--workflow",
                    "workflow.1",
                    "--filter",
                    "name=not_valid",
                ],
            )
            assert result.exit_code == 1
            assert "No files matching filter criteria." in result.output
Esempio n. 19
0
def test_workflows_sessions():
    """Test list command for getting interactive sessions."""
    response = [{
        'created': '2019-03-19T14:37:58',
        'id': '29136cd0-b259-4d48-8c1e-afe3572df408',
        'name': 'workflow.1',
        'session_type': 'jupyter',
        'session_uri': '/29136cd0-b259-4d48-8c1e-afe3572df408',
        'size': '0',
        'status': 'created',
        'user': '******'
    }]
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {'REANA_SERVER_URL': 'localhost', 'REANA_WORKON': 'mytest.1'}
    reana_token = '000000'
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = runner.invoke(cli,
                                   ['list', '-at', reana_token, '--sessions'])
            message = 'RUN_NUMBER'
            assert result.exit_code == 0
            assert message in result.output
Esempio n. 20
0
def test_list_files_ok():
    """Test list workflow workspace files successfull."""
    status_code = 200
    response = {
        "items": [{
            "last-modified": "string",
            "name": "string",
            "size": {
                "raw": 0,
                "human_readable": "0 Bytes"
            },
        }]
    }
    env = {"REANA_SERVER_URL": "localhost"}
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(
                cli,
                ["ls", "-t", reana_token, "--workflow", "mytest.1", "--json"])
            json_response = json.loads(result.output)
            assert result.exit_code == 0
            assert isinstance(json_response, list)
            assert len(json_response) == 1
            assert json_response[0]["name"] in response["items"][0]["name"]
Esempio n. 21
0
def test_workflows_valid_json():
    """Test workflows command with --json and -v flags."""
    response = {
        "items": [{
            "status": "running",
            "created": "2018-06-13T09:47:35.66097",
            "user": "******",
            "name": "mytest.1",
            "id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
            "size": {
                "raw": 0,
                "human_readable": "0 Bytes"
            },
        }]
    }
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost"}
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(cli,
                                   ["list", "-v", "-t", reana_token, "--json"])
            assert result.exit_code == 0
Esempio n. 22
0
def test_list_files_url():
    """Test list workflow workspace files' urls."""
    status_code = 200
    response = {
        "items": [{
            "last-modified": "string",
            "name": "string",
            "size": {
                "raw": 0,
                "human_readable": "0 Bytes"
            },
        }]
    }
    env = {"REANA_SERVER_URL": "localhost"}
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    workflow_name = "mytest"
    reana_token = "000000"
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(cli, [
                "ls", "-t", reana_token, "--workflow", workflow_name, "--url"
            ])
            assert result.exit_code == 0
            assert workflow_name in result.output
            assert response["items"][0]["name"] in result.output
Esempio n. 23
0
def test_workflow_create_successful(create_yaml_workflow_schema):
    """Test workflow create when creation is successfull."""
    status_code = 201
    response = {
        "message": "The workflow has been successfully created.",
        "workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac",
        "workflow_name": "mytest.1",
    }
    env = {"REANA_SERVER_URL": "localhost"}
    reana_token = "000000"
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            with runner.isolated_filesystem():
                with open("reana.yaml", "w") as f:
                    f.write(create_yaml_workflow_schema)
                result = runner.invoke(
                    cli, ["create", "-t", reana_token, "--skip-validation"])
                assert result.exit_code == 0
                assert response["workflow_name"] in result.output
Esempio n. 24
0
def test_secrets_add(secret):
    """Test secrets add."""
    status_code = 201
    reana_token = '000000'
    secret_file = 'file.txt'
    response = [secret_file]
    env = {'REANA_SERVER_URL': 'localhost'}
    message = 'were successfully uploaded.'
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            with runner.isolated_filesystem():
                with open(secret_file, 'w') as f:
                    f.write('test')
                result = runner.invoke(cli, [
                    'secrets-add', '-t', reana_token, '--file', secret_file,
                    '--env', secret
                ])
                assert result.exit_code == 0
                assert message in result.output
Esempio n. 25
0
def test_workflow_start_successful(status):
    """Test workflow start when creation is successfull."""
    workflow_name = "mytest.1"
    response = {
        "status": status,
        "message": "Server message",
        "id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
        "workflow_name": workflow_name,
        "user": "******",
    }
    status_code = 200
    reana_token = "000000"
    expected_message = get_workflow_status_change_msg(workflow_name, status)
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {"REANA_SERVER_URL": "localhost"}
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client("reana-server")(mock_response,
                                                     mock_http_response),
        ):
            result = runner.invoke(
                cli,
                ["start", "-t", reana_token, "-w", response["workflow_name"]])
            assert result.exit_code == 0
            assert expected_message in result.output
Esempio n. 26
0
def test_delete_file(app, default_user, _get_user_mock):
    """Test delete_file view."""
    mock_response = Mock()
    mock_response.headers = {"Content-Type": "multipart/form-data"}
    mock_response.json = Mock(return_value={})
    mock_response.status_code = 200
    with app.test_client() as client:
        with patch(
            "reana_server.rest.workflows.current_rwc_api_client",
            make_mock_api_client("reana-workflow-controller")(
                mock_http_response=mock_response
            ),
        ):
            res = client.delete(
                url_for(
                    "workflows.delete_file",
                    workflow_id_or_name="1",
                    file_name="test_delete.txt",
                )
            )
            assert res.status_code == 403

            res = client.delete(
                url_for(
                    "workflows.delete_file",
                    workflow_id_or_name="1",
                    file_name="test_delete.txt",
                ),
                query_string={"access_token": default_user.access_token},
            )
            assert res.status_code == 200
Esempio n. 27
0
def test_set_workflow_status(app, default_user, _get_user_mock):
    """Test get_workflow_logs view."""
    with app.test_client() as client:
        with patch(
            "reana_server.rest.workflows.current_rwc_api_client",
            make_mock_api_client("reana-workflow-controller")(),
        ):
            res = client.put(
                url_for("workflows.set_workflow_status", workflow_id_or_name="1")
            )
            assert res.status_code == 401

            res = client.put(
                url_for("workflows.set_workflow_status", workflow_id_or_name="1"),
                query_string={"access_token": "wrongtoken"},
            )
            assert res.status_code == 403

            res = client.put(
                url_for("workflows.set_workflow_status", workflow_id_or_name="1"),
                headers={"Content-Type": "application/json"},
                query_string={"access_token": default_user.access_token},
            )
            assert res.status_code == 500

            res = client.put(
                url_for("workflows.set_workflow_status", workflow_id_or_name="1"),
                headers={"Content-Type": "application/json"},
                query_string={
                    "access_token": default_user.access_token,
                    "status": "stop",
                },
                data=json.dumps(dict(parameters=None)),
            )
            assert res.status_code == 200
Esempio n. 28
0
def test_workflows_valid_json():
    """Test workflows command with --json and -v flags."""
    response = [{
        "status": "running",
        "created": "2018-06-13T09:47:35.66097",
        "user": "******",
        "name": "mytest.1",
        "id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
        "size": "0K"
    }]
    status_code = 200
    mock_http_response, mock_response = Mock(), Mock()
    mock_http_response.status_code = status_code
    mock_response = response
    env = {'REANA_SERVER_URL': 'localhost'}
    reana_token = '000000'
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            result = runner.invoke(
                cli, ['list', '-v', '-at', reana_token, '--json'])
            json_response = json.loads(result.output)
            assert result.exit_code == 0
            assert isinstance(json_response, list)
            assert len(json_response) == 1
            assert 'name' in json_response[0]
            assert 'run_number' in json_response[0]
            assert 'created' in json_response[0]
            assert 'status' in json_response[0]
            assert 'id' in json_response[0]
            assert 'user' in json_response[0]
Esempio n. 29
0
def test_secrets_add(secret):
    """Test secrets add."""
    status_code = 201
    reana_token = "000000"
    secret_file = "file.txt"
    response = [secret_file]
    env = {"REANA_SERVER_URL": "localhost"}
    message = "were successfully uploaded."
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
            "reana_client.api.client.current_rs_api_client",
            make_mock_api_client("reana-server")(mock_response, mock_http_response),
        ):
            with runner.isolated_filesystem():
                with open(secret_file, "w") as f:
                    f.write("test")
                result = runner.invoke(
                    cli,
                    [
                        "secrets-add",
                        "-t",
                        reana_token,
                        "--file",
                        secret_file,
                        "--env",
                        secret,
                    ],
                )
                assert result.exit_code == 0
                assert message in result.output
Esempio n. 30
0
def test_delete_non_existing_file():
    """Test delete non existing file."""
    status_code = 200
    reana_token = '000000'
    filename = 'file11'
    response = {'deleted': {}, 'failed': {}}
    message = '{} did not match any existing file.'.format(filename)
    mock_http_response = Mock()
    mock_http_response.status_code = status_code
    mock_http_response.raw_bytes = str(response).encode()
    mock_response = response
    env = {'REANA_SERVER_URL': 'localhost'}
    runner = CliRunner(env=env)
    with runner.isolation():
        with patch(
                "reana_client.api.client.current_rs_api_client",
                make_mock_api_client('reana-server')(mock_response,
                                                     mock_http_response)):
            with runner.isolated_filesystem():
                result = runner.invoke(cli, [
                    'rm', '-at', reana_token, '--workflow', 'mytest.1',
                    filename
                ])
                assert result.exit_code == 0
                assert message in result.output