Пример #1
0
def test_check_user_interactions(session_scope_function, output_format,
                                 expected_format):
    add_user(session_scope_function,
             name='test_user',
             password='******',
             lastname='lastname',
             firstname='firstname',
             email='*****@*****.**',
             access_level='asked')
    params = {'interaction': 'landing'}
    add_user_interaction(session_scope_function, **params)
    params = {
        'interaction': 'landing',
        'user': get_user_by_name(session_scope_function, 'test_user')
    }
    add_user_interaction(session_scope_function, **params)
    user_interaction = get_user_interactions_by_name(
        session_scope_function, output_format=output_format)
    if isinstance(user_interaction, pd.DataFrame):
        assert user_interaction.shape[0] == 2
    assert isinstance(user_interaction, expected_format)
    user_interaction = get_user_interactions_by_name(
        session_scope_function, name='test_user', output_format=output_format)
    if isinstance(user_interaction, pd.DataFrame):
        assert user_interaction.shape[0] == 1
Пример #2
0
def test_sandbox_upload_file(client_session, makedrop_event, submission_dir,
                             filename):
    client, session = client_session
    sign_up_team(session, "iris_test_4event", "test_user")

    config = ramp_config_template()
    ramp_config = generate_ramp_config(read_config(config))

    # upload file in sandbox.html
    path_submissions = os.path.join(ramp_config["ramp_kit_dir"],
                                    submission_dir)

    with login_scope(client, "test_user", "test") as client:
        rv = client.get("http://localhost/events/iris_test_4event/sandbox")
        assert rv.status_code == 200

        # choose file and check if it was uploaded correctly
        path_submission = os.path.join(path_submissions, filename)
        assert os.path.isfile(path_submission)

        rv = client.post(
            "http://localhost/events/iris_test_4event/sandbox",
            headers={
                "Referer": "http://localhost/events/iris_test_4event/sandbox"
            },
            data={"file": (open(path_submission, "rb"), filename)},
            follow_redirects=False,
        )

        assert rv.status_code == 302
        assert (
            rv.location == "http://localhost/events/iris_test_4event/sandbox")

        # code of the saved file
        with open(path_submission, "r") as file:
            submitted_data = file.read()

        # code from the db
        event = get_event(session, "iris_test_4event")
        sandbox_submission = get_submission_by_name(session,
                                                    "iris_test_4event",
                                                    "test_user",
                                                    event.ramp_sandbox_name)
        submission_code = sandbox_submission.files[-1].get_code()

        # get user interactions from db and check if 'upload' was added
        user_interactions = get_user_interactions_by_name(session, "test_user")

        # check if the code of the submitted file in the 'submission_code'
        assert submitted_data is not None
        assert submitted_data in submission_code
        # check if the user_interaction was added to the db
        assert "upload" in user_interactions["interaction"].values
Пример #3
0
def user_interactions():
    """Show the user interactions recorded on the website."""
    if flask_login.current_user.access_level != 'admin':
        return redirect_to_user(
            u'Sorry {}, you do not have admin rights'.format(
                flask_login.current_user.firstname),
            is_error=True)
    user_interactions_html = get_user_interactions_by_name(
        db.session, output_format='html')
    return render_template('user_interactions.html',
                           user_interactions_title='User interactions',
                           user_interactions=user_interactions_html)
Пример #4
0
def test_sandbox_save_file(client_session, makedrop_event):
    client, session = client_session
    sign_up_team(session, "iris_test_4event", "test_user")

    example_code = "example content"

    with login_scope(client, "test_user", "test") as client:
        rv = client.get("http://localhost/events/iris_test_4event/sandbox")
        assert rv.status_code == 200

        rv = client.post(
            "http://localhost/events/iris_test_4event/sandbox",
            headers={
                "Referer": "http://localhost/events/iris_test_4event/sandbox"
            },
            data={
                "estimator": example_code,
                "code-csrf_token": "temp_token"
            },
            follow_redirects=False,
        )
        assert rv.status_code == 200

        # code from the db
        event = get_event(session, "iris_test_4event")
        sandbox_submission = get_submission_by_name(session,
                                                    "iris_test_4event",
                                                    "test_user",
                                                    event.ramp_sandbox_name)
        submission_code = sandbox_submission.files[-1].get_code()

        # get user interactions from db and check if 'save' was added
        user_interactions = get_user_interactions_by_name(session, "test_user")

        assert "save" in user_interactions["interaction"].values
        assert example_code in submission_code

    # make sure that after changing the code example
    # and reloading the page the code is still changed
    with login_scope(client, "test_user", "test") as client:
        rv = client.get("http://localhost/events/iris_test_4event/sandbox")
        assert rv.status_code == 200
        assert example_code.encode() in rv.data
Пример #5
0
def test_sandbox_upload_file_dont_exist(client_session, makedrop_event,
                                        submission_dir, filename):
    client, session = client_session
    sign_up_team(session, "iris_test_4event", "test_user")

    config = ramp_config_template()
    ramp_config = generate_ramp_config(read_config(config))

    # upload file in sandbox.html
    path_submissions = os.path.join(ramp_config["ramp_kit_dir"], )

    with login_scope(client, "test_user", "test") as client:
        rv = client.get("http://localhost/events/iris_test_4event/sandbox")
        assert rv.status_code == 200

        # choose file and check if it was uploaded correctly
        path_submission = os.path.join(path_submissions, filename)
        assert not os.path.isfile(path_submission)

        with pytest.raises(FileNotFoundError):
            rv = client.post(
                "http://localhost/events/iris_test_4event/sandbox",
                headers={
                    "Referer":
                    "http://localhost/events/iris_test_4event/sandbox"
                },
                data={"file": (open(path_submission, "rb"), filename)},
                follow_redirects=False,
            )

        assert rv.status_code == 200

        with pytest.raises(FileNotFoundError):
            with open(path_submission, "r") as file:
                submitted_data = file.read()
                assert not submitted_data

        # get user interactions from db and check if 'upload' was added
        user_interactions = get_user_interactions_by_name(session, "test_user")
        assert "upload" not in user_interactions["interaction"].values