def test_get_exists_action(self, test_client):
     response = test_client.get('/path/{}/empty_dir?action=exists'.format(
         standard_user().username),
                                headers={"apiKey": standard_user().api_key})
     booleanResponse = BooleanResponseSchema().load(
         load_json_data(response)).data
     assert booleanResponse.exists is True
 def test_get_with_offset_greater_than_execution_count(
         self, test_client, number_of_executions):
     offset = 1000
     response = test_client.get('/executions?offset={}'.format(offset),
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     assert len(json_response) == 0
 def test_get_properties_action_with_dir(self, test_client, dir_object):
     response = test_client.get(
         '/path/{}/subdirectory?action=properties'.format(
             standard_user().username),
         headers={"apiKey": standard_user().api_key})
     path = PathSchema().load(load_json_data(response)).data
     assert path == dir_object
 def test_get_with_executions(self, test_client, number_of_executions):
     response = test_client.get('/executions',
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     executions, error = ExecutionSchema(many=True).load(json_response)
     assert not error
     assert len(executions) == number_of_executions
示例#5
0
 def test_get_content_action_empty(self, test_client):
     response = test_client.get('/pipelines',
                                headers={"apiKey": standard_user().api_key})
     pipeline = PipelineSchema(many=True).load(
         load_json_data(response)).data
     assert PipelineOne in pipeline
     assert PipelineTwo in pipeline
     assert PipelineThree in pipeline
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_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_get_md5_action_with_file(self, test_client):
     response = test_client.get('/path/{}/file.json?action=md5'.format(
         standard_user().username),
                                headers={"apiKey": standard_user().api_key})
     md5 = PathMD5Schema().load(load_json_data(response)).data
     assert md5 == generate_md5(
         os.path.join(app.config['DATA_DIRECTORY'],
                      "{}/file.json".format(standard_user().username)))
 def test_get_exists_action_with_invalid_file(self, test_client):
     response = test_client.get(
         '/path/{}/!invalid_F1l3?action=exists'.format(
             standard_user().username),
         headers={"apiKey": standard_user().api_key})
     booleanResponse = BooleanResponseSchema().load(
         load_json_data(response)).data
     assert booleanResponse.exists is False
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_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_get_list_action_with_dir(self, test_client):
     response = test_client.get('/path/{}/subdirectory?action=list'.format(
         standard_user().username),
                                headers={"apiKey": standard_user().api_key})
     paths = PathSchema(many=True).load(load_json_data(response)).data
     expected_paths_list = os.listdir(
         os.path.join(app.config['DATA_DIRECTORY'],
                      '{}/subdirectory'.format(standard_user().username)))
     assert len(expected_paths_list) == len(paths)
示例#13
0
 def test_get_content_action_with_study_identifier(self, test_client):
     response = test_client.get(
         '/pipelines?studyIdentifier={}'.format(NameStudyOne),
         headers={"apiKey": standard_user().api_key})
     pipeline = PipelineSchema(many=True).load(
         load_json_data(response)).data
     assert PipelineOne in pipeline
     assert PipelineTwo in pipeline
     assert PipelineThree not in pipeline
示例#14
0
 def test_get_content_action_with_property(self, test_client):
     response = test_client.get(
         '/pipelines?property={}'.format(PropNameOne),
         headers={"apiKey": standard_user().api_key})
     pipeline = PipelineSchema(many=True).load(
         load_json_data(response)).data
     assert PipelineOne in pipeline
     assert PipelineTwo not in pipeline
     assert PipelineThree in pipeline
示例#15
0
    def test_get_pipeline_boutiques_descriptor_by_identifier(
            self, test_client):
        response = test_client.get('/pipelines/{}/boutiquesdescriptor'.format(
            PipelineOne.identifier),
                                   headers={"apiKey": standard_user().api_key})
        pipeline = load_json_data(response)
        original_pipeline = json.loads(
            PipelineSchema().dumps(PipelineOne).data)

        assert pipeline == original_pipeline
示例#16
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
示例#17
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"
示例#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_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
示例#20
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
示例#23
0
 def test_get_execution(self, test_client, execution_id):
     response = test_client.get('/executions/{}'.format(execution_id),
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     execution = ExecutionSchema().load(json_response).data
     assert isinstance(execution, Execution)
示例#24
0
 def test_get_pipeline_by_identifier_no_result(self, test_client):
     response = test_client.get('/pipelines/{}'.format("NOT_{}".format(
         PipelineOne.identifier)))
     pipeline = PipelineSchema().load(load_json_data(response)).data
     assert not pipeline
示例#25
0
 def test_get_0_executions(self, test_client):
     response = test_client.get('/executions/count',
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     assert json_response == 0
 def test_get_without_executions(self, test_client):
     response = test_client.get('/executions',
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     executions = ExecutionSchema(many=True).load(json_response).data
     assert not executions
 def test_get_with_negative_limit(self, test_client, number_of_executions):
     limit = -10
     response = test_client.get('/executions?limit={}'.format(limit),
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     assert len(json_response) == number_of_executions
示例#28
0
 def test_get_content_action_with_only_property_value(self, test_client):
     response = test_client.get(
         '/pipelines?propertyValue={}'.format(PropValueOne),
         headers={"apiKey": standard_user().api_key})
     error = ErrorCodeAndMessageSchema().load(load_json_data(response)).data
     assert error == MISSING_PIPELINE_PROPERTY
 def test_get_with_invalid_offset(self, test_client, number_of_executions):
     offset = "invalid"
     response = test_client.get('/executions?offset={}'.format(offset),
                                headers={"apiKey": standard_user().api_key})
     json_response = load_json_data(response)
     assert len(json_response) == number_of_executions
示例#30
0
 def test_get_pipeline_by_identifier(self, test_client):
     response = test_client.get('/pipelines/{}'.format(
         PipelineOne.identifier),
                                headers={"apiKey": standard_user().api_key})
     pipeline = PipelineSchema().load(load_json_data(response)).data
     assert pipeline == PipelineOne