예제 #1
0
def test_post_upload_list(db, client, token):
    """
    Test uploading a report.
    """
    count_1 = db.session.query(models.Upload).count()

    rv = client.post(
        "/rest_api/v1/uploads",
        data={"report": resource_stream("tests", "multiqc_data.json")},
        headers={
            "access_token": token,
            "Content-Type": "multipart/form-data",
            "Accept": "application/json",
        },
    )

    # Check the request was successful
    assert rv.status_code == 201, rv.json

    # Validate the response
    schemas.UploadSchema().validate(rv.json)

    # Check that there is a new Upload
    count_2 = db.session.query(models.Upload).count()
    assert count_2 == count_1 + 1
예제 #2
0
def test_post_upload_list(db, client, token):
    """
    Test uploading a report
    """
    count_1 = db.session.query(models.Upload).count()

    rv = client.post(
        '/rest_api/v1/uploads',
        data={'report': resource_stream('tests', 'multiqc_data.json')},
        headers={
            'access_token': token,
            'Content-Type': 'multipart/form-data',
            'Accept': 'application/json'
        }
    )

    # Check the request was successful
    assert rv.status_code == 201, rv.json

    # Validate the response
    schemas.UploadSchema().validate(rv.json)

    # Check that there is a new Upload
    count_2 = db.session.query(models.Upload).count()
    assert count_2 == count_1 + 1
예제 #3
0
파일: views.py 프로젝트: pythseq/MegaQC
    def post(self, **kwargs):
        """
        Upload a new report.
        """
        # This doesn't exactly follow the JSON API spec, since it doesn't exactly support file uploads:
        # https://github.com/json-api/json-api/issues/246
        file_name = utils.get_unique_filename()
        request.files["report"].save(file_name)
        upload_row = models.Upload.create(
            status="NOT TREATED",
            path=file_name,
            message="File has been created, loading in MegaQC is queued.",
            user_id=kwargs["user"].user_id,
        )

        return schemas.UploadSchema(
            many=False).dump(upload_row), HTTPStatus.CREATED