예제 #1
0
def test_list_dir_path():
    """
    Creates a folder and puts a file in it.
    Checks for file.
    Checks for response code: 226
    @requires: delete_folder to pass
    @requires: upload to pass
    """
    expected = '226'
    dir_name = 'ListTest'
    file_name = 'temp.txt'
    the_dir = os.path.join(test_dir, dir_name)
    os.mkdir(the_dir)
    the_file = os.path.join(the_dir, file_name)
    with open(the_file, 'w') as w:
        w.write('words')
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.mkd(dir_name)
    f.upload(the_file)
    the_list = f.list_dir(the_dir)
    actual = f.lastresp
    f.delete_folder(the_dir)
    f.quit()
    f.close()
    if os.path.exists(the_dir):
        rmtree(the_dir)
    if file_name in the_list:
        n_eq(expected, actual, f, 'list_dir')
    else:
        n_ok(False, f, 'list_dir', message='404')
예제 #2
0
def test_cd():
    """
    Tests the cd command
    Checks for response code: 250
    Checks the directory name:
    @required: delete_folder to pass
    """
    expected= '250'
    dir_name = 'TestCd'
    the_dir = os.path.join(test_dir, dir_name)
    os.mkdir(the_dir)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.mkd(dir_name)
    f.cd(the_dir)
    actual = f.lastresp
    in_dir = f.pwd()
    f.cwd('..')
    f.delete_folder(the_dir)
    f.quit()
    f.close()
    if os.path.exists(the_dir):
        rmtree(the_dir)
    if in_dir.strip('/') == dir_name:
        n_eq(expected, actual, f, 'cd')
    else:
        print 'Expected:', dir_name, 'Actual:', in_dir
        n_ok(False, f, 'cd', message="Dir names don't match")
예제 #3
0
def test_mkdir():
    """
    Test making a new directory based on local directory.
    Checks for response code: 257
    Checks for folder on server.
    @requires: list_dir to pass
    @requires: delete_folder to pass
    """
    expected = '257'
    dir_name = 'TestMkDir'
    the_dir = os.path.join(test_dir, dir_name)
    os.mkdir(the_dir)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.mkdir(the_dir)
    actual = f.lastresp
    the_list = f.list_dir()
    f.delete_folder(the_dir)
    f.quit()
    f.close()
    if os.path.exists(the_dir):
        rmtree(the_dir)
    if dir_name in the_list:
        n_eq(expected, actual, f, 'mkdir')
    else:
        n_ok(False, f, 'mkdir', message='folder not found')
