def test_listdirs():
    'Tests the LISTDIRS command'
    dbconn = setup_test()
    dbdata = init_server(dbconn)
    conn = ServerConnection()
    assert conn.connect('localhost', 2001), 'Connection to server at localhost:2001 failed'
    reset_top_dir(dbdata)
    pwhash = '$argon2id$v=19$m=65536,t=2,p=1$ew5lqHA5z38za+257DmnTA$0LWVrI2r7XCqdcCYkJLok65qussSyhN5TTZP+OTgzEI'
    devid = '22222222-2222-2222-2222-222222222222'
    devpair = EncryptionPair(CryptoString('CURVE25519:@X~msiMmBq0nsNnn0%~x{M|NU_{?<Wj)cYybdh&Z'), CryptoString('CURVE25519:W30{oJ?w~NBbj{F8Ag4~<bcWy6_uQ{i{X?NDq4^l'))
    dbdata['pwhash'] = pwhash
    dbdata['devid'] = devid
    dbdata['devpair'] = devpair
    regcode_admin(dbdata, conn)
    login_admin(dbdata, conn)
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': '/ 11111111-1111-1111-1111-111111111111'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 404), 'test_listdirs: #1 failed to handle missing path'
    admin_dir = os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid'])
    status = make_test_file(admin_dir)
    assert (not status.error()), 'test_listdirs: #2 failed to create test file'
    conn.send_message({'Action': 'LIST', 'Data': {'Path': ' '.join(['/ wsp', dbdata['admin_wid'], status['name']])}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_listdirs: #2 failed to handle path as file'
    os.mkdir(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111'))
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': (('/ wsp ' + dbdata['admin_wid']) + ' 11111111-1111-1111-1111-111111111111')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 200), 'test_listdirs: #3 failed to handle empty directory'
    assert (('Directories' in response['Data']) and (len(response['Data']['Directories']) == 0)), 'test_listdirs: #3 failed to have empty response for empty directory'
    for i in range(2, 7):
        tempname = '-'.join([(str(i) * 8), (str(i) * 4), (str(i) * 4), (str(i) * 4), (str(i) * 12)])
        try:
            os.mkdir(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111', tempname))
        except Exception as e:
            assert False, ('test_listdirs: #4 failed to create test directories: ' + e)
        make_test_file(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111'))
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': (('/ wsp ' + dbdata['admin_wid']) + ' 11111111-1111-1111-1111-111111111111')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 200), 'test_listdirs: #4 failed to handle non-empty directory'
    assert (('Directories' in response['Data']) and (len(response['Data']['Directories']) == 5)), 'test_list: #4 failed to list all subdirectories'
    conn.disconnect()
Tests the LISTDIRS command
def test_listdirs():
    
    dbconn = setup_test()
    dbdata = init_server(dbconn)
    conn = ServerConnection()
    assert conn.connect('localhost', 2001), 'Connection to server at localhost:2001 failed'
    reset_top_dir(dbdata)
    pwhash = '$argon2id$v=19$m=65536,t=2,p=1$ew5lqHA5z38za+257DmnTA$0LWVrI2r7XCqdcCYkJLok65qussSyhN5TTZP+OTgzEI'
    devid = '22222222-2222-2222-2222-222222222222'
    devpair = EncryptionPair(CryptoString('CURVE25519:@X~msiMmBq0nsNnn0%~x{M|NU_{?<Wj)cYybdh&Z'), CryptoString('CURVE25519:W30{oJ?w~NBbj{F8Ag4~<bcWy6_uQ{i{X?NDq4^l'))
    dbdata['pwhash'] = pwhash
    dbdata['devid'] = devid
    dbdata['devpair'] = devpair
    regcode_admin(dbdata, conn)
    login_admin(dbdata, conn)
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': '/ 11111111-1111-1111-1111-111111111111'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 404), 'test_listdirs: #1 failed to handle missing path'
    admin_dir = os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid'])
    status = make_test_file(admin_dir)
    assert (not status.error()), 'test_listdirs: #2 failed to create test file'
    conn.send_message({'Action': 'LIST', 'Data': {'Path': ' '.join(['/ wsp', dbdata['admin_wid'], status['name']])}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_listdirs: #2 failed to handle path as file'
    os.mkdir(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111'))
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': (('/ wsp ' + dbdata['admin_wid']) + ' 11111111-1111-1111-1111-111111111111')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 200), 'test_listdirs: #3 failed to handle empty directory'
    assert (('Directories' in response['Data']) and (len(response['Data']['Directories']) == 0)), 'test_listdirs: #3 failed to have empty response for empty directory'
    for i in range(2, 7):
        tempname = '-'.join([(str(i) * 8), (str(i) * 4), (str(i) * 4), (str(i) * 4), (str(i) * 12)])
        try:
            os.mkdir(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111', tempname))
        except Exception as e:
            assert False, ('test_listdirs: #4 failed to create test directories: ' + e)
        make_test_file(os.path.join(admin_dir, '11111111-1111-1111-1111-111111111111'))
    conn.send_message({'Action': 'LISTDIRS', 'Data': {'Path': (('/ wsp ' + dbdata['admin_wid']) + ' 11111111-1111-1111-1111-111111111111')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 200), 'test_listdirs: #4 failed to handle non-empty directory'
    assert (('Directories' in response['Data']) and (len(response['Data']['Directories']) == 5)), 'test_list: #4 failed to list all subdirectories'
    conn.disconnect()