Exemple #1
0
def test_query_invitation_using_token(default_header, test_record_settings):
    # we invite the admin user
    # GIVEN
    invitee_email = test_record_settings('users.4.email')
    input = {'invitationType': 'USER', 'inviteeEmail': invitee_email}
    # invite the user as default_user:
    execute_gql_mutation(CREATE_INVITATION_MUTATION,
                         _headers=default_header,
                         **input)
    _, token = extract_invitation_link_and_token(get_emails()[0]['body'])

    # WHEN
    hubert_header = authenticated_header(
        login(invitee_email, test_record_settings('users.1.password')))
    result = execute_gql(QUERY_INVITATION_BY_TOKEN,
                         headers=hubert_header,
                         variables={'token': token})
    invitation = result['data']['invitation']

    # THEN
    assert invitation is not None
    assert invitation['state'] == STATE_PENDING
    assert invitation['inviteeEmail'] == invitee_email
    assert invitation['isValid']
    assert invitation['invalidReason'] is None
    assert len(invitation['acceptPage']) > 0
Exemple #2
0
def test_cancel_user_invitation(default_header, test_record_settings):
    # we invite the german user and cancel it again
    # GIVEN
    invitee_email = test_record_settings('users.4.email')
    input = {'invitationType': 'USER', 'inviteeEmail': invitee_email}
    result = execute_gql_mutation(CREATE_INVITATION_MUTATION,
                                  _headers=default_header,
                                  **input)
    invitation_id = result['invitation']['id']
    delete_emails()

    # WHEN
    execute_gql_mutation(CANCEL_INVITATION_MUTATION,
                         _headers=default_header,
                         id=invitation_id)

    # THEN
    result = execute_gql(QUERY_INVITATION_BY_ID,
                         headers=default_header,
                         variables={'id': invitation_id})
    assert result['data']['invitation']['state'] == 'CANCELED'
    # test the information mail:
    emails = get_emails()
    assert len(emails) == 1
    email = emails[0]
    assert email['to'][0] == input['inviteeEmail']
    assert email['body'].lower().find(
        'cancel') != -1, 'Info mail should include `cancel`'
def test_query_all_user_tags(admin_header, test1_user_obj, test2_user_obj):
    # GIVEN
    execute_gql_mutation(
        UPDATE_USER_MUTATION,
        _headers=admin_header,
        **{
            'id': test1_user_obj['id'],
            'tags': [{'name': 'tag1'}, {'name': 'tag2'}, {'name': 'tag3'}],
        },
    )
    execute_gql_mutation(
        UPDATE_USER_MUTATION,
        _headers=admin_header,
        **{
            'id': test2_user_obj['id'],
            'tags': [{'name': 'tag1'}, {'name': 'tag5'}, {'name': 'foo3'}],
        },
    )

    # WHEN
    result = execute_gql(
        QUERY_ALL_USER_TAGS, headers=admin_header, variables={'name_Istartswith': 'tAg'}
    )['data']['allUserTags']

    # THEN
    assert result['totalCount'] == 4, "foo is filtered out, so tag1, tag2, tag3 and tag5"
def test_query_me(snapshot, default_header, test_record_settings):
    result = execute_gql(ME_QUERY, headers=default_header)
    me = result['data']['me']
    assert me['username'] == test_record_settings('users.1.email')
    pprint(me)

    # remove time related data
    del me['registrationCompleted']
    snapshot.assert_match(me)
def test_update_user_image(admin_header, test2_user_obj, test2_header, api_is_production):
    # GIVEN
    user_id = test2_user_obj['id']
    oldImg = execute_gql(
        QUERY_USER_PROFILE_PICTURE, headers=admin_header, variables={'id': user_id}
    )['data']['user']['profileImage']

    payload = {'id': user_id, 'profileImageTemporaryId': upload_image(EXAMPLE_PROFILE_PICTURE_PATH)}

    # WHEN
    data = execute_gql_mutation(
        UPDATE_USER_PROFILE_IMAGE_MUTATION, _headers=test2_header, **payload
    )

    # THEN
    newImg = execute_gql(
        QUERY_USER_PROFILE_PICTURE, headers=admin_header, variables={'id': user_id}
    )['data']['user']['profileImage']
    assert newImg is not None and newImg != ''
    assert oldImg != newImg
    if not api_is_production:
        # test also if image is downloadable, (does not work on drone)
        assert is_static_content_available(newImg), "cannot not download uploaded image"
def test_query(test1_header):
    # GIVEN
    payload = {'text': 'default todo text', 'isDone': False}
    original_todo = execute_gql_mutation(CREATE_TODO_MUTATION,
                                         _headers=test1_header,
                                         **payload)

    # WHEN
    todos = execute_gql(QUERY_ALL_USER_TODOS, headers=test1_header)

    # THEN
    queried_todo = todos['data']['me']['ownedOrganisation']['todos']['edges'][
        0]['node']
    assert queried_todo['id'] == original_todo['todo']['id']
Exemple #7
0
def test_query_all_users(admin_header):
    """
    Tests the gql Query `allUsers` 3 times:
        * without the `orderBy` argument
        * with the `orderBy` argument
        * with the `orderBy` set to id,email
    :return:
    """
    total_counts = []
    for order_by_clause in ('', '(orderBy: "id")',
                            '(orderBy: ["id", "email"])'):
        query = ("query AllUsers { allUsers" + order_by_clause +
                 " { totalCount, edges { node { id } } } }")
        result = execute_gql(query, headers=admin_header)
        total_count = get(result, 'data.allUsers.totalCount')
        assert total_count is not None
        edges = get(result, 'data.allUsers.edges')
        assert total_count == len(edges)
        total_counts.append(total_count)

    # check if all queries returned the same amount of users:
    assert all(item == total_counts[0] for item in total_counts)
Exemple #8
0
def test_reject_user_invitation(default_header, test_record_settings):
    # we invite the german user and reject the invitation as the german user
    # GIVEN
    invitee_email = test_record_settings('users.4.email')
    input = {'invitationType': 'USER', 'inviteeEmail': invitee_email}
    result = execute_gql_mutation(CREATE_INVITATION_MUTATION,
                                  _headers=default_header,
                                  **input)
    invitation_id = result['invitation']['id']

    # WHEN
    hubert_header = authenticated_header(
        login(invitee_email, test_record_settings('users.4.password')))
    execute_gql_mutation(REJECT_INVITATION_MUTATION,
                         _headers=hubert_header,
                         id=invitation_id)

    # THEN
    result = execute_gql(QUERY_INVITATION_BY_ID,
                         headers=default_header,
                         variables={'id': invitation_id})
    assert result['data']['invitation']['state'] == 'REJECTED'
def test_query_me_admin_permissions(admin_header):
    result = execute_gql(ME_QUERY, headers=admin_header)
    me = result['data']['me']
    assert 'Administrators' in me['groups']