Exemplo n.º 1
0
def test_duplicate_login(client):
    # New test request contexts so we don't try two
    # logins under the same session.
    with startup.get_app().test_request_context():
        res = client.post('/login',
                          data={"username": "******"},
                          follow_redirects=True)

    with startup.get_app().test_request_context():
        res = client.post('/login',
                          data={"username": "******"},
                          follow_redirects=True)

    assert b'already in use' in res.data
Exemplo n.º 2
0
def test_submit_answer_not_all_answered(client):
    # Borrowing from the first test. It sets up
    # three players, one of which hasn't answered.
    # This is exactly what we need for this test too.
    run_db_script("test_get_answers.sql")
    with client.session_transaction() as test_session:
        test_session['username'] = "******"

    res = client.post('/submit-answer',
                      data={"answer": "THIS IS A TEST"},
                      follow_redirects=True)

    with startup.get_app().app_context():
        recs = cah.db.get_db().execute(
            "SELECT name, answer FROM players").fetchall()

    # Check in both the db and the response data
    # since we don't render from db information
    [ player_2_answer ] = [ x['answer'] for x in recs \
                            if x['name'] == "player 2"]

    assert "A TEST" in player_2_answer
    assert b"A TEST" in res.data

    # Check that we didn't modify db in an incorrect manner
    [ player_3_rec ] = [ x['answer'] for x in recs  \
                         if x['name'] == "player 3" ]

    assert None == player_3_rec
Exemplo n.º 3
0
def test_invalid_login(client):
    # Input: Request with invalid chars for login.

    # Output: Login request with error message.
    res = client.post('/login',
                      data={"username": "******"},
                      follow_redirects=True)

    assert b'try again using' in res.data
Exemplo n.º 4
0
def test_blank_login(client):
    # Input: Request with empty string for login.
    #        (Cannot be done through frontend web pages,
    #         could potentially be stimulated via curl, etc.

    # Output: Login request with error message.
    res = client.post('/login', data={"username": ""}, follow_redirects=True)

    assert b'try again using' in res.data
Exemplo n.º 5
0
def test_good_login(client):
    # Input: Valid login request
    # Output: Lobby page with new player
    res = client.post('/login',
                      data={"username": "******"},
                      follow_redirects=True)

    # Check that the given username was correctly rendered
    # and sent to the client.
    # Not particularly thorough, but good enough.
    assert b'not a real person' in res.data
Exemplo n.º 6
0
def test_select_winner(client):
  run_db_script("test_select_winner.sql")
  
  with client.session_transaction() as test_session:
    test_session['username'] = '******' # Set to judge in sql file

  res = client.post('/select-winner',
              data = {"answer-button":"Player 1 answer"},
              follow_redirects = True)
  assert b'<td> player 1 </td>' in res.data
  assert b'<td> 7 </td>' in res.data
Exemplo n.º 7
0
def test_ready(client):

    run_db_script("test_ready.sql")

    with client.session_transaction() as test_session:
        test_session['username'] = '******'

    res = client.post('/submit-ready', follow_redirects=True)
    assert b'asdf is ready' in res.data

    with startup.get_app().app_context():

        # Check ready and answer flags are properly set
        rec = cah.db.get_db().execute("SELECT ready, answer FROM players"
                                      " WHERE name = 'asdf'").fetchone()
        assert rec['ready'] == 1
        assert rec['answer'] == None
Exemplo n.º 8
0
def test_ready_with_updates(client):
    # Similar to the test above, but all playrs will be ready
    # once the post is sent, so the judge and question should
    # be updated.
    run_db_script("test_ready_with_updates.sql")

    # Get all information before our post switches to
    # a new round, which involves a lot of changes to
    # the database.
    initial_judge = ""
    initial_question = ""
    inital_player_recs = []
    with startup.get_app().app_context():

        initial_judge = cah.db.get_db().execute(
            'SELECT name FROM players'
            ' WHERE judge = 1').fetchone()['name']

        initial_question = cah.db.get_db().execute(
            'SELECT question FROM current_question').fetchone()['question']
        with client.session_transaction() as test_session:
            test_session['username'] = "******"

        res = client.post('/submit-ready', follow_redirects=True)
        assert b'asdf is ready' in res.data

        # Check ready and answer flags are properly set
        rec = cah.db.get_db().execute("SELECT ready, answer FROM players"
                                      " WHERE name = 'asdf'").fetchone()
        assert rec['ready'] == 1
        assert rec['answer'] == None

        # Check that the question has changed.
        new_question = cah.db.get_db().execute(
            "SELECT question FROM current_question").fetchone()['question']

        assert new_question != initial_question

        # Check that the judge has changed.
        new_judge = cah.db.get_db().execute(
            "SELECT name FROM players"
            " WHERE judge = 1").fetchone()['name']

        assert new_judge != initial_judge
Exemplo n.º 9
0
def test_bad_session_ready(client):
    res = client.post('/submit-ready', follow_redirects=True)

    assert b"You don't exist!" in res.data