Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docbuilder python wrapper smoke tests #1212

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ doc

# other
.vscode
__pycache__
5 changes: 0 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ desc 'run project spec'
task :project_spec do
system('bundle exec parallel_rspec project_spec')
end

desc 'run python spec'
task :python_spec do
system('bundle exec parallel_rspec python_spec')
end
Binary file added assets/python_wrapper_test_files/OpenFile.docx
Binary file not shown.
4 changes: 4 additions & 0 deletions assets/python_wrapper_test_files/run.docbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is a paragraph for Run");
oDocument.Push(oParagraph);
3 changes: 1 addition & 2 deletions lib/doc_builder_testing/doc_builder_python_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def build(script_file)

# Build document and parse it
# @param script_file [String] path to script file
# @return [OoxmlParser::CommonDocumentStructure] parsed file if file is Ooxml
# @return [OnlyofficePdfParser::PdfStructure] parsed structure if file is PDF
# @return [OnlyofficePdfParser::PdfStructure, OoxmlParser::Parser, nil] parsed file if file is Ooxml or structure if file is PDF
def build_and_parse(script_file)
temp_script_data = build_file(script_file)
parse(temp_script_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

content = context.CreateArray(1)
content[0] = paragraph

document.Call("InsertContent", content)
builder.SaveFile("docx", "result.docx")

builder.SaveFile("docx", "BaseExample.docx")
builder.CloseFile()
20 changes: 20 additions & 0 deletions python/wrapper/smoke/doc_builder/execute_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

builder.ExecuteCommand('Argument = {"some key": "Some ExecuteCommand value"}')
document = api.Call("GetDocument")
paragraph = api.Call("CreateParagraph")
argument = globalObj['Argument']
paragraph.Call("AddText", argument["some key"].ToString())

content = context.CreateArray(1)
content[0] = paragraph
document.Call("InsertContent", content)

builder.SaveFile("docx", "ExecuteCommand.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder/get_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "If this paragraph is here, GetContext works")

builder.SaveFile("docx", "GetContext.docx")
builder.CloseFile()
20 changes: 20 additions & 0 deletions python/wrapper/smoke/doc_builder/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

version = builder.GetVersion()
document = api.Call("GetDocument")
paragraph = api.Call("CreateParagraph")
paragraph.Call("SetSpacingAfter", 1000, False)
paragraph.Call("AddText", version.decode())

content = context.CreateArray(1)
content[0] = paragraph
document.Call("InsertContent", content)

builder.SaveFile("docx", "GetVersion.docx")
builder.CloseFile()
16 changes: 16 additions & 0 deletions python/wrapper/smoke/doc_builder/is_save_with_doctrenderer_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
from python.docbuilder import builder
builder.SetProperty('--use-doctrenderer-scheme', 'true')
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", f"IsSaveWithDoctrendererMode = {builder.IsSaveWithDoctrendererMode()}")

builder.SaveFile("docx", "IsSaveWithDoctrendererMode.docx")
builder.CloseFile()
5 changes: 5 additions & 0 deletions python/wrapper/smoke/doc_builder/open_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from python.docbuilder import builder
builder.OpenFile("assets/python_wrapper_test_files/OpenFile.docx",
"<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>")
builder.SaveFile("docx", "OpenFile.docx")
builder.CloseFile()
5 changes: 5 additions & 0 deletions python/wrapper/smoke/doc_builder/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from python.docbuilder import builder
builder.CreateFile("docx")
builder.Run("assets/python_wrapper_test_files/run.docbuilder")
builder.SaveFile("docx", "Run.docx")
builder.CloseFile()
10 changes: 10 additions & 0 deletions python/wrapper/smoke/doc_builder/run_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from python.docbuilder import builder
builder.CreateFile("docx")
builder.RunText("""
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is a paragraph for RunText");
oDocument.Push(oParagraph);
""")
builder.SaveFile("docx", "RunText.docx")
builder.CloseFile()
3 changes: 3 additions & 0 deletions python/wrapper/smoke/doc_builder/save_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from python.docbuilder import builder
builder.CreateFile("docx")
builder.SaveFile("docx", "SaveFile.docx")
21 changes: 21 additions & 0 deletions python/wrapper/smoke/doc_builder/set_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import json
from python.docbuilder import builder
builder.SetProperty("--argument", json.dumps({"some key": "Some SetProperty value"}))
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = api.Call("CreateParagraph")
argument = globalObj['Argument']
paragraph.Call("AddText", argument["some key"].ToString())

content = context.CreateArray(1)
content[0] = paragraph
document.Call("InsertContent", content)

builder.SaveFile("docx", "SetProperty.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder/set_tmp_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder

builder.SetTmpFolder("tmp/folder")
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = api.Call("CreateParagraph")
scope.Close()
paragraph.Call("AddText", "Hello, World!")
2 changes: 2 additions & 0 deletions python/wrapper/smoke/doc_builder/write_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from python.docbuilder import builder
builder.WriteData("WriteData.log", "Check", False)
22 changes: 22 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call('GetDocument')
paragraph1 = api.Call('CreateParagraph')
paragraph1.Call('SetSpacingAfter', 1000, False)
paragraph1.Call('AddText', 'CreateArray')
paragraph2 = api.Call('CreateParagraph')
paragraph2.Call('AddText', 'test')

content = context.CreateArray(2)
content[0] = paragraph1
content[1] = paragraph2
document.Call('InsertContent', content)

builder.SaveFile("docx", "CreateArray.docx")
builder.CloseFile()
15 changes: 15 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
value = context.CreateNull()
paragraph.Call("AddText", f"Value is null = {value.IsNull()}")

builder.SaveFile("docx", "CreateNull.docx")
builder.CloseFile()
15 changes: 15 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
value = context.CreateObject()
paragraph.Call("AddText", f"Value is object = {value.IsObject()}")

builder.SaveFile("docx", "CreateObject.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "Without CreateScope script doesn't work")

builder.SaveFile("docx", "CreateScope.docx")
builder.CloseFile()
15 changes: 15 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_undefined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
value = context.CreateUndefined()
paragraph.Call("AddText", f"Value is undefined = {value.IsUndefined()}")

builder.SaveFile("docx", "CreateUndefined.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder_context/get_global.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "If this paragraph is here, GetGlobal works")

builder.SaveFile("docx", "GetGlobal.docx")
builder.CloseFile()
8 changes: 8 additions & 0 deletions python/wrapper/smoke/doc_builder_context/is_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from python.docbuilder import builder
builder.CreateFile("docx")
result = builder.RunText("""
var oDocument = Api.GetDocument();
var oParagraph = Api.GetParagraph(0);
""")
builder.SaveFile("docx", "IsError.docx")
builder.CloseFile()
15 changes: 15 additions & 0 deletions python/wrapper/smoke/doc_builder_context_scope/close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
scope.Close()
paragraph.Call("AddText", "Without created scope script doesn't works")

builder.SaveFile("docx", "Close.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder_value/call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "This is Call method check")

builder.SaveFile("docx", "Call.docx")
builder.CloseFile()
19 changes: 19 additions & 0 deletions python/wrapper/smoke/doc_builder_value/clear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
new_paragraph = api.Call("CreateParagraph")
new_paragraph.Call("AddText", "some content")
paragraph.Call("AddText", f"before clear: {new_paragraph.IsEmpty()}")
paragraph.Call("AddLineBreak")
new_paragraph.Clear()
paragraph.Call("AddText", f"after clear: {new_paragraph.IsEmpty()}")

builder.SaveFile("docx", "Clear.docx")
builder.CloseFile()
18 changes: 18 additions & 0 deletions python/wrapper/smoke/doc_builder_value/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "Some text for Get method")

paragraphs = document.Call("GetAllParagraphs")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f'Text is {paragraphs.Get(0).Call("GetText").ToString()}')

builder.SaveFile("docx", "Get.docx")
builder.CloseFile()
26 changes: 26 additions & 0 deletions python/wrapper/smoke/doc_builder_value/get_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
run1 = api.Call("CreateRun")
run1.Call("AddText", "First run")
paragraph.Call("AddElement", run1)
run1.Call("AddComment", "Comment one", "John", "uid-1")
paragraph.Call("AddLineBreak")
run2 = api.Call("CreateRun")
run2.Call("AddText", "Second run")
paragraph.Call("AddElement", run2)
run2.Call("AddComment", "Comment two", "Jane", "uid-2")

comments = document.Call("GetAllComments")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Comments GetLength = {comments.GetLength()}")

builder.SaveFile("docx", "GetLength.docx")
builder.CloseFile()
Loading
Loading