예제 #4
0
def test_tm_good_quick_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Checks that data is being written with a good push
    """
    expected = ['abc', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(expected)
    s = SqlManager(db_name)
    s.connect()
    values = s._fetch_command('SELECT * FROM ' + table_name + ';')
    s.disconnect()
    values = values[0]
    actual = []
    expected = ['abc', 1]
    for val in values:
        if type(val) == int:
            val = int(val)
        else:
            val = str(val)
        actual += [val]
    message = 'Expected: ' + str(expected) + '\n' + 'Actual' + str(actual)
    n_eq(expected, actual, message=message)
예제 #5
0
def test_tm_good_quick_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Checks that data is being written with a good push
    """
    expected = ['abc', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(expected)
    s = SqlManager(db_name)
    s.connect()
    values = s._fetch_command('SELECT * FROM ' + table_name + ';')
    s.disconnect()
    values = values[0]
    actual = []
    expected = ['abc', 1]
    for val in values:
        if type(val) == int:
            val = int(val)
        else:
            val = str(val)
        actual += [val]
    message = 'Expected: ' + str(expected) + '\n' + 'Actual' + str(actual)
    n_eq(expected, actual, message=message)
예제 #6
0
def test_move_as_move_folder():
    """
    Tries to move one folder into another.
    Creates one more folder.
    Tries to move folder into it.
    Checks for response code: 250
    @requires: test_move_as_file to pass
    """
    expected = '250'
    folder = os.path.join(test_dir, 'second_transfer')
    if not os.path.exists(folder):
        os.mkdir(folder)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.mkd('second_transfer')
    to_folder = os.path.abspath(folder)
    f.move('first_transfer', to_folder)
    actual = f.lastresp
    nlst = f.nlst('second_transfer')
    f.quit()
    f.close()
    if os.path.split(uploaded_file)[1] in nlst:
        n_eq(expected, actual, f, 'move')
    else:
        print 'nlst:', nlst
        n_ok(False, f, 'move', message='File not moved')
예제 #7
0
def test_delete_empty_folder():
    """
    Deletes the folder we were uploading into
    """
    u1_ftp.rmd('upload_folder')
    actual = u1_ftp.lastresp
    expected = '250'
    n_eq(actual, expected)
예제 #8
0
def test_sm_pull_tables():
    """
    Checks that pull tables is retrieving all the tables
    """
    s = SqlManager(db_name)
    actual = s.tables[0]
    expected = table_name
    n_eq(expected, actual, s, '_pull_tables')
예제 #9
0
def test_sm_pull_tables():
    """
    Checks that pull tables is retrieving all the tables
    """
    s = SqlManager(db_name)
    actual = s.tables[0]
    expected = table_name
    n_eq(expected, actual, s, '_pull_tables')
예제 #10
0
def test_pwd():
    """
    All users see '/' as their starting dir.
    Admin is actually in the same file as all the server python files
    """
    actual = ftp.pwd()
    expected = '/'
    n_eq(expected, actual)
예제 #11
0
def test_make_dir():
    """
    Makes a dir called server, and checks for the response code '257'
    Which means that everything is all good.
    """
    ftp.voidcmd('MKD /test_fs')
    expect = '257'
    actual = ftp.lastresp
    n_eq(expect, actual)
예제 #12
0
def test_delete_file():
    """
    Deletes the file that we uploaded earlier
    """
    u1_ftp.cwd('upload_folder')
    u1_ftp.delete('uploaded.txt')
    actual = u1_ftp.lastresp
    expected = '250'
    n_eq(actual, expected)
예제 #13
0
def test_ta_add_column():
    """
    Checks that the column is added
    """
    table_name = 'def'
    expected = 'test_column'
    t = TableAdder(db_name, table_name)
    t.add_column(expected)
    actual = t.table_columns[0][0]
    n_eq(expected, actual, t, 'add_column', message='table still not added')
예제 #14
0
def test_ta_add_column():
    """
    Checks that the column is added
    """
    table_name = 'def'
    expected = 'test_column'
    t = TableAdder(db_name, table_name)
    t.add_column(expected)
    actual = t.table_columns[0][0]
    n_eq(expected, actual, t, 'add_column', message='table still not added')
예제 #15
0
def test_tm_medium_pull():
    """
    Tries to pull all the columns were there are different types
    """
    push = ['one', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(push)
        expected = ('one', 1)
        actual = t.pull()[0]
    n_eq(expected, actual)
예제 #16
0
def test_tm_medium_pull():
    """
    Tries to pull all the columns were there are different types
    """
    push = ['one', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(push)
        expected = ('one', 1)
        actual = t.pull()[0]
    n_eq(expected, actual)
예제 #17
0
def test_connect():
    """
    Tests the __init__
    Checks for response code : 230
    """
    expected = '230'
    f = OneDirFtpClient(ip, user, pw, test_dir)
    actual = f.lastresp
    f.quit()
    f.close()
    n_eq(expected, actual)
예제 #18
0
def test_sm_fetch_command():
    """
    Checks that the db can run a fetch command
    """
    command = 'SELECT * FROM %s;' % table_name
    s = SqlManager(db_name)
    s.connect()
    data = s._fetch_command(command)[0]
    s.disconnect()
    actual = [str(col) for col in data]
    expected = ['one', 'two', 'three']
    n_eq(expected, actual, s, '_fetch_command')
예제 #19
0
def test_sm_fetch_command():
    """
    Checks that the db can run a fetch command
    """
    command = 'SELECT * FROM %s;' % table_name
    s = SqlManager(db_name)
    s.connect()
    data = s._fetch_command(command)[0]
    s.disconnect()
    actual = [str(col) for col in data]
    expected = ['one', 'two', 'three']
    n_eq(expected, actual, s, '_fetch_command')
예제 #20
0
def test_user_add():
    """
    Makes a new user
    """
    ftp.cwd('/test_fs')
    ftp.voidcmd('mkd %s' % user_one)
    ftp.voidcmd('useradd %s %s' % (user_one, user_one_pw))
    r1 = ftp.lastresp
    setup_user_one()
    r2 = u1_ftp.lastresp
    teardown_user_one()
    expected = ['200', '230']
    actual = [r1, r2]
    n_eq(expected, actual)
예제 #21
0
def test_user_list():
    """
    Gets a list of all the users 
    Checks for responce code: 226
    Checks a line representing admin exists.
    """
    expected = '226'
    ftp.retrlines('site userlist', callback)
    actual = ftp.lastresp
    line = "('admin', 1, 'welcome', 'goodbye')"
    if line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='line not recieved') 
예제 #22
0
def test_get_log():
    """
    Gives the location of log. A normal download command can be used to download it.
    Checks for responce code: 200
    Check the name of the log.
    """
    expected = '200'
    log = ftp.sendcmd('site getlog')
    actual = ftp.lastresp
    log = log.split('/')[-1]
    if log == 'pyftpd.log':
        n_eq(expected, actual)
    else:
        print log
        n_ok(False)
예제 #23
0
def test_get_log():
    """
    Gives the location of log. A normal download command can be used to download it.
    Checks for responce code: 200
    Check the name of the log.
    """
    expected = '200'
    log = ftp.sendcmd('site getlog')
    actual = ftp.lastresp
    log = log.split('/')[-1]
    if log == 'pyftpd.log':
        n_eq(expected, actual)
    else:
        print log
        n_ok(False)
예제 #24
0
def test_user_list():
    """
    Gets a list of all the users 
    Checks for responce code: 226
    Checks a line representing admin exists.
    """
    expected = '226'
    ftp.retrlines('site userlist', callback)
    actual = ftp.lastresp
    line = "('admin', 1, 'welcome', 'goodbye')"
    if line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='line not recieved')
예제 #25
0
def test_download():
    """
    Attempts to download a file
    """
    u1_ftp.cwd('upload_folder')
    f_name = 'uploaded.txt'
    download_file = open(f_name, 'wb')
    u1_ftp.retrlines('RETR %s' % f_name, download_file.write)
    download_file.close()
    if os.path.isfile(f_name):
        os.remove(f_name)
    else:
        n_ok(False)
    actual = u1_ftp.lastresp
    expected = '226'
    n_eq(actual, expected)
예제 #26
0
def test_list_dir_current():  # NOTE: I am thinking of killing this so it is not allowed, thoughts?
    """
    Lists the files in the folder,
    Since the testing server runs on 'testing_server.py' it will check for that
    Checks for response code: 226
    """
    expected = '226'
    f = OneDirFtpClient(ip, user, pw, test_dir)
    files = f.list_dir()
    actual = f.lastresp
    f.quit()
    f.close()
    if 'testing_server.py' in files:
        n_eq(expected, actual, f, 'list_dir')
    else:
        n_ok(False, f, 'list_dir', message='404')
예제 #27
0
def test_user_del():
    """
    Attempts to delete a user.
    @requires: user_add to pass.
    Check for responce code: 200
    Checks that user is not in database.
    """
    expected = '200'
    ftp.sendcmd('site userdel user_one')
    actual = ftp.lastresp
    line = "('user_one', 0, 'welcome', 'goodbye')"
    ftp.retrlines('site userlist', callback)
    if not line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='user not deleted')
