コード例 #1
0
def test_ta_add_column_bad_type():
    """
    Checks that it rejects unknown types
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    t.add_column('the_name', 'the_type')
コード例 #2
0
def test_ta_add_column_bad_type():
    """
    Checks that it rejects unknown types
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    t.add_column('the_name', 'the_type')
コード例 #3
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')
コード例 #4
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')
コード例 #5
0
def user_setup(ip, port=None, user=None, password=None, root=None): # TODO IP PORT
    if not user:
        print 'TODO'
        user=raw_input("Enter your username: "******"username": user, "root_dir": root, "nick": str(nick),
                "is_syncing": True, "password": password, 'last_sync': "0"}
            path = os.path.expanduser('~') + '/.onedirclient/client.json'
            conf_folder = os.path.expanduser('~') + '/.onedirclient'
            if not os.path.exists(conf_folder):
                os.mkdir(conf_folder)
            with open(path, 'w') as filename:
                json.dump(data, filename)
            watch_folder = os.path.expanduser('~') + '/OneDirFiles'
            if not os.path.exists(watch_folder):
                os.mkdir(watch_folder)
            # ftpclient = OneDirFtpClient(ip, port, user, nick, password, root)
            db = conf_folder + '/sync.db'
            ta = TableAdder(db, 'local')
            ta.add_column('time')
            ta.add_column('cmd')
            ta.add_column('line')
            ta.commit()
            # print 3
        except:
            print 'invalid credentials'
コード例 #6
0
def test_ta_not_exists():
    """
    Checks that it raise a name error if the table does not exists
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    actual = t.done
    del t
    n_ok(not actual, message='Table not added yet')
コード例 #7
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)
コード例 #8
0
def test_ta_commit():
    """
    Checks that the table is added to the database
    @precondition: SqlManager all test - Pass
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    t.add_column('text_column')
    t.add_column('int_column', 'integer')
    t.commit()
    s = SqlManager(db_name)
    actual = table_name in s.tables
    n_ok(actual, t, 'commit', message='finally table added')
コード例 #9
0
ファイル: user_signup.py プロジェクト: Devon-Peroutky/OneDir
def create_user(ip, port, username, password, temppw, nickname, root_dir):
    data = {"username": username, "root_dir": root_dir, "nick": str(nickname),
            "is_syncing": True, "password": password, 'last_sync': "0"}
    path = os.path.expanduser('~') + '/.onedirclient/client.json'
    conf_folder = os.path.expanduser('~') +'/.onedirclient'
    if not os.path.exists(conf_folder):
        os.mkdir(conf_folder)
    with open(path, 'w') as filename:
        json.dump(data, filename)
    ftpclient = OneDirFtpClient(ip, port, username, nickname, temppw, root_dir)
    ftpclient.set_password(temppw, password)
    db = conf_folder + '/sync.db'
    ta = TableAdder(db, 'local')
    ta.add_column('time')
    ta.add_column('cmd')
    ta.add_column('line')
    ta.commit()
コード例 #10
0
def user_setup(ip,
               port=None,
               user=None,
               password=None,
               root=None):  # TODO IP PORT
    if not user:
        print 'TODO'
        user = raw_input("Enter your username: "******"username": user,
                "root_dir": root,
                "nick": str(nick),
                "is_syncing": True,
                "password": password,
                'last_sync': "0"
            }
            path = os.path.expanduser('~') + '/.onedirclient/client.json'
            conf_folder = os.path.expanduser('~') + '/.onedirclient'
            if not os.path.exists(conf_folder):
                os.mkdir(conf_folder)
            with open(path, 'w') as filename:
                json.dump(data, filename)
            watch_folder = os.path.expanduser('~') + '/OneDirFiles'
            if not os.path.exists(watch_folder):
                os.mkdir(watch_folder)
            # ftpclient = OneDirFtpClient(ip, port, user, nick, password, root)
            db = conf_folder + '/sync.db'
            ta = TableAdder(db, 'local')
            ta.add_column('time')
            ta.add_column('cmd')
            ta.add_column('line')
            ta.commit()
            # print 3
        except:
            print 'invalid credentials'
コード例 #11
0
def server_user_add(username, password, is_admin=False):
    if not os.path.isfile('conf.json'):
        print 'Conf file not found, please run setup.'
        sys.exit(1)
    if is_admin:
        status = 1
    else:
        status = 0
    with open('conf.json') as jd:
        template = json.load(jd)
    with TableManager(str(template['user_db']), str(template['user_table'])) as tm:
        salt = gen_salt()
        password = gen_hash(password, salt)
        row = [username, status, password, salt, 'welcome', 'goodbye']
        tm.quick_push(row)
    ta = TableAdder(template['user_logs'], username)
    cols = ['time', 'ip', 'cmd', 'line', 'arg']
    for col in cols:
        ta.add_column(col)
    ta.commit()
    del ta
    user_dir = '%s/%s' % (template['root'], username)  # Untested
    os.mkdir(user_dir)  # Untested
