예제 #1
0
def connection_with_temporary_testuser(connection):
    d = Users(connection)
    previous_quantity = len(d)
    assert previous_quantity > 0  # The server should already have a user
    username = "******" + str(uuid.uuid4())
    email = "*****@*****.**"

    new_user = User(username=username, email=email, password="******")
    print(new_user)

    new_user_id = d.append(new_user)
    print("Created new user id", new_user_id, ":", new_user)

    # Let the test use the user
    ConnectionWithTemporaryTestUser = namedtuple(
        "ConnectionWithTemporaryTestUser", "connection, users, user, user_id")
    yield ConnectionWithTemporaryTestUser(connection, d, d[new_user_id],
                                          new_user_id)

    # Cleanup
    del d[new_user_id]

    # Update happened
    assert len(d) == previous_quantity

    with pytest.raises(KeyError):
        _ = d[new_user_id]
예제 #2
0
def test_valid_email_addresses(email, valid):

    u = {'user': {'id': '1', 'username': '******', 'email': email}}

    if email == MissingSentinal:
        del u['user']['email']
        email = None

    o = User.from_dict(None, None, u, many=False)

    print(o)
    assert valid == isinstance(o, User)

    back_to_json = o._serialize()
    print("back_to_json:", back_to_json)

    assert back_to_json['user']['email'] not in (None, MissingSentinal)

    if email == "":
        email = None

    if valid:
        assert isinstance(o, User)
        assert o.email == email
    else:
        assert isinstance(o, dict)
예제 #3
0
def test_modify_an_existing_user_object(connection):
    d = Users(connection)
    previous_quantity = len(d)

    assert previous_quantity > 0  # The server should already have a user

    username = "******" + str(uuid.uuid4())
    email = "*****@*****.**"
    new_user = User(username=username, email=email, password="******")
    print(new_user)

    new_user_id = d.append(new_user)
    print("Created new user id", new_user_id, ":", new_user)

    # Setup Completed

    # Get and mutate the object
    refetch_user = d[new_user_id]
    assert refetch_user.username == username

    with refetch_user as m:
        m.email = "*****@*****.**"

    # Retrieve updated object from server
    verification = d[new_user_id]

    # Remove the key from the server before asserts
    del d[new_user_id]

    # Update happened
    assert verification.email == "*****@*****.**"
    assert len(d) == previous_quantity
예제 #4
0
def test_add_user_and_remove_it_again(connection):
    d = Users(connection)
    previous_quantity = len(d)

    assert previous_quantity > 0  # The server should already have a user

    username = "******" + str(uuid.uuid4())
    email = "*****@*****.**"
    new_user = User(username=username, email=email, password="******")
    print(new_user)

    new_user_id = d.append(new_user)
    print("Created new user id", new_user_id, ":", new_user)

    refetch_user = d[new_user_id]
    assert refetch_user.username == username

    # Remove the key from the server; server may become unlicensed at this point
    del d[new_user_id]

    # Same quantity now as before
    assert len(d) == previous_quantity