github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/sdk/exttest/templates.go (about) 1 // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved. 2 // 3 // This software (Documize Community Edition) is licensed under 4 // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html 5 // 6 // You can operate outside the AGPL restrictions by purchasing 7 // Documize Enterprise Edition and obtaining a commercial license 8 // by contacting <sales@documize.com>. 9 // 10 // https://documize.com 11 12 package exttest 13 14 import ( 15 "testing" 16 17 "github.com/documize/community/sdk" 18 ) 19 20 func testTemplates(t *testing.T, c *documize.Client, testFolder, testFile, testData string) { 21 22 temps, err := c.GetTemplates(true) 23 if err != nil { 24 t.Error(err) 25 } else { 26 if len(temps) == 0 { 27 t.Log("INFO: no stock templates found in the database") 28 } else { 29 t.Logf("INFO: testing with stock template %#v", temps[0]) 30 docID, errStart := c.StartDocumentFromTemplate(true, temps[0].ID, testFolder) 31 if errStart != nil { 32 t.Error(errStart) 33 } else { 34 t.Log("INFO: created document", docID) 35 err = c.DeleteDocument(docID) 36 if err != nil { 37 t.Error(err) 38 } 39 } 40 } 41 } 42 43 temps, err = c.GetTemplates(false) 44 if err != nil { 45 t.Error(err) 46 } else { 47 if len(temps) == 0 { 48 t.Log("INFO: no saved templates found in the database") 49 } else { 50 t.Logf("INFO: testing with saved template %#v", temps[0]) 51 docID, err := c.StartDocumentFromTemplate(false, temps[0].ID, testFolder) 52 if err != nil { 53 t.Error(err) 54 } else { 55 t.Log("INFO: created document", docID) 56 err = c.DeleteDocument(docID) 57 if err != nil { 58 t.Error(err) 59 } 60 } 61 } 62 } 63 64 }