def test_download():
    'This tests the command DOWNLOAD'
    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)
    init_user(dbdata, conn)
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_download: #1 failed to handle missing parameter'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': ((('/ wsp ' + dbdata['admin_wid']) + ' 22222222-2222-2222-2222-222222222222') + ' 1000.1000.22222222-2222-2222-2222-222222222222')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 404), 'test_download: #2 failed to handle non-existent path'
    status = make_test_file(os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid']), file_size=1000)
    assert (not status.error()), f'test_download: #3 failed to create test file: {status.info}'
    testname = status['name']
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}"}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 100), 'test_download: #3 failed to proceed to file download'
    assert (('Size' in response['Data']) and (response['Data']['Size'] == '1000')), 'test_download: #3 server failed to respond with file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Size': '1000'}})
    rawdata = conn.read()
    assert (len(rawdata) == 1000), 'test_download: #3 downloaded file had wrong length'
    status = make_test_file(os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid']), file_size=1000)
    assert (not status.error()), f'test_download: #4 failed to create test file: {status.info}'
    testname = status['name']
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '2500'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_download: #4 failed to handle offset > file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '500'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 100), 'test_download: #3 failed to proceed to file download'
    assert (('Size' in response['Data']) and (response['Data']['Size'] == '1000')), 'test_download: #5 server failed to respond with file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '500', 'Size': '1000'}})
    rawdata = conn.read()
    assert (len(rawdata) == 500), 'test_download: #5 resumed data had wrong length'
    assert (blake2hash((('0' * 500) + rawdata).encode()) == 'BLAKE2B-256:4(8V*JuSdLH#SL%edxldiA<&TayrTtdIV9yiK~Tp'), 'test_download: #8 resumed file hash failure'
    conn.disconnect()
This tests the command DOWNLOAD
def test_download():
    
    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)
    init_user(dbdata, conn)
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_download: #1 failed to handle missing parameter'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': ((('/ wsp ' + dbdata['admin_wid']) + ' 22222222-2222-2222-2222-222222222222') + ' 1000.1000.22222222-2222-2222-2222-222222222222')}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 404), 'test_download: #2 failed to handle non-existent path'
    status = make_test_file(os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid']), file_size=1000)
    assert (not status.error()), f'test_download: #3 failed to create test file: {status.info}'
    testname = status['name']
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}"}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 100), 'test_download: #3 failed to proceed to file download'
    assert (('Size' in response['Data']) and (response['Data']['Size'] == '1000')), 'test_download: #3 server failed to respond with file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Size': '1000'}})
    rawdata = conn.read()
    assert (len(rawdata) == 1000), 'test_download: #3 downloaded file had wrong length'
    status = make_test_file(os.path.join(dbdata['configfile']['global']['workspace_dir'], dbdata['admin_wid']), file_size=1000)
    assert (not status.error()), f'test_download: #4 failed to create test file: {status.info}'
    testname = status['name']
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '2500'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 400), 'test_download: #4 failed to handle offset > file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '500'}})
    response = conn.read_response(server_response)
    assert (response['Code'] == 100), 'test_download: #3 failed to proceed to file download'
    assert (('Size' in response['Data']) and (response['Data']['Size'] == '1000')), 'test_download: #5 server failed to respond with file size'
    conn.send_message({'Action': 'DOWNLOAD', 'Data': {'Path': f"/ wsp {dbdata['admin_wid']} {testname}", 'Offset': '500', 'Size': '1000'}})
    rawdata = conn.read()
    assert (len(rawdata) == 500), 'test_download: #5 resumed data had wrong length'
    assert (blake2hash((('0' * 500) + rawdata).encode()) == 'BLAKE2B-256:4(8V*JuSdLH#SL%edxldiA<&TayrTtdIV9yiK~Tp'), 'test_download: #8 resumed file hash failure'
    conn.disconnect()