예제 #28
0
def test_user_del():
    """
    Attempts to delete a user.
    @requires: user_add to pass.
    Check for responce code: 200
    Checks that user is not in database.
    """
    expected = '200'
    ftp.sendcmd('site userdel user_one')
    actual = ftp.lastresp
    line = "('user_one', 0, 'welcome', 'goodbye')"
    ftp.retrlines('site userlist', callback)
    if not line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='user not deleted')
예제 #29
0
def test_user_add():
    """
    Attempts to create a user
    @requires: user_list to pass.
    Checks for responce code: 200
    Checks that user is in database.
    """
    expected = '200'
    ftp.sendcmd('site useradd user_one 0 %s' % password)
    actual = ftp.lastresp
    ftp.retrlines('site userlist', callback)
    line = "('user_one', 0, 'welcome', 'goodbye')"
    if line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='User not added')
예제 #30
0
def test_check_file():
    """
    Gets the checksum of a file
    NOTE: This has been changed so that the file is not longer written with an extra line at the end
    """
    f_name = 'check_this.txt'
    with open(f_name, 'w') as w:
        w.write('some text for the file')
    u1_ftp.storbinary('STOR %s' % f_name, open(f_name, 'rb'))
    local = hashlib.sha224(open(f_name, 'rb').read()).hexdigest()
    if os.path.isfile(f_name):
        os.remove(f_name)
    setup_callback()
    u1_ftp.retrlines('checksum %s' % f_name, callback)
    server = received
    server = ''.join(server)
    n_eq(server, local)
