• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python server.userpath2serverpath函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中server.userpath2serverpath函数的典型用法代码示例。如果您正苦于以下问题:Python userpath2serverpath函数的具体用法?Python userpath2serverpath怎么用?Python userpath2serverpath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了userpath2serverpath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_files_post_with_bad_md5

    def test_files_post_with_bad_md5(self):
        """
        Test upload with bad md5.
        """
        user_relative_upload_filepath = 'testupload/testfile.txt'
        upload_test_url = SERVER_FILES_API + user_relative_upload_filepath
        uploaded_filepath = userpath2serverpath(USR, user_relative_upload_filepath)
        assert not os.path.exists(uploaded_filepath), '"{}" file is existing'.format(uploaded_filepath)
        # Create temporary file for test
        test_file, not_used_md5 = _make_temp_file()

        # Create fake md5 and send it instead the right md5
        fake_md5 = 'sent_bad_md5'
        try:
            test = self.app.post(upload_test_url,
                                 headers=make_basicauth_headers(USR, PW),
                                 data={'file': test_file, 'md5': fake_md5},
                                 follow_redirects=True)
        finally:
            test_file.close()
        self.assertEqual(test.status_code, server.HTTP_CONFLICT)
        self.assertFalse(os.path.isfile(userpath2serverpath(USR, user_relative_upload_filepath)))

        # check that uploaded path NOT exists in username files dict
        self.assertNotIn(user_relative_upload_filepath, server.userdata[USR][server.SNAPSHOT])
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:25,代码来源:test_server.py


示例2: test_files_put_with_auth

    def test_files_put_with_auth(self):
        """
        Test put. File content and stored md5 must be changed.
        """
        path = 'test_put/file_to_change.txt'
        _create_file(USR, path, 'I will change')
        to_modify_filepath = userpath2serverpath(USR, path)
        old_content = open(to_modify_filepath).read()
        old_md5 = server.userdata[USR][server.SNAPSHOT][path][1]

        url = SERVER_FILES_API + path
        # Create temporary file for test
        test_file, not_used_md5 = _make_temp_file()

        # Create fake md5 and send it instead the right md5
        fake_md5 = 'sent_bad_md5'
        try:
            test = self.app.put(url,
                                headers=make_basicauth_headers(USR, PW),
                                data={'file': test_file, 'md5': fake_md5},
                                follow_redirects=True)
        finally:
            test_file.close()
        new_content = open(to_modify_filepath).read()
        self.assertEqual(old_content, new_content)
        new_md5 = server.userdata[USR][server.SNAPSHOT][path][1]
        self.assertEqual(old_md5, new_md5)
        self.assertEqual(test.status_code, server.HTTP_CONFLICT)
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:28,代码来源:test_server.py


示例3: build_tstuser_dir

def build_tstuser_dir(username):
    """
    Create a directory with files and return its structure
    in a list.
    :param username: str
    :return: tuple
    """
    # md5("foo") = "acbd18db4cc2f85cedef654fccc4a4d8"
    # md5("bar") = "37b51d194a7513e45b56f6524f2d51f2"
    # md5("spam") = "e09f6a7593f8ae3994ea57e1117f67ec"
    file_contents = [
        ('spamfile', 'spam', 'e09f6a7593f8ae3994ea57e1117f67ec'),
        (os.path.join('subdir', 'foofile.txt'), 'foo', 'acbd18db4cc2f85cedef654fccc4a4d8'),
        (os.path.join('subdir', 'barfile.md'), 'bar', '37b51d194a7513e45b56f6524f2d51f2'),
    ]

    user_root = userpath2serverpath(username)
    # If directory already exists, destroy it
    if os.path.isdir(user_root):
        shutil.rmtree(user_root)
    os.mkdir(user_root)
    expected_timestamp = None
    expected_snapshot = {}
    for user_filepath, content, md5 in file_contents:
        expected_timestamp = int(_create_file(username, user_filepath, content))
        expected_snapshot[user_filepath] = [expected_timestamp, unicode(md5)]
    return expected_timestamp, expected_snapshot
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:27,代码来源:test_server.py


