def number_of_executions(test_client, pipeline) -> int:
    number_of_executions = 10
    for _ in range(number_of_executions):
        test_client.post('/executions',
                         headers={"apiKey": standard_user().api_key},
                         data=json.dumps(ExecutionSchema().dump(
                             post_valid_execution(pipeline.identifier)).data))
    return number_of_executions
    def test_register_successful_and_login(self, test_client, test_user):
        response = test_client.post("/users/register",
                                    headers={"apiKey": admin().api_key},
                                    data=json.dumps(test_user),
                                    follow_redirects=True)
        assert response.status_code == 204

        response = test_client.post("/authenticate",
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 200
    def test_edit_password_user(self, test_client):
        response = test_client.post(
            "/users/edit",
            headers={"apiKey": standard_user().api_key},
            data=json.dumps({"password": standard_user().password + "2"}))
        assert response.status_code == 200

        response = test_client.post("/authenticate",
                                    data=json.dumps({
                                        "username":
                                        standard_user().username,
                                        "password":
                                        standard_user().password + "2"
                                    }))
        assert response.status_code == 200
 def test_post_invalid_model(self, test_client):
     response = test_client.post(
         '/executions',
         headers={"apiKey": standard_user().api_key},
         data=POST_INVALID_MODEL)
     error = error_from_response(response)
     assert error == INVALID_MODEL_PROVIDED
def post_execution_no_sleep(test_client, pipeline_no_sleep):
    execution_no_sleep = post_valid_execution(pipeline_no_sleep.identifier)
    response = test_client.post(
        '/executions',
        headers={"apiKey": standard_user().api_key},
        data=json.dumps(ExecutionSchema().dump(execution_no_sleep).data))
    json_response = load_json_data(response)
    return ExecutionSchema().load(json_response).data.identifier
 def test_post_identifier_set(self, test_client, pipeline):
     response = test_client.post(
         '/executions',
         headers={"apiKey": standard_user().api_key},
         data=json.dumps(ExecutionSchema().dump(
             post_invalid_identifier_set(pipeline.identifier)).data))
     error = error_from_response(response)
     assert error == EXECUTION_IDENTIFIER_MUST_NOT_BE_SET
 def test_register_invalid_api_key(self, test_client, test_user):
     response = test_client.post(
         "/users/register",
         headers={"apiKey": "NOT_{}".format(admin().api_key)},
         data=json.dumps(test_user),
         follow_redirects=True)
     error = ErrorCodeAndMessageSchema().load(load_json_data(response)).data
     assert error == INVALID_API_KEY
 def test_register_user_api_key(self, test_client, test_user):
     response = test_client.post(
         "/users/register",
         headers={"apiKey": standard_user().api_key},
         data=json.dumps(test_user),
         follow_redirects=True)
     error = ErrorCodeAndMessageSchema().load(load_json_data(response)).data
     assert error == UNAUTHORIZED
 def test_edit_password_no_password(self, test_client):
     response = test_client.post(
         "/users/edit",
         headers={"apiKey": standard_user().api_key},
         data=json.dumps({"password": ""}))
     error = error_from_response(response)
     INVALID_MODEL_PROVIDED.error_detail = "'password' is required"
     assert error == INVALID_MODEL_PROVIDED
 def test_register_successful(self, test_client, test_user):
     response = test_client.post("/users/register",
                                 headers={"apiKey": admin().api_key},
                                 data=json.dumps(test_user),
                                 follow_redirects=True)
     assert response.status_code == 204
     assert os.path.exists(
         os.path.join(app.config['DATA_DIRECTORY'], test_user["username"]))
def execution_id(test_client, pipeline) -> str:
    response = test_client.post('/executions',
                                headers={"apiKey": standard_user().api_key},
                                data=json.dumps(ExecutionSchema().dump(
                                    post_valid_execution(
                                        pipeline.identifier)).data))
    json_response = load_json_data(response)
    return ExecutionSchema().load(json_response).data.identifier
 def test_post_pipeline_identifier_doesnt_exist(self, test_client):
     response = test_client.post(
         '/executions',
         headers={"apiKey": standard_user().api_key},
         data=json.dumps(ExecutionSchema().dump(
             POST_INVALID_EXECUTION_IDENTIFIER_NOT_EXIST).data))
     error = error_from_response(response)
     assert error == INVALID_PIPELINE_IDENTIFIER
    def test_register_already_existing_username(self, test_client, test_user):
        response = test_client.post("/users/register",
                                    headers={"apiKey": admin().api_key},
                                    data=json.dumps(test_user),
                                    follow_redirects=True)
        assert response.status_code == 204

        response2 = test_client.post("/users/register",
                                     headers={"apiKey": admin().api_key},
                                     data=json.dumps(test_user),
                                     follow_redirects=True)
        error = ErrorCodeAndMessageSchema().load(
            load_json_data(response2)).data

        expected_error_code_and_message = copy.deepcopy(
            USERNAME_ALREADY_EXISTS)
        expected_error_code_and_message.error_message = expected_error_code_and_message.error_message.format(
            test_user["username"])
        assert error == expected_error_code_and_message
 def test_edit_password_user_other_user(self, test_client):
     response = test_client.post(
         "/users/edit",
         headers={"apiKey": standard_user().api_key},
         data=json.dumps({
             "username": standard_user_2().username,
             "password": standard_user().password + "2"
         }))
     error = error_from_response(response)
     assert error == UNAUTHORIZED
예제 #15
0
    def test_same_api_key(self, test_client, test_user):
        response = test_client.post("/authenticate",
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 200

        schema = AuthenticationSchema()
        auth_cred, errors = schema.load(load_json_data(response))
        assert not errors

        response = test_client.post("/authenticate",
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 200

        auth_cred2, errors2 = schema.load(load_json_data(response))
        assert not errors2
        assert auth_cred.http_header_value == auth_cred2.http_header_value
예제 #16
0
    def test_valid_login(self, test_client, test_user):
        response = test_client.post("/authenticate",
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 200

        schema = AuthenticationSchema()
        auth_cred, errors = schema.load(load_json_data(response))

        assert not errors
        assert auth_cred.http_header == "apiKey"
 def test_post_file_doesnt_exist(self, test_client, pipeline):
     user_execution_dir = os.path.join(app.config['DATA_DIRECTORY'],
                                       standard_user().username,
                                       'executions')
     response = test_client.post(
         '/executions',
         headers={"apiKey": standard_user().api_key},
         data=json.dumps(ExecutionSchema().dump(
             post_invalid_execution_file_not_exist(
                 pipeline.identifier)).data))
     assert not os.listdir(user_execution_dir)
     assert response.status_code == 400
예제 #18
0
    def test_invalid_password(self, test_client, test_user):
        test_user["password"] = "******".format(test_user["password"])

        response = test_client.post("/authenticate",
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 400

        schema = ErrorCodeAndMessageSchema()
        ecam, errors = schema.load(load_json_data(response))

        assert not errors
        assert ecam == INVALID_USERNAME_OR_PASSWORD
 def test_edit_password_user_not_exist(self, test_client):
     response = test_client.post("/users/edit",
                                 headers={"apiKey": admin().api_key},
                                 data=json.dumps({
                                     "username":
                                     "******",
                                     "password":
                                     standard_user().password + "2"
                                 }))
     error = error_from_response(response)
     expected_error_code_and_message = copy.deepcopy(USER_DOES_NOT_EXIST)
     expected_error_code_and_message.error_message = expected_error_code_and_message.error_message.format(
         "does_not_exist")
     assert error == expected_error_code_and_message
    def test_post_array_file_doesnt_exist(self, test_client, pipeline):
        user_execution_dir = os.path.join(app.config['DATA_DIRECTORY'],
                                          standard_user().username,
                                          'executions')
        execution = post_invalid_execution_array_file_not_exist(
            pipeline.identifier)
        response = test_client.post(
            '/executions',
            headers={"apiKey": standard_user().api_key},
            data=json.dumps(ExecutionSchema().dump(execution).data))
        error_code_and_message = error_from_response(response)

        expected_error_code_and_message = copy.deepcopy(INVALID_INPUT_FILE)
        expected_error_code_and_message.error_message = expected_error_code_and_message.error_message.format(
            *execution.input_values["input_file"])
        assert not os.listdir(user_execution_dir)
        assert error_code_and_message == expected_error_code_and_message
    def test_register_already_existing_user_folder_overwrite_folder(
            self, test_client, test_user):
        user_folder_path = os.path.join(app.config['DATA_DIRECTORY'],
                                        test_user["username"])
        os.mkdir(user_folder_path)
        with open(os.path.join(user_folder_path, "file.json"), 'w') as f:
            f.write('{"test": "json"}')

        response = test_client.post("/users/register",
                                    headers={"apiKey": admin().api_key},
                                    data=json.dumps(test_user),
                                    follow_redirects=True)

        assert response.status_code == 204

        folder_final_content = os.listdir(user_folder_path)
        assert len(folder_final_content) == 1
        assert "executions" in folder_final_content
        assert "file.json" not in folder_final_content
예제 #22
0
    def test_missing_properties(self, test_client):
        response = test_client.post("/authenticate",
                                    data=json.dumps({
                                        "notavalid": "NotAValid",
                                        "invalid": "Invalid"
                                    }),
                                    follow_redirects=True)

        assert response.status_code == 400

        schema = ErrorCodeAndMessageSchema()
        ecam, errors = schema.load(load_json_data(response))

        assert not errors
        assert ecam.error_code == INVALID_MODEL_PROVIDED.error_code
        assert ecam.error_message == INVALID_MODEL_PROVIDED.error_message
        assert len(ecam.error_detail) == 2
        assert "username" in ecam.error_detail
        assert "password" in ecam.error_detail
    def test_post_valid_execution(self, test_client, pipeline):
        user_execution_dir = os.path.join(app.config['DATA_DIRECTORY'],
                                          standard_user().username,
                                          'executions')
        response = test_client.post(
            '/executions',
            headers={"apiKey": standard_user().api_key},
            data=json.dumps(ExecutionSchema().dump(
                post_valid_execution(pipeline.identifier)).data))
        assert response.status_code == 200

        json_response = load_json_data(response)
        execution = ExecutionSchema().load(json_response).data
        execution_dir = os.path.join(user_execution_dir, execution.identifier)
        carmin_files_dir = os.path.join(execution_dir, ".carmin-files")
        assert os.path.isdir(execution_dir)
        assert os.path.isdir(carmin_files_dir)
        assert INPUTS_FILENAME in os.listdir(carmin_files_dir)
        assert DESCRIPTOR_FILENAME in os.listdir(carmin_files_dir)
 def test_register_missing_api_key(self, test_client, test_user):
     response = test_client.post("/users/register",
                                 data=json.dumps(test_user),
                                 follow_redirects=True)
     error = ErrorCodeAndMessageSchema().load(load_json_data(response)).data
     assert error == MISSING_API_KEY