예제 #31
0
def test_user_add():
    """
    Attempts to create a user
    @requires: user_list to pass.
    Checks for responce code: 200
    Checks that user is in database.
    """
    expected = '200'
    ftp.sendcmd('site useradd user_one 0 %s' % password)
    actual = ftp.lastresp
    ftp.retrlines('site userlist', callback)
    line = "('user_one', 0, 'welcome', 'goodbye')"
    if line in received:
        n_eq(expected, actual)
    else:
        print received
        n_ok(False, message='User not added')
예제 #32
0
def test_i_am():
    """
    Sets secondary username.
    Checks for responce code: 200
    Checks that the name was set. 
    @requres: who am i to pass
    """
    expected = '200'
    ftp.sendcmd('site iam abc')
    actual = ftp.lastresp
    x = ftp.sendcmd('site whoami')
    x = x.split(':')
    x[0] = x[0].split(' ')[1]
    if x[0] == 'admin' and x[1] == 'abc':
        n_eq(expected, actual)
    else:
        print x
        n_ok(False, message='name not set')
예제 #33
0
def test_i_am():
    """
    Sets secondary username.
    Checks for responce code: 200
    Checks that the name was set. 
    @requres: who am i to pass
    """
    expected = '200'
    ftp.sendcmd('site iam abc')
    actual = ftp.lastresp
    x = ftp.sendcmd('site whoami')
    x = x.split(':')
    x[0] = x[0].split(' ')[1]
    if x[0] == 'admin' and x[1] == 'abc':
        n_eq(expected, actual)
    else:
        print x
        n_ok(False, message='name not set')
예제 #34
0
def test_admin_change_password():
    """
    Creates a new users.
    Changes new user password.
    Attempts to log in with new password.
    Checks for responce code: 200
    """
    expected = '200'
    ftp.sendcmd('site useradd %s 0 %s' % (usr, password))
    ftp.sendcmd('site changepw %s %s' % (usr, new_pw))
    actual = ftp.lastresp
    f = FTP()
    f.connect(ip)
    try:
        f.login(usr, new_pw)
        n_eq(expected, actual)
    except:
        n_ok(False, message='Authentication Failed')
예제 #35
0
def test_upload():
    """
    Attempts to upload a file
    NOTE: This one has been edited in order to fix the extra line being appended to the end of the file.
    NOTE: This works with any file type.
    """
    new_dir = 'upload_folder'
    f_name = 'uploaded.txt'
    u1_ftp.voidcmd('mkd %s' % new_dir)
    with open(f_name, 'w') as w:
        w.write('some text for the file')
    u1_ftp.cwd(new_dir)
    u1_ftp.storbinary('STOR %s' % f_name, open(f_name, 'rb'))
    actual = u1_ftp.lastresp
    expected = '226'
    if os.path.isfile(f_name):
        os.remove(f_name)
    n_eq(expected, actual)
예제 #36
0
def test_admin_change_password():
    """
    Creates a new users.
    Changes new user password.
    Attempts to log in with new password.
    Checks for responce code: 200
    """
    expected = '200'
    ftp.sendcmd('site useradd %s 0 %s' % (usr, password))
    ftp.sendcmd('site changepw %s %s' % (usr, new_pw))  
    actual = ftp.lastresp
    f = FTP()
    f.connect(ip)
    try:
        f.login(usr, new_pw)
        n_eq(expected, actual)
    except:
        n_ok(False, message='Authentication Failed')