示例4: create_user_dir

def create_user_dir(username):
    """
    Create user directory (must not exist)
    :param username:
    :return:
    """
    os.makedirs(userpath2serverpath(username))
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:7,代码来源:test_server.py


示例5: test_files_put_with_bad_md5

    def test_files_put_with_bad_md5(self):
        """
        Test modify with bad md5.
        """
        path = 'test_put/file_to_change.txt'
        _create_file(USR, path, 'I will NOT change')
        to_modify_filepath = userpath2serverpath(USR, path)
        old_content = open(to_modify_filepath).read()
        old_md5 = server.userdata[USR][server.SNAPSHOT][path][1]

        url = SERVER_FILES_API + path
        # Create temporary file for test
        test_file, test_md5 = _make_temp_file()
        try:
            test = self.app.put(url,
                                headers=make_basicauth_headers(USR, PW),
                                data={'file': test_file, 'md5': test_md5},
                                follow_redirects=True)
        finally:
            test_file.close()
        new_content = open(to_modify_filepath).read()
        self.assertNotEqual(old_content, new_content)
        new_md5 = server.userdata[USR][server.SNAPSHOT][path][1]
        self.assertNotEqual(old_md5, new_md5)
        self.assertEqual(test.status_code, server.HTTP_CREATED)  # 200 or 201 (OK or created)?
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:25,代码来源:test_server.py


示例6: test_files_post_with_existent_path

    def test_files_post_with_existent_path(self):
        """
        Test the creation of file that already exists.
        """
        path = 'test_put/file_to_change.txt'  # path already existent
        _create_file(USR, path, 'I already exist! Don\'t erase me!')
        to_created_filepath = userpath2serverpath(USR, path)
        old_content = open(to_created_filepath).read()
        old_md5 = server.userdata[USR][server.SNAPSHOT][path][1]

        url = SERVER_FILES_API + path

        # Create temporary file for test
        test_file, test_md5 = _make_temp_file()
        try:
            test = self.app.post(url,
                                 headers=make_basicauth_headers(USR, PW),
                                 data={'file': test_file, 'md5': test_md5},
                                 follow_redirects=True)
        finally:
            test_file.close()
        self.assertEqual(test.status_code, server.HTTP_FORBIDDEN)
        new_content = open(to_created_filepath).read()
        self.assertEqual(old_content, new_content)
        new_md5 = server.userdata[USR][server.SNAPSHOT][path][1]
        self.assertEqual(old_md5, new_md5)
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:26,代码来源:test_server.py


示例7: test_delete_user

    def test_delete_user(self):
        """
        User deletion.
        """
        # Creating user to delete on-the-fly (TODO: pre-load instead)
        _manually_create_user(USR, PW)
        user_dirpath = userpath2serverpath(USR)
        # Really created?
        assert USR in server.userdata, 'Utente "{}" non risulta tra i dati'.format(USR)  # TODO: translate
        assert os.path.exists(user_dirpath), 'Directory utente "{}" non trovata'.format(USR)  # TODO: translate

        # Test FORBIDDEN case (removing other users)
        url = SERVER_API + 'users/' + 'otheruser'
        test = self.app.delete(url,
                               headers=make_basicauth_headers(USR, PW))
        self.assertEqual(test.status_code, server.HTTP_FORBIDDEN)

        # Test OK case
        url = SERVER_API + 'users/' + USR
        test = self.app.delete(url,
                               headers=make_basicauth_headers(USR, PW))

        self.assertNotIn(USR, server.userdata)
        self.assertEqual(test.status_code, server.HTTP_OK)
        self.assertFalse(os.path.exists(user_dirpath))
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:25,代码来源:test_server.py


