Beispiel #1
0
def contact_profile_id(admin_stub, random_name, public_key):
    # Create a new contact profile
    contact_profile_id = create_contact_profile(
        admin_stub, random_name, public_key)
    yield contact_profile_id
    # Delete the profile
    admin_stub.DeleteSqueakProfile(
        squeak_admin_pb2.DeleteSqueakProfileRequest(
            profile_id=contact_profile_id,
        )
    )
def test_subscribe_squeaks(
    admin_stub,
    other_admin_stub,
    signing_profile_id,
):

    # Get the squeak profile
    squeak_profile = get_squeak_profile(admin_stub, signing_profile_id)
    squeak_profile_address = squeak_profile.address
    squeak_profile_name = squeak_profile.profile_name

    # Add the contact profile to the other server and set the profile to be following
    contact_profile_id = create_contact_profile(other_admin_stub,
                                                squeak_profile_name,
                                                squeak_profile_address)
    other_admin_stub.SetSqueakProfileFollowing(
        squeak_admin_pb2.SetSqueakProfileFollowingRequest(
            profile_id=contact_profile_id,
            following=True,
        ))

    with free_price(admin_stub), \
        open_peer_connection(
        other_admin_stub,
        "test_peer",
        "squeaknode",
        18777,
    ):
        # Create a new squeak using the new profile
        make_squeak_content = "Hello this message should be subscribed!"
        make_squeak_hash = make_squeak(
            admin_stub,
            signing_profile_id,
            make_squeak_content,
        )

        time.sleep(2)

        # Get the squeak display item
        squeak_display_entry = get_squeak_display(
            other_admin_stub,
            make_squeak_hash,
        )
        assert squeak_display_entry is not None

        # Get the squeak display item
        get_squeak_display_entry = get_squeak_display(
            other_admin_stub,
            make_squeak_hash,
        )
        assert (get_squeak_display_entry.content_str == make_squeak_content)
def test_make_contact_profile(admin_stub, squeak_address):
    # Create a new contact profile
    contact_name = "test_contact_profile_name"
    contact_profile_id = create_contact_profile(admin_stub, contact_name,
                                                squeak_address)

    # Get all contact profiles
    get_contact_profiles_response = admin_stub.GetContactProfiles(
        squeak_admin_pb2.GetContactProfilesRequest())
    contact_profile_names = [
        profile.profile_name
        for profile in get_contact_profiles_response.squeak_profiles
    ]
    contact_profile_ids = [
        profile.profile_id
        for profile in get_contact_profiles_response.squeak_profiles
    ]
    assert contact_name in contact_profile_names
    assert contact_profile_id in contact_profile_ids
def test_make_contact_profile_empty_name(admin_stub, squeak_address):
    # Try to create a new contact profile with an empty name
    with pytest.raises(Exception) as excinfo:
        create_contact_profile(admin_stub, "", squeak_address)
    assert "Profile name cannot be empty." in str(excinfo.value)