예제 #37
0
def test_sm_no_fetch_command():
    """
    Checks that the table can run a no fetch command
    """
    expected = ['a', 'b', 'c']
    command = 'INSERT INTO %s VALUES(%s);' % (table_name, str(expected)[1:-1])
    s = SqlManager(db_name)
    s.connect()
    s._no_fetch_command(command)
    s.disconnect()
    con = lite.connect(db_name)
    cur = con.cursor()
    command = 'SELECT * FROM %s;' % table_name
    cur.execute(command)
    fetched = cur.fetchall()
    fetched = fetched[1]
    actual = [str(col) for col in fetched]
    n_eq(expected, actual, s, '_no_fetch_command', message='Good chance that I did not setup test right')
예제 #38
0
def test_delete_full_folder():
    """
    Tries to delete a folder with items in it.
    Checks for response code: 250
    Check for folder in dir
    """
    expected = '250'
    f = OneDirFtpClient(ip, user, pw, test_dir)
    folder = os.path.join(test_dir, 'second_transfer')
    f.delete_folder(folder)
    actual = f.lastresp
    nlst = f.nlst()
    f.quit()
    f.close()
    if not 'second_transfer' in nlst:
        n_eq(expected, actual, f, 'delete_folder')
    else:
        print 'nlst:', nlst
        n_ok(False, f, 'delete_folder', message='Folder in nlst')
예제 #39
0
def test_download_image():
    """
    Tries to download a image from the server.
    Checks for response code: 226
    Checks that the file has been downloaded.
    @requires: test_upload_image to pass
    """
    expected = '226'
    if os.path.isfile(test_image):
        os.remove(test_image)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.download(test_image)
    actual = f.lastresp
    f.quit()
    f.close()
    if os.path.isfile(test_image):
        n_eq(expected, actual, f, 'download')
    else:
        n_ok(False, f, 'download', message='File not downloaded')
예제 #40
0
def test_tm_sorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to push a list where the columns are already in order with good info
    """
    push = [('text_col', 'one'), ('int_col', 1)]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[0]
    expected = [str(val[1]) for val in push]
    actual = [str(val) for val in data]
    n_eq(expected, actual)
예제 #41
0
def test_upload_image():
    """
    Tries to upload an image to the server.
    Checks for response code: 226
    Checks for file on server.
    @requires: ../../extra/fancy/small_strip.png to exist
    """
    expected = '226'
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.upload(test_image)
    actual = f.lastresp
    nlst = f.nlst()
    f.quit()
    f.close()
    if os.path.split(test_image)[1] in nlst:
        n_eq(expected, actual, f, 'upload')
    else:
        print 'nlst:', nlst
        n_eq(False, f, 'upload', message='Not in NLST')
예제 #42
0
def test_pull_where_string():
    """
    This one test should cover all operators
    @precondition: test_tm_quick_push passed
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    """
    with TableManager(db_name, table_name) as t:
        t.clear_table()
        for i in range(9):
            text = 'one_%d' % i
            t.quick_push([text, i])
        expected = ('one_5', 5)
        value = column_map[0][0]
        compare_to = 'one_5'
        op = '='
        actual = t.pull_where(value, compare_to, op)[0]
    n_eq(expected, actual)
예제 #43
0
def test_tm_easy_pull():
    """
    @precondition: test_tm_quick_push passed
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to pull all the columns where every type is text
    """
    testing_table = 'def'
    ta = TableAdder(db_name, testing_table)
    ta.add_column('col_one')
    ta.add_column('col_two')
    ta.commit()
    push = ['one', 'two']
    expected = ('one', 'two')
    with TableManager(db_name, testing_table) as t:
        t.quick_push(push)
        actual = t.pull()[0]
    n_eq(expected, actual)
예제 #44
0
def test_pull_where_string():
    """
    This one test should cover all operators
    @precondition: test_tm_quick_push passed
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    """
    with TableManager(db_name, table_name) as t:
        t.clear_table()
        for i in range(9):
            text = 'one_%d' % i
            t.quick_push([text, i])
        expected = ('one_5', 5)
        value = column_map[0][0]
        compare_to = 'one_5'
        op = '='
        actual = t.pull_where(value, compare_to, op)[0]
    n_eq(expected, actual)
예제 #45
0
def test_get_time():
    """
    Tries to get the server time. 
    Checks it length (for formatting)
    Checks for responce code: 200
    Tries to cast time to an int.
    """
    expected = '200'
    x = ftp.sendcmd('site gettime')
    actual = ftp.lastresp
    x = x.split(' ')[1]
    if len(x) == 20:
        int(x)
        global start
        start = x
        n_eq(expected, actual)
    else:
        print 'length: ', len(x)
        print 'value', x
        n_ok(False)
예제 #46
0
def test_delete_file():
    """
    Tries to delete a file ofter the server.
    Checks for response code:
    Checks the file is gone
    @requires: test_move_as_rename to pass
    """
    expected = '250'
    f = OneDirFtpClient(ip, user, pw, test_dir)
    after_name = os.path.join(test_dir, 'after_name.txt')
    f.delete_file(after_name)
    actual = f.lastresp
    nlst = f.nlst()
    f.quit()
    f.close()
    if not 'after_name.txt' in nlst:
        n_eq(expected, actual, f, 'delete_file')
    else:
        print 'nlst:', nlst
        n_ok(False, f, 'delete_file', message='File still in nlst')
예제 #47
0
def test_tm_unsorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to sort the list of good info and then push it.
    Also does type conversion
    """
    push = [('int_col', '1'), ('text_col', 'one')]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[1]
    expected = [str(val[1]) for val in push][::-1]
    actual = [str(val) for val in data]
    n_eq(expected, actual)
예제 #48
0
def test_upload_file():
    """
    Creates a text file, and tries to upload it to the server.
    Checks for response code: 226
    Checks for file on server.
    """
    expected = '226'
    with open(uploaded_file, 'w') as w:
        w.write('some text for the file')
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.upload(uploaded_file)
    actual = f.lastresp
    nlst = f.nlst()
    f.quit()
    f.close()
    if os.path.split(uploaded_file)[1] in nlst:
        n_eq(expected, actual, f, 'upload')
    else:
        print 'nlst:', nlst
        n_ok(False, f, 'upload', message='Not in NLST')
예제 #49
0
def test_download_file():
    """
    Tries to download a file from the server.
    Checks for response code: 226
    Checks if file exists.
    Note: This will downloaded the file into this folder not the testing folder.
    @requires: test_upload_file to pass.
    """
    expected = '226'
    if os.path.isfile(uploaded_file):
        os.remove(uploaded_file)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.download(uploaded_file)
    actual = f.lastresp
    f.quit()
    f.close()
    if os.path.isfile(uploaded_file):
        n_eq(expected, actual, f, 'download')
    else:
        n_ok(False, f, 'download', message='File not downloaded')
예제 #50
0
def test_sm_no_fetch_command():
    """
    Checks that the table can run a no fetch command
    """
    expected = ['a', 'b', 'c']
    command = 'INSERT INTO %s VALUES(%s);' % (table_name, str(expected)[1:-1])
    s = SqlManager(db_name)
    s.connect()
    s._no_fetch_command(command)
    s.disconnect()
    con = lite.connect(db_name)
    cur = con.cursor()
    command = 'SELECT * FROM %s;' % table_name
    cur.execute(command)
    fetched = cur.fetchall()
    fetched = fetched[1]
    actual = [str(col) for col in fetched]
    n_eq(expected,
         actual,
         s,
         '_no_fetch_command',
         message='Good chance that I did not setup test right')
예제 #51
0
def test_delete_empty_folder():
    """
    Tries to delete an empty folder
    Checks for response code: 250
    Checks that the file is gone
    """
    expected = '250'
    folder = os.path.join(test_dir, 'delete_this')
    if not os.path.exists(folder):
        os.mkdir(folder)
    f = OneDirFtpClient(ip, user, pw, test_dir)
    f.mkd('delete_this')
    f.delete_folder(folder)
    actual = f.lastresp
    nlst = f.nlst()
    f.quit()
    f.close()
    if not 'delete_this' in nlst:
        n_eq(expected, actual, f, 'delete_folder')
    else:
        print 'nlst:', nlst
        n_ok(False, f, 'delete_folder', message='Folder in nlst')