示例8: test_consistence_after_actions

    def test_consistence_after_actions(self):
        """
        Complex test that do several actions and finally test the consistence.
        """
        # create user
        user = 'pippo'
        _manually_create_user(user, 'pass')

        # post
        _create_file(user, 'new_file', 'ciao!!!')
        url = SERVER_FILES_API + 'new_file'
        self.app.post(url, headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(USR, PW))})

        # move
        move_test_url = SERVER_ACTIONS_API + 'move'
        src_move_test_file_path = 'test_move_src/testmovesrc.txt'
        dst_move_test_file_path = 'test_move_dst/testmovedst.txt'
        #create source file to be moved and its destination
        _create_file(user, src_move_test_file_path, 'this is the file to be moved')
        test = self.app.post(move_test_url,
                             headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(user, 'pass'))},
                             data={'src': src_move_test_file_path, 'dst': dst_move_test_file_path},
                             follow_redirects=True)

        # copy
        copy_test_url = SERVER_FILES_API + 'copy'
        test = self.app.post(copy_test_url,
                             headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(user, 'pass'))},
                             data={'src': src_move_test_file_path, 'dst': dst_move_test_file_path},
                             follow_redirects=True)

        # intermediate check
        dic_state, dir_state = get_dic_dir_states()
        self.assertEqual(dic_state, dir_state)

        # create other user
        user, pw = 'pluto', 'pw'
        _manually_create_user(user, pw)
        # post a file
        path = 'dir/dirfile.txt'
        _create_file(user, path, 'dirfile content...')
        self.app.post(SERVER_FILES_API + path,
                      headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(user, pw))})

        # delete it
        self.app.post(SERVER_FILES_API + 'delete',
                      headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(user, pw))},
                      data={'filepath': path})

        # final check
        dic_state, dir_state = get_dic_dir_states()
        self.assertEqual(dic_state, dir_state)

        # Now I manually delete a file in the server and must be NOT synchronized!
        os.remove(userpath2serverpath(user, 'WELCOME'))
        dic_state, dir_state = get_dic_dir_states()
        self.assertNotEqual(dic_state, dir_state)  # NOT EQUAL
开发者ID:luca0314,项目名称:share-system-team2,代码行数:57,代码来源:test_server.py


示例9: setUp

    def setUp(self):
        setup_test_dir()
        server.reset_userdata()

        self.app = server.app.test_client()
        self.app.testing = True

        self.username = USR
        self.password = PW
        self.user_dirpath = userpath2serverpath(self.username)
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:10,代码来源:test_server.py


示例10: test_files_post_with_not_allowed_path

 def test_files_post_with_not_allowed_path(self):
     """
     Test that creating a directory upper than the user root is not allowed.
     """
     user_filepath = '../../../test/myfile2.dat'  # path forbidden
     url = SERVER_FILES_API + user_filepath
     test = self.app.post(url,
                          headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(USR, PW))},
                          data=dict(file=(io.BytesIO(b'this is a test'), 'test.pdf'),), follow_redirects=True)
     self.assertEqual(test.status_code, server.HTTP_FORBIDDEN)
     self.assertFalse(os.path.isfile(userpath2serverpath(USR, user_filepath)))
开发者ID:luca0314,项目名称:share-system-team2,代码行数:11,代码来源:test_server.py


示例11: test_unexisting_username

    def test_unexisting_username(self):
        """
        Not existing username and existing activation_code.
        """
        unexisting_user = 'unexisting'
        test = self.app.put(urlparse.urljoin(SERVER_API, 'users/' + unexisting_user),
                            data={'activation_code': self.activation_code})

        self.assertEqual(test.status_code, HTTP_NOT_FOUND)
        self.assertNotIn(unexisting_user, server.userdata.keys())
        self.assertFalse(os.path.exists(userpath2serverpath(unexisting_user)))
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:11,代码来源:test_server.py


示例12: _manually_remove_user

def _manually_remove_user(username):  # TODO: make this from server module?
    """
    Remove user dictionary from server <userdata>, if exist,
    and remove its directory from disk, if exist.
    :param username: str
    """
    if USR in server.userdata:
        server.userdata.pop(username)
    # Remove user directory if exists!
    user_dirpath = userpath2serverpath(USR)
    if os.path.exists(user_dirpath):
        shutil.rmtree(user_dirpath)
        logging.debug('"%s" user directory removed' % user_dirpath)
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:13,代码来源:test_server.py


