def test_list_keys():
    mocked_keys = [Mock(key='mykey1'), Mock(key='key2')]
    mocked_connection = Mock()
    # Start with patching connect_s3
    with patch('boto.connect_s3', Mock(return_value=mocked_connection)):
        mocked_bucket = Mock()
        # Mock get_bucket() call
        mocked_connection.get_bucket = Mock(return_value=mocked_bucket)
        # Mock the list() call to return the keys you want
        mocked_bucket.list = Mock(return_value=mocked_keys)
        keys = list_keys()

        assert keys == mocked_keys
def test_list_keys():

    expected_keys = ['key1', 'key2']

    moto = mock_s3()
    # We enter "moto" mode using this
    moto.start()

    # Get the connection object
    conn = get_s3_conn()

    # Set up S3 as we expect it to be
    conn.create_bucket('bucket_name')
    for name in expected_keys:
        k = conn.get_bucket('bucket_name').new_key(name)
        k.set_contents_from_string('abcdedsd')

    # Now call the actual function
    keys = list_keys()
    assert expected_keys == [k.name for k in keys]

    # get out of moto mode
    moto.stop()