def test_put_without_content_creates_directory(self, test_client):
     dir_to_create = '{}/new_directory'.format(standard_user().username)
     response = test_client.put('/path/{}'.format(dir_to_create),
                                headers={"apiKey": standard_user().api_key})
     new_dir_path = os.path.join(app.config['DATA_DIRECTORY'],
                                 dir_to_create)
     assert os.path.isdir(new_dir_path)
Exemplo n.º 2
0
 def test_put_illegal_parameter_identifier(self, test_client, execution_id):
     response = test_client.put('/executions/{}'.format(execution_id),
                                headers={"apiKey": standard_user().api_key},
                                data=json.dumps(PATCH_ILLEGAL_PARAMETER2))
     error = error_from_response(response)
     expected_error_code_and_message = copy.deepcopy(error)
     expected_error_code_and_message.error_message = error.error_message.format(
         "identifier")
     assert error == expected_error_code_and_message
    def test_put_file_raw(self, test_client):
        path = '{}/test_file_raw.txt'.format(standard_user().username)
        file_content = "This is a test raw file"
        response = test_client.put('/path/{}'.format(path),
                                   headers={"apiKey": standard_user().api_key},
                                   data=file_content)
        assert response.status_code == 201

        file_path = os.path.join(app.config['DATA_DIRECTORY'], path)
        with open(file_path) as f:
            assert f.read() == file_content
 def test_put_base64_dir(self, test_client, put_dir):
     path = '{}/empty_dir'.format(standard_user().username)
     abs_path = os.path.join(app.config['DATA_DIRECTORY'], path)
     response = test_client.put(
         '/path/{}'.format(path),
         headers={
             "apiKey": standard_user().api_key,
             "Content-Type": "application/carmin+json"
         },
         data=json.dumps(UploadDataSchema().dump(put_dir).data))
     assert response.status_code == 201 and os.listdir(abs_path)
 def test_put_base64_file(self, test_client, put_file):
     file_name = '{}/put_file.txt'.format(standard_user().username)
     response = test_client.put(
         '/path/{}'.format(file_name),
         headers={
             "apiKey": standard_user().api_key,
             "Content-Type": "application/carmin+json"
         },
         data=json.dumps(UploadDataSchema().dump(put_file).data))
     assert os.path.exists(
         os.path.join(app.config['DATA_DIRECTORY'], file_name))
Exemplo n.º 6
0
    def test_put_valid_execution_name(self, test_client, session,
                                      execution_id):
        response = test_client.put('/executions/{}'.format(execution_id),
                                   headers={"apiKey": standard_user().api_key},
                                   data=json.dumps(PATCH_VALID_EXECUTION2))
        assert response.status_code == 204

        execution = session.query(ExecutionDB).filter_by(
            identifier=execution_id).first()
        execution, _ = get_execution_as_model(standard_user().username,
                                              execution)
        assert execution.name == PATCH_VALID_EXECUTION2["name"]
Exemplo n.º 7
0
    def test_put_parameter_no_change(self, test_client, session, execution_id):
        response = test_client.put('/executions/{}'.format(execution_id),
                                   headers={"apiKey": standard_user().api_key},
                                   data=json.dumps(PATCH_NO_CHANGE_PARAMETER))
        assert response.status_code == 204

        execution = session.query(ExecutionDB).filter_by(
            identifier=execution_id).first()
        execution, _ = get_execution_as_model(standard_user().username,
                                              execution)
        assert (execution.pipeline_identifier !=
                PATCH_NO_CHANGE_PARAMETER["pipelineIdentifier"])
 def test_put_with_invalid_upload_type(self, test_client):
     response = test_client.put(
         '/path/{}/new_file.txt'.format(standard_user().username),
         headers={
             "apiKey": standard_user().api_key,
             "Content-Type": "application/carmin+json"
         },
         data='{"type": "Invented", "base64Content": "ewlfkjweflk=="}')
     error = error_from_response(response)
     assert error.error_code == INVALID_MODEL_PROVIDED.error_code
     assert error.error_message == INVALID_MODEL_PROVIDED.error_message
     assert len(error.error_detail) == 1
     assert "type" in error.error_detail
 def test_put_base64_invalid_dir(self, test_client):
     path = '{}/empty_dir2'.format(standard_user().username)
     abs_path = os.path.join(app.config['DATA_DIRECTORY'], path)
     put_dir = UploadData(base64_content='bad_content',
                          upload_type='Archive',
                          md5='')
     response = test_client.put(
         '/path/{}'.format(path),
         headers={
             "apiKey": standard_user().api_key,
             "Content-Type": "application/carmin+json"
         },
         data=json.dumps(UploadDataSchema().dump(put_dir).data))
     assert response.status_code == 400
 def test_put_file_on_dir(self, test_client):
     path = '{}/empty_dir'.format(standard_user().username)
     put_dir = UploadData(base64_content='bad_content',
                          upload_type='File',
                          md5='')
     response = test_client.put(
         '/path/{}'.format(path),
         headers={
             "apiKey": standard_user().api_key,
             "Content-Type": "application/carmin+json"
         },
         data=json.dumps(UploadDataSchema().dump(put_dir).data))
     error = error_from_response(response)
     assert error.error_message == "Invalid path: '{}' is a directory.".format(
         path)
    def test_put_execution_play_fast(self, test_client, test_config,
                                     post_execution_no_sleep):
        response = test_client.get('/executions',
                                   headers={"apiKey": standard_user().api_key})
        response = test_client.put(
            '/executions/{}/play'.format(post_execution_no_sleep),
            headers={
                "apiKey": standard_user().api_key,
            })
        assert response.status_code == 204

        output_path = os.path.join(app.config['DATA_DIRECTORY'],
                                   standard_user().username, 'executions',
                                   post_execution_no_sleep, 'greeting.txt')
        assert os.path.exists(output_path)

        with open(output_path) as f:
            assert f.read() == 'Welcome to CARMIN-Server, Jane Doe.\n'
Exemplo n.º 12
0
 def test_put_invalid_parameter(self, test_client, execution_id):
     response = test_client.put('/executions/{}'.format(execution_id),
                                headers={"apiKey": standard_user().api_key},
                                data=json.dumps(PATCH_INVALID_PARAMETER))
     assert response.status_code == 400
 def test_put_dir_already_exists(self, test_client):
     dir_to_create = "{}/subdirectory".format(standard_user().username)
     response = test_client.put('/path/{}'.format(dir_to_create),
                                headers={"apiKey": standard_user().api_key})
     error = error_from_response(response)
     assert error == PATH_EXISTS
 def test_put_where_parent_dir_not_exist(self, test_client):
     response = test_client.put('/path/{}/made_up_dir/file.txt'.format(
         standard_user().username),
                                headers={"apiKey": standard_user().api_key})
     error = error_from_response(response)
     assert error == INVALID_PATH
 def test_put_outside_authorized_directory(self, test_client):
     response = test_client.put('/path/../../test_file',
                                headers={"apiKey": standard_user().api_key})
     error = error_from_response(response)
     assert error == INVALID_PATH