示例13: get_dic_dir_states

def get_dic_dir_states():
    """
    Return a tuple with dictionary state and directory state of all users.
    NB: Passwords are removed from the dictionary states.
    :return: tuple
    """
    dic_state = {}
    dir_state = {}
    for username in server.userdata:
        single_user_data = server.userdata[username].copy()
        single_user_data.pop(server.PASSWORD)  # not very beautiful
        dic_state[username] = single_user_data
        dir_state[username] = server.compute_dir_state(userpath2serverpath(username))
    return dic_state, dir_state
开发者ID:luca0314,项目名称:share-system-team2,代码行数:14,代码来源:test_server.py


示例14: test_copy_file_path_with_unexisting_destinationfile

    def test_copy_file_path_with_unexisting_destinationfile(self):
        """
        Test the creation of a destination file if this one doesn't exists from the beginning.
        """
        copy_test_url = SERVER_ACTIONS_API + 'copy'
        src_copy_test_file_path = 'test_copy_src/testcopysrc.txt'
        dst_copy_test_file_path = 'test_copy_dst/testcopydst.txt'
        # Create source file to be copied and its destination.
        src_copy_filepath = userpath2serverpath(USR, src_copy_test_file_path)

        _create_file(USR, src_copy_test_file_path, 'this is the file to be copied')

        test = self.app.post(copy_test_url,
                             headers=make_basicauth_headers(USR, PW),
                             data={'src': src_copy_test_file_path, 'dst': dst_copy_test_file_path},
                             follow_redirects=True)

        self.assertEqual(test.status_code, server.HTTP_OK)
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:18,代码来源:test_server.py


示例15: test_delete_file_path

    def test_delete_file_path(self):
        """
        Test if a created file is deleted and assures it doesn't exists anymore with assertFalse
        """
        # create file to be deleted
        delete_test_url = SERVER_ACTIONS_API + 'delete'
        delete_test_file_path = 'testdelete/testdeletefile.txt'
        to_delete_filepath = userpath2serverpath(USR, delete_test_file_path)

        _create_file(USR, delete_test_file_path, 'this is the file to be deleted')

        test = self.app.post(delete_test_url,
                             headers=make_basicauth_headers(USR, PW),
                             data={'filepath': delete_test_file_path}, follow_redirects=True)

        self.assertEqual(test.status_code, server.HTTP_OK)
        self.assertFalse(os.path.isfile(to_delete_filepath))
        self.assertNotIn(delete_test_file_path, server.userdata[USR][server.SNAPSHOT])
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:18,代码来源:test_server.py


示例16: test_move_file_path

    def test_move_file_path(self):
        """
        Test if a created source file is moved in a new created destination and assures the source file
        doesn't exists after
        """
        move_test_url = SERVER_ACTIONS_API + 'move'
        src_move_test_file_path = 'test_move_src/testmovesrc.txt'
        dst_move_test_file_path = 'test_move_dst/testmovedst.txt'
        #create source file to be moved and its destination
        src_move_filepath = userpath2serverpath(USR, src_move_test_file_path)

        _create_file(USR, src_move_test_file_path, 'this is the file to be moved')

        test = self.app.post(move_test_url,
                             headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(USR, PW))},
                             data={'src': src_move_test_file_path, 'dst': dst_move_test_file_path}, follow_redirects=True)

        self.assertEqual(test.status_code, server.HTTP_OK)
        self.assertFalse(os.path.isfile(src_move_filepath))
开发者ID:luca0314,项目名称:share-system-team2,代码行数:19,代码来源:test_server.py


示例17: test_files_post_with_not_allowed_path

 def test_files_post_with_not_allowed_path(self):
     """
     Test that creating a directory upper than the user root is not allowed.
     """
     user_filepath = '../../../test/myfile2.dat'  # path forbidden
     url = SERVER_FILES_API + user_filepath
     # Create temporary file for test
     test_file, test_md5 = _make_temp_file()
     try:
         test = self.app.post(url,
                              headers=make_basicauth_headers(USR, PW),
                              data={'file': test_file, 'md5': test_md5},
                              follow_redirects=True)
     finally:
         test_file.close()
     self.assertEqual(test.status_code, server.HTTP_FORBIDDEN)
     self.assertFalse(os.path.isfile(userpath2serverpath(USR, user_filepath)))
     # check that uploaded path NOT exists in username files dict
     self.assertNotIn(user_filepath, server.userdata[USR][server.SNAPSHOT])
