Exemple #1
0
def test_user_find_by_token(session, monkeypatch):  # pylint: disable=unused-argument
    """Assert that a user can be found by token."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub']
    factory_user_model(user_info=user_with_token)

    found_user = UserService.find_by_jwt_token()
    assert found_user is None

    # User accepted older version terms and conditions should return False
    patch_token_info(TestJwtClaims.user_test, monkeypatch)
    UserService.update_terms_of_use(True, 1)
    found_user = UserService.find_by_jwt_token()
    assert found_user is not None
    dictionary = found_user.as_dict()
    assert dictionary['username'] == TestJwtClaims.user_test[
        'preferred_username']
    assert dictionary['keycloak_guid'] == TestJwtClaims.user_test['sub']
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is False

    # User accepted latest version terms and conditions should return True
    UserService.update_terms_of_use(True, get_tos_latest_version())
    found_user = UserService.find_by_jwt_token()
    dictionary = found_user.as_dict()
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is True
Exemple #2
0
def test_terms_of_service_prev_version(session, monkeypatch):  # pylint: disable=unused-argument
    """Assert that a terms of use can be updated for a user."""
    patch_token_info(TestJwtClaims.user_test, monkeypatch)
    UserService.save_from_jwt_token()

    # update TOS with old version
    updated_user = UserService.update_terms_of_use(True, 1)
    dictionary = updated_user.as_dict()
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is True

    # accepted version from previous step was old.so comparison should return false
    updated_user = UserService.save_from_jwt_token()
    dictionary = updated_user.as_dict()
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is False

    # update TOS with latest version
    updated_user = UserService.update_terms_of_use(True,
                                                   get_tos_latest_version())
    dictionary = updated_user.as_dict()
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is True

    # accepted version from previous step is latest.so comparison should return true
    updated_user = UserService.save_from_jwt_token()
    dictionary = updated_user.as_dict()
    assert dictionary['user_terms']['isTermsOfUseAccepted'] is True
Exemple #3
0
def test_update_terms_of_use_for_user(session):  # pylint: disable=unused-argument
    """Assert that a terms of use can be updated for a user."""
    UserService.save_from_jwt_token(TestJwtClaims.user_test)

    updated_user = UserService.update_terms_of_use(TestJwtClaims.user_test, True, 1)
    dictionary = updated_user.as_dict()
    assert dictionary['userTerms']['isTermsOfUseAccepted'] is True