mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
initial commit
This commit is contained in:
commit
18933c6767
1841 changed files with 810642 additions and 0 deletions
40
sdk/exttest/apibenchmark.go
Normal file
40
sdk/exttest/apibenchmark.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
// APIbenchmark is the main entry point for the benchmark code, it is called by both internal and external tests.
|
||||
func APIbenchmark() error {
|
||||
testEndPt := os.Getenv("DOCUMIZEAPI") //e.g. "http://localhost:5002"
|
||||
testAuth := os.Getenv("DOCUMIZEAUTH") //e.g. "demo1:jim@davidson.com:demo123"
|
||||
c, err := documize.NewClient(testEndPt, testAuth) // should work
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
folders, err := c.GetNamedFolderIDs("Test")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(folders) == 0 {
|
||||
return errors.New("no Test folder for test user")
|
||||
}
|
||||
testFolder := folders[0]
|
||||
_ = testFolder
|
||||
// TODO add benchmark code
|
||||
return nil
|
||||
}
|
339
sdk/exttest/apitest.go
Normal file
339
sdk/exttest/apitest.go
Normal file
|
@ -0,0 +1,339 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/documize/community/documize/api/entity"
|
||||
"github.com/documize/community/sdk"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testFileName string
|
||||
|
||||
func setupTestFile() error {
|
||||
testFileName = os.TempDir()
|
||||
if !strings.HasSuffix(testFileName, string(os.PathSeparator)) {
|
||||
testFileName += string(os.PathSeparator)
|
||||
}
|
||||
testFileName += "TESTDATA.html"
|
||||
return ioutil.WriteFile(testFileName, []byte(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>TESTDATA Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>TESTDATA Heading</h1>
|
||||
<p>TESTDATA paragraph.</p>
|
||||
</body>
|
||||
</html>
|
||||
`), os.ModePerm)
|
||||
}
|
||||
|
||||
// APItest is the main entry point for the test code, it is called by both internal and external tests.
|
||||
func APItest(t *testing.T) {
|
||||
setupTestFile()
|
||||
defer os.Remove(testFileName) // ignore error
|
||||
|
||||
c, err := auth(t)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
if c == nil {
|
||||
t.Error("unable to log-in to Documize, nil pointer returned")
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
t.Logf("INFO: Auth client=%#v\n", *c)
|
||||
|
||||
testMeta(t, c)
|
||||
|
||||
// create a testing folder here, with a defer to remove it
|
||||
myFolder := &entity.Label{
|
||||
Name: "Folder created during Go unit tests",
|
||||
// OrgID is set by the endpoint
|
||||
UserID: c.Auth.User.RefID,
|
||||
Type: 2, // only the user can see it
|
||||
}
|
||||
err = c.AddFolder(myFolder)
|
||||
if err != nil {
|
||||
t.Error("c.AddFolder():", err)
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
// find a folder to move the deleted myFolder's contents to
|
||||
fids, err := c.GetNamedFolderIDs("Test")
|
||||
if err != nil {
|
||||
t.Error("c.GetNamedFolderIDs():", err)
|
||||
t.Fail()
|
||||
}
|
||||
if len(fids) == 0 {
|
||||
t.Error("can't find a folder named Test")
|
||||
t.Fail()
|
||||
}
|
||||
reserveFolder := fids[0] // use the 1st we found
|
||||
defer func() {
|
||||
err = c.RemoveFolder(myFolder.RefID, reserveFolder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
testFolder := myFolder.RefID
|
||||
if testFolder == "" {
|
||||
t.Error("myFolder.RefID is empty!")
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
t.Log("INFO: myFolder.RefID='" + testFolder + "'")
|
||||
|
||||
testFile := loadFile(c, t, testFolder, testFileName)
|
||||
testData := loadData(c, t, testFolder)
|
||||
|
||||
testPages(t, c, testFolder, testFile, testData)
|
||||
|
||||
testFolderAPI(t, c, testFolder, testFile)
|
||||
testSearch(t, c, testFolder, testFile)
|
||||
testDownload(t, c, testFolder, testFile)
|
||||
|
||||
testGetUpdDocument(t, c, testFile, testData)
|
||||
testGetDocumentMeta(t, c, testFile, testData)
|
||||
testDocAttachments(t, c, testFile, testData)
|
||||
testTemplates(t, c, testFolder, testFile, testData)
|
||||
testDelete(t, c, testFile, testData)
|
||||
|
||||
testOrg(t, c)
|
||||
testFolders(t, c, myFolder)
|
||||
testUsers(t, c)
|
||||
|
||||
}
|
||||
|
||||
func testOrg(t *testing.T, c *documize.Client) {
|
||||
orgs, err := c.GetOrganizations()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: organizations = %#v", orgs)
|
||||
}
|
||||
if len(orgs) > 0 {
|
||||
err = c.UpdateOrganization(&orgs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// TODO actually check that the update did what we expected
|
||||
}
|
||||
}
|
||||
|
||||
func testGetUpdDocument(t *testing.T, c *documize.Client, testFile, testData string) {
|
||||
var err error
|
||||
doc, err := c.GetDocument(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if doc.RefID != testFile {
|
||||
t.Error("wrong RefId got", doc.RefID, "want", testFile)
|
||||
}
|
||||
}
|
||||
|
||||
err = c.UpdateDocument(doc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// NOTE updates to unknown documents do not generate errors
|
||||
|
||||
docData, err := c.GetDocument(testData)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if docData.BaseEntity.RefID != testData {
|
||||
t.Error("wrong RefID want", testData, "got", docData.RefID)
|
||||
}
|
||||
if _, err = c.GetDocument(""); err == nil {
|
||||
t.Error("GetDocument did not error on empty DocumentID")
|
||||
} else {
|
||||
t.Log("INFO: GetDocument emptyDocID msg:", err)
|
||||
}
|
||||
if _, err = c.GetDocument("XXXXXXXXXXXXX"); err == nil {
|
||||
t.Error("GetDocument did not error on bad DocumentID")
|
||||
} else {
|
||||
t.Log("INFO: GetDocument badDocID msg:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testGetDocumentMeta(t *testing.T, c *documize.Client, testFile, testData string) {
|
||||
var err error
|
||||
docM, err := c.GetDocumentMeta(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(docM.Editors) < 2 { // TODO review
|
||||
t.Error("wrong number of editors expected >=2 got", len(docM.Editors))
|
||||
}
|
||||
}
|
||||
docDataM, err := c.GetDocumentMeta(testData)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(docDataM.Editors) != 2 { // TODO review
|
||||
t.Error("wrong number of editors expected 0 got", len(docDataM.Editors))
|
||||
}
|
||||
}
|
||||
if _, err = c.GetDocumentMeta(""); err == nil {
|
||||
t.Error("GetDocumentMeta did not error on empty DocumentID")
|
||||
} else {
|
||||
t.Log("INFO: GetDocumentMeta emptyDocID msg:", err)
|
||||
}
|
||||
/* TODO reivew
|
||||
if _, err = c.GetDocumentMeta("XXXXXXXXXXXXX"); err == nil {
|
||||
t.Error("GetDocumentMeta did not error on bad DocumentID")
|
||||
} else {
|
||||
t.Log("INFO: GetDocumentMeta badDocID msg:", err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func testDelete(t *testing.T, c *documize.Client, testFile, testData string) {
|
||||
var err error
|
||||
if err = c.DeleteDocument(testFile); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = c.DeleteDocument(testData); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = c.DeleteDocument(""); err == nil {
|
||||
t.Error("DeleteDocument did not error on empty DocumentID")
|
||||
} else {
|
||||
t.Log("INFO: Delete Doc emptyDocID msg:", err)
|
||||
}
|
||||
/* TODO reivew
|
||||
if err = c.DeleteDocument("XXXXXXXXXXXXX"); err == nil {
|
||||
t.Error("DeleteDocument did not error on bad DocumentID")
|
||||
} else {
|
||||
t.Log("Delete Doc badDocID msg:", err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func testMeta(t *testing.T, c *documize.Client) {
|
||||
sitemap, err := c.GetSitemap()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if sitemap == nil {
|
||||
t.Error("sitemap []byte is nil")
|
||||
} else {
|
||||
if !bytes.Contains(sitemap, []byte("http://www.sitemaps.org/schemas/sitemap")) {
|
||||
t.Errorf("Incorrect Site Map: %#v", string(sitemap))
|
||||
}
|
||||
}
|
||||
}
|
||||
robots, err := c.GetRobots()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if robots == nil {
|
||||
t.Error("robots []byte is nil")
|
||||
} else {
|
||||
if !bytes.HasPrefix(robots, []byte("User-agent:")) {
|
||||
t.Errorf("Incorrect Robots data: %#v", string(robots))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFolderAPI(t *testing.T, c *documize.Client, testFolder, testFile string) {
|
||||
|
||||
_, err := c.GetDocumentsByFolder("")
|
||||
if err == nil {
|
||||
t.Error("did not error on blank folder ID")
|
||||
} else {
|
||||
t.Log("INFO: ", err)
|
||||
}
|
||||
|
||||
docs, err := c.GetDocumentsByFolder(testFolder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
for _, doc := range docs {
|
||||
if doc.RefID == testFile {
|
||||
goto foundDoc
|
||||
}
|
||||
}
|
||||
t.Error("Unable to find " + testFile + " in the test folder")
|
||||
return
|
||||
foundDoc:
|
||||
|
||||
docs2, err := c.GetDocumentsByFolder("什么都没有")
|
||||
if err == nil {
|
||||
t.Error("did not error on bad folder ID for GetDocumentsByFolder")
|
||||
if len(docs2) != 0 {
|
||||
t.Error("found documents in folder where there should be none")
|
||||
}
|
||||
} else {
|
||||
t.Log("INFO: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testSearch(t *testing.T, c *documize.Client, testFolder, testFile string) {
|
||||
|
||||
// NOTE: search does not error on blank search term
|
||||
srch, err := c.SearchDocuments("TESTDATA")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for _, doc := range srch {
|
||||
//t.Logf("DEBUG search %#v", doc)
|
||||
if doc.DocumentID == testFile {
|
||||
goto foundSrch
|
||||
}
|
||||
}
|
||||
t.Error("Unable to find " + testFileName + " in the search list")
|
||||
foundSrch:
|
||||
|
||||
srch2, err := c.SearchDocuments("石磊先生是谁?")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(srch2) != 0 {
|
||||
t.Error("found documents in search where there should be none")
|
||||
}
|
||||
}
|
||||
|
||||
func testDownload(t *testing.T, c *documize.Client, testFolder, testFile string) {
|
||||
|
||||
nam, content, err := c.GetDocumentAsDocx(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
/* TODO
|
||||
if !strings.HasPrefix(nam, "addpage") || len(content) < 10000 {
|
||||
t.Error(" docAsDocx not as expected", nam, len(content))
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
nam, content, err = c.GetDocumentAsDocx("XXXXXXXXXX")
|
||||
if err == nil {
|
||||
t.Errorf("did not error on bad document id for get doc as docx, name: %s len(%d)",
|
||||
nam, len(content))
|
||||
} else {
|
||||
t.Log("INFO: get doc as docx bad doc id msg:", err)
|
||||
}
|
||||
|
||||
}
|
107
sdk/exttest/attachment.go
Normal file
107
sdk/exttest/attachment.go
Normal file
|
@ -0,0 +1,107 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
func testDocAttachments(t *testing.T, c *documize.Client, testFile, testData string) {
|
||||
atts, err := c.GetAttachments(testData)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for a := range atts {
|
||||
err = c.GetAttachmentData(&atts[a])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if atts[a].Filename == "test.txt" {
|
||||
if string(atts[a].Data) != "This is a test text file.\n" {
|
||||
t.Error("incorrect content to attachment")
|
||||
}
|
||||
goto foundAtt
|
||||
}
|
||||
//t.Logf("DEBUG %d atts= %#v ; err=%v; data=%s", a, atts[a], err,string(atts[a].Data))
|
||||
}
|
||||
t.Error("Attachment test.txt not found")
|
||||
foundAtt:
|
||||
dingbat := "dingbat\n"
|
||||
err = c.AddAttachment(testFile, "dingbat.txt", []byte(dingbat))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
atts, err = c.GetAttachments(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(atts) != 1 {
|
||||
t.Error("should be exactly 1 attachment")
|
||||
} else {
|
||||
err = c.GetAttachmentData(&atts[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if string(atts[0].Data) != dingbat {
|
||||
t.Error("Wrong data in attachement")
|
||||
}
|
||||
err = c.DeleteAttachment(&atts[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
atts, err = c.GetAttachments(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(atts) != 0 {
|
||||
t.Error("should be no attachments")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// errors
|
||||
atts, err = c.GetAttachments("XXXXXXX")
|
||||
if len(atts) != 0 {
|
||||
if err == nil {
|
||||
t.Error("Get attachments of unknown file did not error")
|
||||
} else {
|
||||
t.Log("INFO: get attachments of unknown file msg:", err)
|
||||
}
|
||||
}
|
||||
/* TODO improve failure modes
|
||||
att := &entity.Attachment{}
|
||||
err = c.GetAttachmentData(att)
|
||||
if len(att.Data) > 0 {
|
||||
if err == nil {
|
||||
t.Error("Get attachment data of blank file did not error")
|
||||
} else {
|
||||
t.Log("INFO: get attachments of blank file msg:", err)
|
||||
}
|
||||
}
|
||||
err = c.AddAttachment("YYYYYYYYYYYY", "dingbat.txt", []byte(dingbat))
|
||||
if err != nil {
|
||||
t.Error("Did not error adding attachment to bad file id")
|
||||
} else {
|
||||
t.Log("INFO: add attachment to unknown file msg:", err)
|
||||
}
|
||||
err = c.DeleteAttachment(&entity.Attachment{})
|
||||
if err != nil {
|
||||
t.Error("Did not error deleting attachment of blank data")
|
||||
} else {
|
||||
t.Log("INFO: delete attachment to blank file msg:", err)
|
||||
}
|
||||
*/
|
||||
}
|
98
sdk/exttest/auth.go
Normal file
98
sdk/exttest/auth.go
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
// auth provides authorization tests to be run locally or from the main Documize repo.
|
||||
func auth(t *testing.T) (*documize.Client, error) {
|
||||
|
||||
testEndPt := os.Getenv("DOCUMIZEAPI") //e.g. "http://localhost:5002"
|
||||
testAuth := os.Getenv("DOCUMIZEAUTH") //e.g. "demo1:jim@davidson.com:demo123"
|
||||
|
||||
testCreds(t, testEndPt, testAuth)
|
||||
testEndpoint(t, testEndPt, testAuth)
|
||||
|
||||
//t.Log("Auth", testEndPt, testAuth)
|
||||
|
||||
c, err := documize.NewClient(testEndPt, testAuth) // should work
|
||||
if err == nil && c == nil {
|
||||
err = errors.New("unable to authorize, new client nil")
|
||||
}
|
||||
return c, err
|
||||
}
|
||||
|
||||
func testCreds(t *testing.T, testEndPt, testAuth string) {
|
||||
_, err := documize.NewClient(testEndPt, "")
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on empty auth string ")
|
||||
} else {
|
||||
t.Log("INFO: Empty Auth string error:", err)
|
||||
}
|
||||
_, err = documize.NewClient(testEndPt, "AAA:BBB")
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on AAA:BBB auth string ")
|
||||
} else {
|
||||
t.Log("INFO: Malfomed auth string error:", err)
|
||||
}
|
||||
credentials := strings.SplitN(testAuth, ":", 3)
|
||||
if len(credentials) == 3 {
|
||||
base := []string{"XXX", "YYY", "ZZZ"}
|
||||
for i := range credentials {
|
||||
ta := make([]string, 3)
|
||||
copy(ta, base)
|
||||
for j := range ta {
|
||||
if j != i { // make sure one of the three is wrong
|
||||
ta[j] = credentials[j]
|
||||
}
|
||||
}
|
||||
as := strings.Join(ta, ":")
|
||||
//t.Log(as)
|
||||
if credentials[i] != "" { // to avoid the case where the sub-domain is empty
|
||||
_, err = documize.NewClient(testEndPt, as)
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on bad auth string: ", as)
|
||||
} else {
|
||||
t.Log("INFO: Bad component to auth string error:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testEndpoint(t *testing.T, testEndPt, testAuth string) {
|
||||
_, err := documize.NewClient("", testAuth)
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on empty end point")
|
||||
} else {
|
||||
t.Log("INFO: Empty end-point error:", err)
|
||||
}
|
||||
_, err = documize.NewClient("XXXXX", testAuth)
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on bad end point")
|
||||
} else {
|
||||
t.Log("INFO: Bad end point error:", err)
|
||||
}
|
||||
_, err = documize.NewClient("http://XXXXXYYYYYYZZZZZZ.com", testAuth)
|
||||
if err == nil {
|
||||
t.Error("ExtTestAuth did not error on invalid end point")
|
||||
} else {
|
||||
t.Log("INFO: Invalid end point error:", err)
|
||||
}
|
||||
}
|
57
sdk/exttest/folders.go
Normal file
57
sdk/exttest/folders.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
"github.com/documize/community/documize/api/entity"
|
||||
)
|
||||
|
||||
func testFolders(t *testing.T, c *documize.Client, myFolder *entity.Label) {
|
||||
|
||||
perms, err := c.GetFolderPermissions(myFolder.RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
//t.Logf("INFO: folder perms %#v", *perms)
|
||||
}
|
||||
err = c.SetFolderPermissions(myFolder.RefID, "test message", perms)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
//t.Logf("INFO: set empty folder perms")
|
||||
}
|
||||
|
||||
fv, err := c.GetFoldersVisibility()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
//t.Logf("INFO: folder vis %#v", fv)
|
||||
_ = fv
|
||||
}
|
||||
|
||||
myFolder.Name += " - Modified"
|
||||
err = c.UpdateFolder(myFolder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
fi, err := c.GetFolder(myFolder.RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
//t.Logf("INFO: folder info %#v", fi)
|
||||
_ = fi
|
||||
}
|
||||
}
|
92
sdk/exttest/loaddata.go
Normal file
92
sdk/exttest/loaddata.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
"github.com/documize/community/wordsmith/api"
|
||||
)
|
||||
|
||||
// loadData provides data-loading tests to be run locally or from the main Documize repo.
|
||||
func loadData(c *documize.Client, t *testing.T, testFolder string) string {
|
||||
ret, err := c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{
|
||||
//Err error
|
||||
PagesHTML: []byte{}, // If empty, use Pages
|
||||
Pages: []api.Page{
|
||||
{
|
||||
Level: 1, // uint64 // overall document is level 1, <H1> => level 2
|
||||
Title: "Test Data Title top", // string
|
||||
Body: []byte("This is the body of page 0"), // []byte
|
||||
},
|
||||
{
|
||||
Level: 2, // uint64 // overall document is level 1, <H1> => level 2
|
||||
Title: "Test Data Title second", // string
|
||||
Body: []byte("This is the body of page 1"), // []byte
|
||||
},
|
||||
},
|
||||
EmbeddedFiles: []api.EmbeddedFile{
|
||||
{
|
||||
ID: "TestID1",
|
||||
Type: "txt",
|
||||
Name: "test.txt", // do not change, used in exttest
|
||||
Data: []byte("This is a test text file.\n"), // do not change, used in exttest
|
||||
},
|
||||
{
|
||||
ID: "TestID2",
|
||||
Type: "go",
|
||||
Name: "blob.go",
|
||||
Data: []byte("// Package blob is a test go file.\npackage blob\n"),
|
||||
},
|
||||
},
|
||||
Excerpt: "Ext Test Load Data - Excerpt",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{
|
||||
//Err error
|
||||
PagesHTML: []byte{}, // If empty, use Pages
|
||||
Pages: []api.Page{
|
||||
{
|
||||
Level: 1, // overall document is level 1, <H1> => level 2
|
||||
Title: "Test Data Title top",
|
||||
Body: []byte("This is the body of page 0"),
|
||||
},
|
||||
},
|
||||
EmbeddedFiles: []api.EmbeddedFile{
|
||||
{
|
||||
ID: "TestID1",
|
||||
Type: "txt",
|
||||
Name: "test", // wrong, does not have correct extension
|
||||
Data: []byte("This is a test text file.\n"),
|
||||
},
|
||||
},
|
||||
Excerpt: "Ext Test Load Data - Excerpt",
|
||||
})
|
||||
if err == nil {
|
||||
t.Error("data load did not error on bad embedded file name")
|
||||
} else {
|
||||
t.Log("INFO: Bad embedded file name error:", err)
|
||||
}
|
||||
|
||||
_, err = c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{})
|
||||
if err == nil {
|
||||
t.Error("data load did not error on no pages ")
|
||||
} else {
|
||||
t.Log("INFO: No pages error:", err)
|
||||
}
|
||||
|
||||
return ret.BaseEntity.RefID
|
||||
}
|
45
sdk/exttest/loadfile.go
Normal file
45
sdk/exttest/loadfile.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
// loadFile provides file load tests to be run locally or from the main Documize repo.
|
||||
func loadFile(c *documize.Client, t *testing.T, testFolder, testFileName string) string {
|
||||
docID := "" //NOT-FOUND
|
||||
ret, err := c.LoadFile(testFolder, testFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if ret == nil {
|
||||
t.Error("nil pointer returned for LoadFile")
|
||||
} else {
|
||||
docID = ret.BaseEntity.RefID
|
||||
}
|
||||
_, err = c.LoadFile("XXX", testFileName)
|
||||
if err == nil {
|
||||
t.Error("did not error on bad folder")
|
||||
} else {
|
||||
t.Log("INFO: Bad folder error:", err)
|
||||
}
|
||||
_, err = c.LoadFile(testFolder, "XXX")
|
||||
if err == nil {
|
||||
t.Error("did not error on bad file name")
|
||||
} else {
|
||||
t.Log("INFO: Bad file name error:", err)
|
||||
}
|
||||
return docID
|
||||
}
|
132
sdk/exttest/pages.go
Normal file
132
sdk/exttest/pages.go
Normal file
|
@ -0,0 +1,132 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/documize/api/endpoint/models"
|
||||
"github.com/documize/community/documize/api/entity"
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
func testPages(t *testing.T, c *documize.Client, testFolder, testFile, testData string) {
|
||||
|
||||
lastSeq := 0.0
|
||||
dp, err := c.GetDocumentPages(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
var pageIDs []string
|
||||
for _, v := range dp {
|
||||
pageIDs = append(pageIDs, v.RefID)
|
||||
if v.Sequence > lastSeq {
|
||||
lastSeq = v.Sequence
|
||||
}
|
||||
}
|
||||
pageIDlist := strings.Join(pageIDs, ",")
|
||||
if dpb, err2 := c.GetDocumentPagesBatch(testFile, pageIDlist); err != nil {
|
||||
t.Error(err2)
|
||||
} else {
|
||||
for k, v := range dp {
|
||||
if v.Body != dpb[k].Body {
|
||||
t.Errorf("page %d from GetDocumentPages != from GetDocumentPagesBatch", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const numPages = 100
|
||||
pagesAdded := make([]*entity.Page, 0, numPages)
|
||||
for i := 0; i < numPages; i++ {
|
||||
lastSeq += 1000.0
|
||||
pg := entity.Page{
|
||||
DocumentID: testFile,
|
||||
Level: 1,
|
||||
Title: "AddPage() title " + fmt.Sprintf("%d", i),
|
||||
Body: "AddPage() body " + fmt.Sprintf("%d", i),
|
||||
ContentType: "wysiwyg",
|
||||
Sequence: lastSeq,
|
||||
}
|
||||
if newPg, err2 := c.AddDocumentPage(testFile, &pg); err != nil {
|
||||
t.Error(err2)
|
||||
} else {
|
||||
pagesAdded = append(pagesAdded, newPg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(pagesAdded) < 2 {
|
||||
t.Error("Less than two pages added, cannot continue with pages test")
|
||||
return
|
||||
}
|
||||
|
||||
err = c.ChangeDocumentPageLevel(testFile, &[]models.PageLevelRequestModel{
|
||||
{PageID: pagesAdded[0].RefID, Level: int(pagesAdded[0].Level + 42)},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDocumentPageSequence(testFile, &[]models.PageSequenceRequestModel{
|
||||
{PageID: pagesAdded[0].RefID, Sequence: pagesAdded[0].Sequence - 1.0},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
pagesAdded[0].Body += " - Modified!"
|
||||
err = c.UpdateDocumentPage(pagesAdded[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
revs, err := c.GetDocumentPageRevisions(testFile, pagesAdded[0].RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
diff, err2 := c.GetDocumentPageDiff(testFile, pagesAdded[0].RefID, revs[0].RefID)
|
||||
if err2 != nil {
|
||||
t.Error(err2)
|
||||
} else {
|
||||
t.Logf("INFO: Revised single doc page diff: %s", string(diff))
|
||||
}
|
||||
err = c.RollbackDocumentPage(testFile, pagesAdded[0].RefID, revs[0].RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: Rolled-back revised single doc page %s", revs[0].RefID)
|
||||
}
|
||||
}
|
||||
|
||||
err = c.DeleteDocumentPage(testFile, pagesAdded[0].RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Log("INFO: Deleted single doc page", pagesAdded[0].RefID)
|
||||
}
|
||||
|
||||
delList := []string{pagesAdded[1].RefID}
|
||||
for k, v := range pagesAdded {
|
||||
if k > 1 {
|
||||
delList = append(delList, v.RefID)
|
||||
}
|
||||
}
|
||||
err = c.DeleteDocumentPages(testFile, delList)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Log("INFO: Deleted multiple doc pages:", len(delList))
|
||||
}
|
||||
|
||||
}
|
64
sdk/exttest/templates.go
Normal file
64
sdk/exttest/templates.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
)
|
||||
|
||||
func testTemplates(t *testing.T, c *documize.Client, testFolder, testFile, testData string) {
|
||||
|
||||
temps, err := c.GetTemplates(true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(temps) == 0 {
|
||||
t.Log("INFO: no stock templates found in the database")
|
||||
} else {
|
||||
t.Logf("INFO: testing with stock template %#v", temps[0])
|
||||
docID, errStart := c.StartDocumentFromTemplate(true, temps[0].ID, testFolder)
|
||||
if errStart != nil {
|
||||
t.Error(errStart)
|
||||
} else {
|
||||
t.Log("INFO: created document", docID)
|
||||
err = c.DeleteDocument(docID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
temps, err = c.GetTemplates(false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(temps) == 0 {
|
||||
t.Log("INFO: no saved templates found in the database")
|
||||
} else {
|
||||
t.Logf("INFO: testing with saved template %#v", temps[0])
|
||||
docID, err := c.StartDocumentFromTemplate(false, temps[0].ID, testFolder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Log("INFO: created document", docID)
|
||||
err = c.DeleteDocument(docID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
63
sdk/exttest/users.go
Normal file
63
sdk/exttest/users.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package exttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/sdk"
|
||||
"github.com/documize/community/documize/api/entity"
|
||||
)
|
||||
|
||||
func testUsers(t *testing.T, c *documize.Client) {
|
||||
|
||||
usrs, err := c.GetUsers()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: users info %#v", usrs)
|
||||
}
|
||||
usr, err := c.GetUserInfo()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: this user info %#v", usr)
|
||||
}
|
||||
perms, err := c.GetUserFolderPermissions()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: testing user folder perms %#v", len(*perms))
|
||||
}
|
||||
|
||||
testUser := &entity.User{
|
||||
Firstname: "TestFirstname",
|
||||
Lastname: "TestLastname",
|
||||
Email: "tt@a.b",
|
||||
Admin: false,
|
||||
}
|
||||
err = c.AddUser(testUser)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
t.Logf("INFO: created test user %#v", *testUser)
|
||||
err = c.UpdateUser(testUser)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = c.DeleteUser(testUser.BaseEntity.RefID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue