def test_registered_reviewer_can_login(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'REVIEWING_ALLOWED', True)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
    add_new_user(registrant)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user.email == registrant['email']
    assert user.passphrase == hash_passphrase(registrant['passphrase'])
    assert user.role == Role.user
    user.role = Role.reviewer
    db.session.commit()
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        }),
        'application/json',
        includes=('login_success', ),
        excludes=(),
    )
    get_and_check_content(
        client,
        '/login_success',
        includes=(' – Login Successful', 'Login successful', logout_menu_item,
                  registration_update_menu_item),
        excludes=(login_menu_item, my_proposals_menu_item, register_menu_item,
                  submit_menu_item),
    )
Beispiel #2
0
def test_user_can_register(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        includes=('register_success', ),
        excludes=(
            login_menu_item,
            register_menu_item,
        ),
    )
    get_and_check_content(
        client,
        '/register_success',
        includes=(' – Registration Successful',
                  'You have successfully registered', login_menu_item,
                  register_menu_item),
        excludes=(logout_menu_item, my_proposals_menu_item,
                  registration_update_menu_item, submit_menu_item),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    assert user[0].email == registrant['email']
    assert user[0].passphrase == hash_passphrase(registrant['passphrase'])
Beispiel #3
0
def test_logged_in_user_cannot_submit_multipresenter_multilead_proposal(
        client, registrant, proposal_multiple_presenters_and_leads,
        monkeypatch):
    test_ensure_registration_and_login(client, registrant, monkeypatch)
    presenters = proposal_multiple_presenters_and_leads['presenters']
    post_and_check_content(
        client,
        '/submit',
        json.dumps(proposal_multiple_presenters_and_leads),
        'application/json',
        code=400,
        includes=("['{}', '{}'] marked as lead presenters".format(
            presenters[0]['email'], presenters[1]['email']), ),
        excludes=(login_menu_item, register_menu_item),
    )
    get_and_check_content(
        client,
        '/register_success',
        includes=(' – Registration Successful',
                  'You have successfully registered'),
        excludes=(),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user is not None
    assert len(user.proposals) == 0
Beispiel #4
0
def test_logged_in_user_can_submit_multipresenter_single_lead_proposal(
        client, registrant, proposal_multiple_presenters_single_lead,
        monkeypatch):
    test_ensure_registration_and_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/submit',
        json.dumps(proposal_multiple_presenters_single_lead),
        'application/json',
        includes=('submit_success', ),
        excludes=(login_menu_item, register_menu_item),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user is not None
    assert len(user.proposals) == 1
    proposal = user.proposals[0]
    assert proposal is not None
    assert proposal.session_type == SessionType.workshop
    presenters = proposal.presenters
    proposal_presenters = proposal.proposal_presenters
    assert len(presenters) == 2
    assert len(proposal_presenters) == 2
    original_presenters = proposal_multiple_presenters_single_lead[
        'presenters']
    if proposal_presenters[0].is_lead:
        assert presenters[0].email == original_presenters[0]['email']
        assert presenters[1].email == original_presenters[1]['email']
    else:
        assert presenters[0].email == original_presenters[1]['email']
        assert presenters[1].email == original_presenters[0]['email']
Beispiel #5
0
def test_ensure_registration_and_login(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        includes=('register_success', ),
        excludes=(),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    assert user[0].passphrase == hash_passphrase(registrant['passphrase'])
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        }),
        'application/json',
        includes=('login_success', ),
        excludes=(),
    )
    get_and_check_content(
        client,
        '/login_success',
        includes=(' – Login Successful', 'Login successful'),
        excludes=(),
    )
def test_logged_in_user_cannot_logout_with_form_post(client, registrant,
                                                     monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/logout',
        registrant,
        code=405,
        includes=('Method Not Allowed', ),
    )
Beispiel #7
0
def test_invalid_email(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    registrant['email'] = 'thing.flob.adob'
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        code=400,
        includes=('Validation failed for the following keys:', 'email'),
    )
Beispiel #8
0
def test_registration_update(client, registrant, monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    monkeypatch.setitem(registrant, 'name', 'Jo Bloggs')
    post_and_check_content(
        client,
        '/registration_update',
        json.dumps(registrant),
        'application/json',
        includes=('registration_update_success', ),
        excludes=(),
    )
def test_logged_in_user_cannot_logout_with_json_post(client, registrant,
                                                     monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/logout',
        json.dumps(registrant),
        'application/json',
        code=405,
        includes=('Method Not Allowed', ),
    )
Beispiel #10
0
def test_no_passphrase(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    registrant['passphrase'] = ''
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        code=400,
        includes=('No passphrase for new registration.', ),
    )
Beispiel #11
0
def test_attempted_duplicate_user_registration_fails(client, registrant,
                                                     monkeypatch):
    test_successful_user_registration(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        code=400,
        includes=('The email address is already in use.', ),
    )
Beispiel #12
0
def test_missing_passphrase_causes_login_failure(client, registrant,
                                                 monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps({'email': registrant['email']}),
        'application/json',
        code=400,
        includes=("Missing keys in registration data: ['passphrase']", ),
        excludes=(),
    )
def test_cannot_login_using_form_submission(client, registrant, monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        {
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        },
        includes=('Failure', register_menu_item),
        excludes=(login_menu_item, ),
    )
Beispiel #14
0
def test_attempted_form_submit_not_json_fails(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
    post_and_check_content(
        client,
        '/register',
        registrant,
        code=400,
        includes=('No JSON data returned', ),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
Beispiel #15
0
def test_cannot_login_using_form_submission(client, registrant, monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        {
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        },
        code=400,
        includes=('No JSON data returned.', ),
        excludes=(),
    )
def test_successful_login(client, registrant, monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        }),
        'application/json',
        includes=('Successful', ),
        excludes=(login_menu_item, register_menu_item),
    )
Beispiel #17
0
def test_attempted_registration_update_not_logged_in(client, registrant,
                                                     monkeypatch):
    test_successful_user_registration(client, registrant, monkeypatch)
    monkeypatch.setitem(registrant, 'name', 'Jo Bloggs')
    post_and_check_content(
        client,
        '/registration_update',
        json.dumps(registrant),
        'application/json',
        code=302,
        includes=('Redirecting', '<a href="/">'),
        excludes=(),
    )
Beispiel #18
0
def test_logged_in_user_can_update_a_previously_submitted_multiple_presenter_proposal(
        client, registrant, proposal_multiple_presenters_single_lead,
        monkeypatch):
    test_logged_in_user_can_submit_multipresenter_single_lead_proposal(
        client, registrant, proposal_multiple_presenters_single_lead,
        monkeypatch)
    alternate_title = 'This is an alternate title'
    alternate_email = '[email protected]'
    monkeypatch.setitem(proposal_multiple_presenters_single_lead, 'title',
                        alternate_title)
    monkeypatch.setitem(
        proposal_multiple_presenters_single_lead['presenters'][1], 'email',
        alternate_email)
    post_and_check_content(
        client,
        '/proposal_update/1',
        json.dumps(proposal_multiple_presenters_single_lead),
        'application/json',
        includes=('proposal_update_success', ),
        excludes=(login_menu_item, register_menu_item),
    )
    get_and_check_content(
        client,
        '/proposal_update_success',
        includes=('Update Successful',
                  'Thank you, you have successfully updated'),
        excludes=(login_menu_item, register_menu_item),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user is not None
    assert len(user.proposals) == 1
    proposal = user.proposals[0]
    assert proposal is not None
    assert proposal.title == alternate_title
    assert proposal.session_type == SessionType.workshop
    presenters = proposal.presenters
    proposal_presenters = proposal.proposal_presenters
    assert len(presenters) == 2
    assert len(proposal_presenters) == 2
    presenter = proposal.presenters[1]
    assert presenter.email == alternate_email
    original_presenters = proposal_multiple_presenters_single_lead[
        'presenters']
    if proposal_presenters[0].is_lead:
        assert presenters[0].email == original_presenters[0]['email']
        assert presenters[1].email == original_presenters[1]['email']
    else:
        assert presenters[0].email == original_presenters[1]['email']
        assert presenters[1].email == original_presenters[0]['email']
Beispiel #19
0
def test_malformed_email_causes_login_failure(client, registrant, monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': 'a.b.c.d',
            'passphrase': 'some words or other'
        }),
        'application/json',
        code=400,
        includes=('The email address is invalid', ),
        excludes=(),
    )
Beispiel #20
0
def test_logged_in_user_cannot_login_again(client, registrant, monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps(registrant),
        'application/json',
        code=302,
        includes=(
            'Redirect',
            '<a href="/">',
        ),
        excludes=(),
    )
def test_update_user_name(client, registrant, monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    registrant['name'] = 'Some Dude'
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        includes=('register_success_update', ),
        excludes=(
            login_menu_item,
            register_menu_item,
        ),
    )
def test_wrong_passphrase_causes_login_failure(client, registrant,
                                               monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': registrant['email'],
            'passphrase': 'Passphrase2'
        }),
        'application/json',
        includes=('Failure', 'User/passphrase not recognised.',
                  register_menu_item),
        excludes=(login_menu_item, ),
    )
def test_logged_in_reviewer_can_submit_score_for_not_own_entries(
        client, registrant, monkeypatch):
    test_logged_in_reviewer_can_get_review_proposal_for_not_own_entries(
        client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/review_proposal/1',
        json.dumps({
            'score': 7,
            'comment_for_proposer': '',
            'comment_for_committee': ''
        }),
        'application/json',
        includes=('Review stored.', ),
        excludes=(),
    )
Beispiel #24
0
def test_logged_in_user_can_update_a_previously_submitted_single_presenter_proposal(
        client, registrant, proposal_single_presenter, monkeypatch):
    test_logged_in_user_can_submit_a_single_presenter_proposal(
        client, registrant, proposal_single_presenter, monkeypatch)
    alternate_title = 'This is an alternate title'
    alternate_email = '[email protected]'
    monkeypatch.setitem(proposal_single_presenter, 'title', alternate_title)
    monkeypatch.setitem(proposal_single_presenter['presenters'][0], 'email',
                        alternate_email)
    post_and_check_content(
        client,
        '/proposal_update/1',
        json.dumps(proposal_single_presenter),
        'application/json',
        includes=('proposal_update_success', ),
        excludes=(login_menu_item, register_menu_item),
    )
    get_and_check_content(
        client,
        '/proposal_update_success',
        includes=('Update Successful',
                  'Thank you, you have successfully updated'),
        excludes=(login_menu_item, register_menu_item),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user is not None
    assert len(user.proposals) == 1
    proposal = user.proposals[0]
    assert proposal is not None
    assert proposal.title == alternate_title
    assert proposal.session_type == SessionType.quickie
    assert proposal.audience == SessionAudience.expert
    assert proposal.notes == proposal_single_presenter['notes']
    assert proposal.constraints == proposal_single_presenter['constraints']
    assert len(proposal.presenters) == 1
    presenter = proposal.presenters[0]
    assert presenter.email == alternate_email
    assert len(proposal.proposal_presenters) == 1
    p = proposal.proposal_presenters[0]
    assert p.proposal == proposal
    assert p.presenter == presenter
    assert p.is_lead
    assert len(presenter.presenter_proposals) == 1
    pp = presenter.presenter_proposals[0]
    assert p == pp
Beispiel #25
0
def test_logged_in_user_cannot_register(client, registrant, monkeypatch):
    test_successful_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/register',
        json.dumps({
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        }),
        'application/json',
        code=302,
        includes=(
            'Redirect',
            '<a href="/">',
        ),
        excludes=(),
    )
Beispiel #26
0
def test_logged_in_user_can_submit_two_proposal_with_the_sam_presenter(
        client, registrant, proposal_single_presenter, monkeypatch):
    test_logged_in_user_can_submit_a_single_presenter_proposal(
        client, registrant, proposal_single_presenter, monkeypatch)
    post_and_check_content(
        client,
        '/submit',
        json.dumps(proposal_single_presenter),
        'application/json',
        includes=('submit_success', ),
        excludes=(login_menu_item, register_menu_item),
    )
    get_and_check_content(
        client,
        '/submit_success',
        includes=('Submission Successful',
                  'Thank you, you have successfully submitted'),
        excludes=(login_menu_item, register_menu_item),
    )
def test_user_can_register(client, registrant, monkeypatch):
    monkeypatch.setitem(app.config, 'CALL_OPEN', True)
    monkeypatch.setitem(app.config, 'MAINTENANCE', False)
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 0
    post_and_check_content(
        client,
        '/register',
        json.dumps(registrant),
        'application/json',
        includes=('register_success_new', ),
        excludes=(
            login_menu_item,
            register_menu_item,
        ),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    assert user[0].email == registrant['email']
    assert user[0].passphrase == hash_passphrase(registrant['passphrase'])
Beispiel #28
0
def test_logged_in_user_can_submit_a_single_presenter_proposal(
        client, registrant, proposal_single_presenter, monkeypatch):
    test_ensure_registration_and_login(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/submit',
        json.dumps(proposal_single_presenter),
        'application/json',
        includes=('submit_success', ),
        excludes=(login_menu_item, register_menu_item),
    )
    get_and_check_content(
        client,
        '/submit_success',
        includes=('Submission Successful',
                  'Thank you, you have successfully submitted'),
        excludes=(login_menu_item, register_menu_item),
    )
    user = User.query.filter_by(email=registrant['email']).all()
    assert len(user) == 1
    user = user[0]
    assert user is not None
    assert len(user.proposals) == 1
    proposal = user.proposals[0]
    assert proposal is not None
    assert proposal.title == proposal_single_presenter['title']
    assert proposal.session_type == SessionType.quickie
    assert proposal.audience == SessionAudience.expert
    assert proposal.notes == proposal_single_presenter['notes']
    assert proposal.constraints == proposal_single_presenter['constraints']
    assert len(proposal.presenters) == 1
    presenter = proposal.presenters[0]
    assert presenter.email == user.email
    assert len(proposal.proposal_presenters) == 1
    p = proposal.proposal_presenters[0]
    assert p.proposal == proposal
    assert p.presenter == presenter
    assert p.is_lead
    assert len(presenter.presenter_proposals) == 1
    pp = presenter.presenter_proposals[0]
    assert p == pp
Beispiel #29
0
def test_successful_login(client, registrant, monkeypatch):
    test_user_can_register(client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/login',
        json.dumps({
            'email': registrant['email'],
            'passphrase': registrant['passphrase']
        }),
        'application/json',
        includes=('login_success', ),
        excludes=(),
    )
    get_and_check_content(
        client,
        '/login_success',
        includes=(' – Login Successful', 'Login successful', logout_menu_item,
                  my_proposals_menu_item, registration_update_menu_item,
                  submit_menu_item),
        excludes=(login_menu_item, register_menu_item),
    )
def test_logged_in_reviewer_can_update_a_review(client, registrant,
                                                monkeypatch):
    test_logged_in_reviewer_can_submit_score_for_not_own_entries(
        client, registrant, monkeypatch)
    post_and_check_content(
        client,
        '/review_proposal/1',
        json.dumps({
            'score': 6,
            'comment_for_proposer': 'Not up to our standard.',
            'comment_for_committee': 'rubbish.'
        }),
        'application/json',
        includes=('Review stored.', ),
        excludes=(),
    )
    get_and_check_content(
        client,
        '/review_proposal/1',
        includes=(' – Proposal to Review', ),
        excludes=(),
    )