コード例 #12
0
def create_user(ip, port, username, password, temppw, nickname, root_dir):
    data = {
        "username": username,
        "root_dir": root_dir,
        "nick": str(nickname),
        "is_syncing": True,
        "password": password,
        'last_sync': "0"
    }
    path = os.path.expanduser('~') + '/.onedirclient/client.json'
    conf_folder = os.path.expanduser('~') + '/.onedirclient'
    if not os.path.exists(conf_folder):
        os.mkdir(conf_folder)
    with open(path, 'w') as filename:
        json.dump(data, filename)
    ftpclient = OneDirFtpClient(ip, port, username, nickname, temppw, root_dir)
    ftpclient.set_password(temppw, password)
    db = conf_folder + '/sync.db'
    ta = TableAdder(db, 'local')
    ta.add_column('time')
    ta.add_column('cmd')
    ta.add_column('line')
    ta.commit()
コード例 #13
0
def test_ta_commit():
    """
    Checks that the table is added to the database
    @precondition: SqlManager all test - Pass
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    t.add_column('text_column')
    t.add_column('int_column', 'integer')
    t.commit()
    s = SqlManager(db_name)
    actual = table_name in s.tables
    n_ok(actual, t, 'commit', message='finally table added')
コード例 #14
0
def quick_setup(root_dir, admin, password):
    here = os.getcwd()
    template = {'root': root_dir, 'user_db': '%s/users.db' % here, 'user_table': 'users',
                'user_logs': '%s/user_logs.db' % here}
    with open('conf.json', 'w') as w:
        json.dump(template, w)
    ta = TableAdder(template['user_db'], template['user_table'])
    cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
    for col in cols:
        if col == 'status':
            ta.add_column(col, 'integer')
        else:
            ta.add_column(col)
    ta.commit()
    del ta
    server_user_add(admin, password, True)
    print 'Setup completed successfully. Exiting.'
    sys.exit(0)
コード例 #15
0
def quick_setup(root_dir, admin, password):
    here = os.getcwd()
    template = {
        'root': root_dir,
        'user_db': '%s/users.db' % here,
        'user_table': 'users',
        'user_logs': '%s/user_logs.db' % here
    }
    with open('conf.json', 'w') as w:
        json.dump(template, w)
    ta = TableAdder(template['user_db'], template['user_table'])
    cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
    for col in cols:
        if col == 'status':
            ta.add_column(col, 'integer')
        else:
            ta.add_column(col)
    ta.commit()
    del ta
    server_user_add(admin, password, True)
    print 'Setup completed successfully. Exiting.'
    sys.exit(0)
コード例 #16
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)
コード例 #17
0
def server_user_add(username, password, is_admin=False):
    if not os.path.isfile('conf.json'):
        print 'Conf file not found, please run setup.'
        sys.exit(1)
    if is_admin:
        status = 1
    else:
        status = 0
    with open('conf.json') as jd:
        template = json.load(jd)
    with TableManager(str(template['user_db']),
                      str(template['user_table'])) as tm:
        salt = gen_salt()
        password = gen_hash(password, salt)
        row = [username, status, password, salt, 'welcome', 'goodbye']
        tm.quick_push(row)
    ta = TableAdder(template['user_logs'], username)
    cols = ['time', 'ip', 'cmd', 'line', 'arg']
    for col in cols:
        ta.add_column(col)
    ta.commit()
    del ta
    user_dir = '%s/%s' % (template['root'], username)  # Untested
    os.mkdir(user_dir)  # Untested
コード例 #18
0
def setup_module():
    t = TableAdder(db_name, table_name)
    t.add_column('test_column')
    t.commit()
コード例 #19
0
def test_hard_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 some of the columns and have different types
    """
    testing_table = 'ghi'
    ta = TableAdder(db_name, testing_table)
    ta.add_column('col_one')
    ta.add_column('col_two', 'integer')
    ta.add_column('col_three')
    ta.add_column('col_four')
    ta.commit()
    push = ['one', 2, 'three', 'four']
    cl = ['col_one', 'col_two']
    expected = ('one', 2)
    with TableManager(db_name, testing_table) as t:
        t.quick_push(push)
        actual = t.pull(cl)[0]
    n_eq(expected, actual)
コード例 #20
0
def setup_module():
    t = TableAdder(db_name, table_name)
    for val in column_map:
        t.add_column(val[0], val[1])
    t.commit()
コード例 #21
0
def setup_module():
    t = TableAdder(db_name, table_name)
    t.add_column('test_column')
    t.commit()
コード例 #22
0
def setup_module():
    t = TableAdder(db_name, table_name)
    for val in column_map:
        t.add_column(val[0], val[1])
    t.commit()
コード例 #23
0
def test_hard_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 some of the columns and have different types
    """
    testing_table = 'ghi'
    ta = TableAdder(db_name, testing_table)
    ta.add_column('col_one')
    ta.add_column('col_two', 'integer')
    ta.add_column('col_three')
    ta.add_column('col_four')
    ta.commit()
    push = ['one', 2, 'three', 'four']
    cl = ['col_one', 'col_two']
    expected = ('one', 2)
    with TableManager(db_name, testing_table) as t:
        t.quick_push(push)
        actual = t.pull(cl)[0]
    n_eq(expected, actual)
コード例 #24
0
def test_ta_exists():
    """
    Checks it can find a table that exists
    """
    TableAdder(db_name, existing_table_name)
コード例 #25
0
def server_start_testing(is_verbose=False, port=None):
    user_db = 'test_users.db'
    user_table = 'users'
    shares_db = 'test_shares.db'
    username = '******'
    password = '******'
    root = os.getcwd() + '/test_server'
    if os.path.isfile(user_db):
        os.remove(user_db)
    if os.path.isfile(shares_db):
        os.remove(shares_db)
    if os.path.isdir(root):
        rmtree(root)
    os.mkdir(root)
    ta = TableAdder(user_db, user_table)
    cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
    for col in cols:
        if col == 'status':
            ta.add_column(col, 'integer')
        else:
            ta.add_column(col)
    ta.commit()
    del ta
    with TableManager(user_db, user_table) as tm:
        salt = gen_salt()
        password = gen_hash(password, salt)
        row = [username, 1, password, salt, 'welcome', 'goodbye']
        tm.quick_push(row)
    ta = TableAdder(shares_db, username)
    cols = ['time', 'ip', 'cmd', 'line', 'arg']
    for col in cols:
        ta.add_column(col)
    ta.commit()
    del ta
    container.set_acc_db(user_db, user_table)
    container.set_shares_db(shares_db)
    container.set_root_dir(root)
    container.set_log_file(root + '/pyftpd.log')
    auth = authorizer()
    handle = handler
    handle.user_sendfile = True
    handle.timeout = None
    handle.authorizer = auth
    handle.banner = 'this is the banner'
    if port:  # untested
        address = ('', port)
    else:
        address = ('', 21)
    server = FTPServer(address, handle)
    server.max_cons = 256
    server.maxcons_per_ip = 5
    if not is_verbose:
        logging.basicConfig(filename=container.get_log_file(), level=logging.INFO)
    server.serve_forever()
コード例 #26
0
def server_start_testing(is_verbose=False, port=None):
    user_db = 'test_users.db'
    user_table = 'users'
    shares_db = 'test_shares.db'
    username = '******'
    password = '******'
    root = os.getcwd() + '/test_server'
    if os.path.isfile(user_db):
        os.remove(user_db)
    if os.path.isfile(shares_db):
        os.remove(shares_db)
    if os.path.isdir(root):
        rmtree(root)
    os.mkdir(root)
    ta = TableAdder(user_db, user_table)
    cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
    for col in cols:
        if col == 'status':
            ta.add_column(col, 'integer')
        else:
            ta.add_column(col)
    ta.commit()
    del ta
    with TableManager(user_db, user_table) as tm:
        salt = gen_salt()
        password = gen_hash(password, salt)
        row = [username, 1, password, salt, 'welcome', 'goodbye']
        tm.quick_push(row)
    ta = TableAdder(shares_db, username)
    cols = ['time', 'ip', 'cmd', 'line', 'arg']
    for col in cols:
        ta.add_column(col)
    ta.commit()
    del ta
    container.set_acc_db(user_db, user_table)
    container.set_shares_db(shares_db)
    container.set_root_dir(root)
    container.set_log_file(root + '/pyftpd.log')
    auth = authorizer()
    handle = handler
    handle.user_sendfile = True
    handle.timeout = None
    handle.authorizer = auth
    handle.banner = 'this is the banner'
    if port:  # untested
        address = ('', port)
    else:
        address = ('', 21)
    server = FTPServer(address, handle)
    server.max_cons = 256
    server.maxcons_per_ip = 5
    if not is_verbose:
        logging.basicConfig(filename=container.get_log_file(),
                            level=logging.INFO)
    server.serve_forever()