Esempio n. 1
0
 def test_FileRequest__init__(self):
     domain = 'default'
     file_path = 'local/dir/subdir/get.js'
     content = 'aGVsbG8gd29ybGQK'
     req = FileRequest()
     req.set_path(domain=domain, file_path=file_path)
     req.set_body(file_path=file_path, content=content)
     assert req.path == '/mgmt/filestore/default/local/dir/subdir/get.js'
     assert req.body == {'file': {'name': 'get.js', 'content': content}}
Esempio n. 2
0
 def test_FileRequest_get(self):
     domain = 'default'
     file_path = 'local/dir/subdir/get.js'
     content = 'aGVsbG8gd29ybGQK'
     req = FileRequest()
     req.set_path(domain=domain, file_path=file_path)
     req.set_body(file_path=file_path, content=content)
     assert req.get(
     )['path'] == '/mgmt/filestore/default/local/dir/subdir/get.js'
     assert req.get()['method'] == 'GET'
     assert not req.get()['data']
Esempio n. 3
0
 def test_FileRequest_update(self):
     domain = 'default'
     file_path = 'local/dir/subdir/get.js'
     content = 'aGVsbG8gd29ybGQK'
     req = FileRequest()
     req.set_path(domain=domain, file_path=file_path)
     req.set_body(file_path=file_path, content=content)
     assert req.put(
     )['path'] == '/mgmt/filestore/default/local/dir/subdir/get.js'
     assert req.put()['method'] == 'PUT'
     assert req.put()['data'] == {
         'file': {
             'name': 'get.js',
             'content': content
         }
     }
Esempio n. 4
0
    def test_FileRequest_set_path_strips_leading_forward_path(self):
        domain = 'default'
        file_path = '/local/dir/subdir/get.js'
        content = 'aGVsbG8gd29ybGQK'
        req = FileRequest()
        req.set_path(domain=domain, file_path=file_path)
        req.set_body(file_path=file_path, content=content)

        assert req.post()['path'] == '/mgmt/filestore/default/local/dir/subdir'
        assert req.post()['method'] == 'POST'
        assert req.post()['data'] == {
            'file': {
                'name': 'get.js',
                'content': content
            }
        }
Esempio n. 5
0
def build_file_request(domain, file_path, data):
    top_dir = file_path.split('/')[0] or posixpath.split(file_path)[0]

    if isBase64(data):
        data_base64 = data
    else:
        data_base64 = base64.b64encode(data).decode()

    file_req = FileRequest()
    # sharedcert is global and can only be used through the default domain.
    if 'sharedcert' in top_dir:
        file_req.set_path(domain='default', file_path=file_path)
    else:
        file_req.set_path(domain=domain, file_path=file_path)
    file_req.set_body(file_path=file_path, content=data_base64)
    return file_req