def test_delete_specific_item():
    """The old behavior of delete cache is deleting the whole cache file. Now we change it to partially deletion."""
    auth.write_temporary_credential_file(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0, CRED_TYPE_0),
        CRED_0,
    )
    auth.write_temporary_credential_file(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0, CRED_TYPE_1),
        CRED_1,
    )
    auth.read_temporary_credential_file()

    assert auth.TEMPORARY_CREDENTIAL
    assert (get_credential(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0,
                                             CRED_TYPE_0)) == CRED_0)
    assert (get_credential(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0,
                                             CRED_TYPE_1)) == CRED_1)

    auth.temporary_credential_file_delete_password(HOST_0, USER_0, CRED_TYPE_0)
    auth.read_temporary_credential_file()
    assert not get_credential(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0, CRED_TYPE_0))
    assert (get_credential(
        HOST_0,
        auth.build_temporary_credential_name(HOST_0, USER_0,
                                             CRED_TYPE_1)) == CRED_1)

    auth.delete_temporary_credential_file()
def test_basic_store(tmpdir):
    os.environ['SF_TEMPORARY_CREDENTIAL_CACHE_DIR'] = str(tmpdir)

    auth.delete_temporary_credential_file()
    auth.TEMPORARY_CREDENTIAL.clear()

    auth.read_temporary_credential_file()
    assert not auth.TEMPORARY_CREDENTIAL

    auth.write_temporary_credential_file(HOST_0, USER_0, CRED_0)
    auth.write_temporary_credential_file(HOST_1, USER_1, CRED_1)
    auth.write_temporary_credential_file(HOST_0, USER_1, CRED_1)

    auth.read_temporary_credential_file()
    assert auth.TEMPORARY_CREDENTIAL
    assert get_credential(HOST_0, USER_0) == CRED_0
    assert get_credential(HOST_1, USER_1) == CRED_1
    assert get_credential(HOST_0, USER_1) == CRED_1

    auth.delete_temporary_credential_file()