def test_upload_resume(server): close_server = threading.Event() with SwapAttr(server.client, 'host', 'http://localhost:8081/nuxeo/'): try: serv = Server.upload_response_server( wait_to_close_event=close_server, port=8081, requests_to_handle=20, fail_args={ 'fail_at': 4, 'fail_number': 3 }) file_in = 'test_in' with serv: batch = server.uploads.batch() with open(file_in, 'wb') as f: f.write(b'\x00' + os.urandom(1024 * 1024) + b'\x00') blob = FileBlob(file_in, mimetype='application/octet-stream') with pytest.raises(UploadError) as e: batch.upload(blob, chunked=True, chunk_size=256 * 1024) assert text(e.value) batch.upload(blob, chunked=True, chunk_size=256 * 1024) close_server.set() # release server block finally: try: os.remove(file_in) except OSError: pass
def test_server_version(server): assert server.client.server_version assert str(server.client) # Bad call server.client._server_info = None with SwapAttr(server.client, 'host', 'http://example.org/'): assert not server.client.server_version
def test_check_params_constant(server): operation = server.operations.new('Document.GetChild') operation.params = {'name': 'workspaces', 'alien': 'the return'} operation.input_obj = '/default-domain' # Should not fail here assert not constants.CHECK_PARAMS operation.execute() # But should fail now with SwapAttr(constants, 'CHECK_PARAMS', True): with pytest.raises(BadQuery): operation.execute()
def test_server_info(server): # At start, no server information with pytest.raises(AttributeError): server.client._server_info # First call assert server.client.server_info() assert isinstance(server.client.server_info(), dict) # Force the call server.client._server_info = None assert server.client.server_info(force=True) assert server.client.server_info() == server.client.server_info(force=True) # Bad call server.client._server_info = None with SwapAttr(server.client, 'host', 'http://example.org/'): assert not server.client.server_info()
def test_server_reachable(server): assert server.client.is_reachable() with SwapAttr(server.client, 'host', 'http://example.org'): assert not server.client.is_reachable() assert server.client.is_reachable()
def test_encoding_404_error(server): with SwapAttr(server.client, 'host', 'http://localhost:8080/'): with pytest.raises((ConnectionError, HTTPError)) as e: server.documents.get(path='/') if isinstance(e, HTTPError): assert e.value.status == 404
def test_guess_mimetype_patch(): """ Test WIN32_PATCHED_MIME_TYPES. """ with SwapAttr(sys, 'platform', 'win32'): assert guess_mimetype('foo.ppt')
def test_add_permission(server): users = ["Administrator"] with SwapAttr(nuxeo.constants, 'CHECK_PARAMS', True), Doc(server) as doc: # NXPY-84: here we should not fail with KeyError: 'list' in check_params() doc.add_permission({"permission": "ReadWrite", "users": users})