Exemplo n.º 1
0
    def test_parse_propfind(self):
        with open(
                os.path.join(this_dir, 'webdav_propfind_response_example.xml'),
                'r') as f:
            propfind_xml = f.read()

        stor = ContraxsuiteWebDAVFileStorage('http://localhost:8090/', 'user',
                                             'password')

        files = [
            fn for fn, is_dir in stor.parse_propfind_response(
                '/documents/dav spaces supported test/', propfind_xml)
            if not is_dir
        ]

        self.assertEqual(files, [
            'documents/davtest/1001635_1998-03-26_10 Spaces should be decoded.txt',
            'documents/davtest/1002037_2005-10-11_2.txt',
            'documents/davtest/1002037_2005-08-09_4.txt'
        ])

        # this time we provide non-relevant path to exclude and it should return the single dir
        dirs = [
            fn for fn, is_dir in ContraxsuiteWebDAVFileStorage().
            parse_propfind_response('something', propfind_xml) if is_dir
        ]

        self.assertEqual(dirs, ['documents/dav spaces supported test'])
Exemplo n.º 2
0
def get_file_storage() -> ContraxsuiteFileStorage:
    access_type = settings.CONTRAX_FILE_STORAGE_TYPE
    if access_type == 'Local':
        return ContraxsuiteLocalFileStorage()  # singleton - always returns the same instance
    elif access_type == 'WebDAV':
        return ContraxsuiteWebDAVFileStorage()
    else:
        raise Exception(f'Unknown file storage type: {access_type}')