开发者ID:giornaledisistema,项目名称:share-system-team2,代码行数:19,代码来源:test_server.py


示例18: test_files_post_with_auth

    def test_files_post_with_auth(self):
        """
        Test for authenticated upload.
        """
        user_relative_upload_filepath = 'testupload/testfile.txt'
        upload_test_url = SERVER_FILES_API + user_relative_upload_filepath
        uploaded_filepath = userpath2serverpath(USR, user_relative_upload_filepath)
        assert not os.path.exists(uploaded_filepath), '"{}" file is existing'.format(uploaded_filepath)

        test = self.app.post(upload_test_url,
                             headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(USR, PW))},
                             data=dict(file=(io.BytesIO(b'this is a test'), 'test.pdf'),),
                             follow_redirects=True)
        self.assertEqual(test.status_code, server.HTTP_CREATED)
        self.assertTrue(os.path.isfile(uploaded_filepath))
        # check that uploaded path exists in username files dict
        self.assertIn(user_relative_upload_filepath, server.userdata[USR][server.SNAPSHOT])
        os.remove(uploaded_filepath)
        logging.info('"{}" removed'.format(uploaded_filepath))
开发者ID:luca0314,项目名称:share-system-team2,代码行数:19,代码来源:test_server.py


示例19: test_signup

 def test_signup(self):
     """
     Test for registration of a new user.
     """
     test = self.app.post(urlparse.urljoin(SERVER_API, 'signup'),
                          data={'username': USR, 'password': PW})
     # test that userdata is actually updated
     single_user_data = server.userdata[USR]
     self.assertIn(USR, server.userdata)
     # test single user data structure (as currently defined)
     self.assertIsInstance(single_user_data, dict)
     self.assertIn(server.LAST_SERVER_TIMESTAMP, single_user_data)
     self.assertIn(server.SNAPSHOT, single_user_data)
     self.assertIsInstance(single_user_data[server.LAST_SERVER_TIMESTAMP], int)
     self.assertIsInstance(single_user_data[server.SNAPSHOT], dict)
     # test that the user directory is created
     user_dirpath = userpath2serverpath(USR)
     self.assertTrue(os.path.isdir(user_dirpath))
     # test server response
     self.assertEqual(test.status_code, server.HTTP_CREATED)
开发者ID:luca0314,项目名称:share-system-team2,代码行数:20,代码来源:test_server.py


示例20: test_files_put_with_auth

    def test_files_put_with_auth(self):
        """
        Test put. File content and stored md5 must be changed.
        """
        path = 'test_put/file_to_change.txt'
        _create_file(USR, path, 'I will change')
        to_modify_filepath = userpath2serverpath(USR, path)
        old_content = open(to_modify_filepath).read()
        old_md5 = server.userdata[USR][server.SNAPSHOT][path][1]

        url = SERVER_FILES_API + path
        test = self.app.put(url,
                            headers={'Authorization': 'Basic ' + base64.b64encode('{}:{}'.format(USR, PW))},
                            data=dict(file=(io.BytesIO(b'I have changed'), 'foo.foo')), follow_redirects=True)

        new_content = open(to_modify_filepath).read()
        self.assertNotEqual(old_content, new_content)
        new_md5 = server.userdata[USR][server.SNAPSHOT][path][1]
        self.assertNotEqual(old_md5, new_md5)
        self.assertEqual(test.status_code, server.HTTP_CREATED)  # 200 or 201 (OK or created)?
开发者ID:luca0314,项目名称:share-system-team2,代码行数:20,代码来源:test_server.py



注:本文中的server.userpath2serverpath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python server.FILES类代码示例发布时间:2022-05-27
下一篇:
Python server.start函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap