tests.test_consent

 1import pytest
 2from flask_login import current_user
 3from hanabiapp.models.user import User
 4from hanabiapp import db
 5
 6def test_get_consent(client, auth):
 7    """
 8    `/consent` ページが正常に取得できることをテストする関数.
 9
10    - ユーザーがログインしている状態で `/consent` にアクセスした際,ステータスコードが 200 であることを確認.
11    - ページ内に「実験説明」の文言が含まれていることを確認.
12    """
13    auth.login()
14    response = client.get('/consent')
15    assert response.status_code == 200
16    assert '実験説明' in response.data.decode('utf-8')
17
18def test_post_consent_agree(client, auth):
19    """
20    ユーザーが `/consent` ページで「同意する」を選択した際の動作をテストする関数.
21
22    - ユーザーがログインし,「agree」を送信すると `/home` にリダイレクトされることを確認.
23    - `current_user.consent` が `True` になっていることを確認.
24    - データベースに保存されたユーザー情報も `consent=True` で更新されていることを確認.
25    """
26    with client:
27        auth.login()
28        response = client.post(
29            '/consent',
30            data={'agree':'agree'}
31        )
32        assert response.status_code == 302
33        assert response.headers['Location'] == '/home'
34        assert current_user.consent
35        user = db.session.get(User, current_user.id)
36        assert user.consent
37
38def test_post_consent_disagree(client, auth):
39    """
40    ユーザーが `/consent` ページで「同意しない」を選択した際の動作をテストする関数.
41
42    - ユーザーがログインし,「disagree」を送信すると `/home` にリダイレクトされることを確認.
43    - `current_user.consent` が `False` であることを確認.
44    - データベースに保存されたユーザー情報も `consent=False` で更新されていることを確認.
45    """
46    with client:
47        auth.login()
48        response = client.post(
49            '/consent',
50            data={'disagree':'disagree'}
51        )
52        assert response.status_code == 302
53        assert response.headers['Location'] == '/home'
54        assert not current_user.consent
55        user = db.session.get(User, current_user.id)
56        assert not user.consent
def test_post_consent_agree(client, auth):
19def test_post_consent_agree(client, auth):
20    """
21    ユーザーが `/consent` ページで「同意する」を選択した際の動作をテストする関数.
22
23    - ユーザーがログインし,「agree」を送信すると `/home` にリダイレクトされることを確認.
24    - `current_user.consent` が `True` になっていることを確認.
25    - データベースに保存されたユーザー情報も `consent=True` で更新されていることを確認.
26    """
27    with client:
28        auth.login()
29        response = client.post(
30            '/consent',
31            data={'agree':'agree'}
32        )
33        assert response.status_code == 302
34        assert response.headers['Location'] == '/home'
35        assert current_user.consent
36        user = db.session.get(User, current_user.id)
37        assert user.consent

ユーザーが /consent ページで「同意する」を選択した際の動作をテストする関数.

  • ユーザーがログインし,「agree」を送信すると /home にリダイレクトされることを確認.
  • current_user.consentTrue になっていることを確認.
  • データベースに保存されたユーザー情報も consent=True で更新されていることを確認.
def test_post_consent_disagree(client, auth):
39def test_post_consent_disagree(client, auth):
40    """
41    ユーザーが `/consent` ページで「同意しない」を選択した際の動作をテストする関数.
42
43    - ユーザーがログインし,「disagree」を送信すると `/home` にリダイレクトされることを確認.
44    - `current_user.consent` が `False` であることを確認.
45    - データベースに保存されたユーザー情報も `consent=False` で更新されていることを確認.
46    """
47    with client:
48        auth.login()
49        response = client.post(
50            '/consent',
51            data={'disagree':'disagree'}
52        )
53        assert response.status_code == 302
54        assert response.headers['Location'] == '/home'
55        assert not current_user.consent
56        user = db.session.get(User, current_user.id)
57        assert not user.consent

ユーザーが /consent ページで「同意しない」を選択した際の動作をテストする関数.

  • ユーザーがログインし,「disagree」を送信すると /home にリダイレクトされることを確認.
  • current_user.consentFalse であることを確認.
  • データベースに保存されたユーザー情報も consent=False で更新されていることを確認.