コード例 #1
0
def test__upload__upload_FileField(client, faker, required, allowed_file_extensions, file_sent, extension, should_be_loaded):
    user = login(client, faker)
    study = faker.get_test_study(collaborator=user)

    field = faker.get_test_field(field_group=study.field_group, field_type=FieldType.get_file(), allowed_file_extensions=allowed_file_extensions, required=required)

    content = faker.text()
    filename = faker.file_name(extension=extension)

    resp = _do_upload(
        client,
        faker,
        study.id,
        field_name=field.field_name,
        field_value=(
            BytesIO(content.encode('utf-8')),
            filename
        ),
    )

    if should_be_loaded:
        assert__redirect(resp, endpoint='ui.index')

        _assert_uploaded_file(study, field, filename=filename, content=content)

    else:
        assert resp.status_code == status.HTTP_200_OK

        assert__error__message(resp.soup, field.field_name)
        _assert_upload_not_saved(study)
コード例 #2
0
def test__ui_unblinding__not_existing(client, faker):
    user = login(client, faker)

    b = faker.get_test_blinding_with_owner(owner=user)

    resp = _unblinding_post(client, b.blinding_type.blinding_set, '1234567')

    assert resp.status_code == 200
    assert__error__message(resp.soup, 'Blind ID "1234567" not found for study')
コード例 #3
0
def test__ui_unblinding__existing(client, faker):
    user = login(client, faker)

    b = faker.get_test_blinding_with_owner(owner=user)

    resp = _unblinding_post(client, b.blinding_type.blinding_set,
                            b.pseudo_random_id.full_code)

    assert resp.status_code == 200
    assert__error__message(resp.soup, f'is unblinded to "{b.unblind_id}"')
コード例 #4
0
def _do_upload_field(client, faker, study, should_be_loaded, field, value):
    resp = _do_upload(client, faker, study.id, field_name=field.field_name, field_value=value)

    if should_be_loaded:
        assert__redirect(resp, endpoint='ui.index')

        _assert_uploaded(study, field, value=value)
    else:
        assert resp.status_code == status.HTTP_200_OK

        assert__error__message(resp.soup, field.field_name)
        _assert_upload_not_saved(study)
コード例 #5
0
def test__upload__upload_BooleanField(client, faker, required, value, should_be_loaded, saved_value):
    user = login(client, faker)
    study = faker.get_test_study(collaborator=user)

    field = faker.get_test_field(field_group=study.field_group, field_type=FieldType.get_boolean(), required=required)

    resp = _do_upload(client, faker, study.id, field_name=field.field_name, field_value=value)

    if should_be_loaded:
        assert__redirect(resp, endpoint='ui.index')

        _assert_uploaded(study, field, value=saved_value)
    else:
        assert resp.status_code == status.HTTP_200_OK

        assert__error__message(resp.soup, field.field_name)
        _assert_upload_not_saved(study)