From d5f30b440e5a40d114a0b54ef13993e9ed0192a4 Mon Sep 17 00:00:00 2001 From: Elliott Stoneham Date: Mon, 18 Jul 2016 14:27:37 +0100 Subject: [PATCH] fix section test, remove dead code. --- documize/section/github/github.go | 4 -- documize/section/section_test.go | 12 +++--- sdk/exttest/pages.go | 22 +--------- sdk/pages.go | 67 +------------------------------ 4 files changed, 11 insertions(+), 94 deletions(-) diff --git a/documize/section/github/github.go b/documize/section/github/github.go index d872db84..2943a5fe 100644 --- a/documize/section/github/github.go +++ b/documize/section/github/github.go @@ -75,10 +75,6 @@ func validateToken(ptoken string) error { return err } -func secretsJSON(token string) string { - return `{"token":"` + strings.TrimSpace(token) + `"}` -} - // Command to run the various functions required... func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) { query := r.URL.Query() diff --git a/documize/section/section_test.go b/documize/section/section_test.go index 9c059194..5d92c3f0 100644 --- a/documize/section/section_test.go +++ b/documize/section/section_test.go @@ -27,18 +27,18 @@ func init() { } // Command is an end-point... -func (ts *testsection) Command(w http.ResponseWriter, r *http.Request) {} +func (ts *testsection) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {} var didRefresh bool // Refresh existing data, returning data in the format of the target system -func (ts *testsection) Refresh(meta, data string) string { +func (ts *testsection) Refresh(ctx *provider.Context, meta, data string) string { didRefresh = true return "" } // Render converts data in the target system format into HTML -func (*testsection) Render(meta, data string) string { +func (*testsection) Render(ctx *provider.Context, meta, data string) string { return "testsection " + data } @@ -54,13 +54,15 @@ func (*testsection) Meta() provider.TypeMeta { } func TestSection(t *testing.T) { - if _, ok := provider.Refresh("testsection", "", ""); !ok { + ctx := provider.NewContext("_orgid_", "_userid_") + + if _, ok := provider.Refresh("testsection", ctx, "", ""); !ok { t.Error("did not find 'testsection' smart section (1)") } if !didRefresh { t.Error("did not run the test Refresh method") } - out, ok := provider.Render("testsection", "meta", "dingbat") + out, ok := provider.Render("testsection", ctx, "meta", "dingbat") if !ok { t.Error("did not find 'testsection' smart section (2)") } diff --git a/sdk/exttest/pages.go b/sdk/exttest/pages.go index 4b881ae1..430333fc 100644 --- a/sdk/exttest/pages.go +++ b/sdk/exttest/pages.go @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// 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 . +// by contacting . // // https://documize.com @@ -91,24 +91,6 @@ func testPages(t *testing.T, c *documize.Client, testFolder, testFile, testData 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) diff --git a/sdk/pages.go b/sdk/pages.go index 22a1f9e4..3d81ce83 100644 --- a/sdk/pages.go +++ b/sdk/pages.go @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// 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 . +// by contacting . // // https://documize.com @@ -171,69 +171,6 @@ func (c *Client) UpdateDocumentPage(pg *entity.Page) error { return nil } -// GetDocumentPageRevisions returns all the previous versions of a given page in a document. -func (c *Client) GetDocumentPageRevisions(documentID, pageID string) ([]entity.Revision, error) { - req, err := http.NewRequest("GET", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions", nil) - if err != nil { - return nil, err - } - req.Header.Add(HeaderAuthTokenName, c.Auth.Token) - resp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() // ignore error - revs := make([]entity.Revision, 0, 3) - dec := json.NewDecoder(resp.Body) - err = dec.Decode(&revs) - if err != nil { - return nil, err - } - return revs, nil -} - -// GetDocumentPageDiff returns html showing the difference between the given page revision and the current version of -// a given page in a document. -func (c *Client) GetDocumentPageDiff(documentID, pageID, revID string) ([]byte, error) { - req, err := http.NewRequest("GET", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions/"+revID, nil) - if err != nil { - return nil, err - } - req.Header.Add(HeaderAuthTokenName, c.Auth.Token) - resp, err := c.Client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() // ignore error - diff, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - return diff, nil -} - -// RollbackDocumentPage reverts the given document page back to the chosen revision. -func (c *Client) RollbackDocumentPage(documentID, pageID, revID string) error { - req, err := http.NewRequest("POST", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions/"+revID, nil) - if err != nil { - return err - } - req.Header.Add(HeaderAuthTokenName, c.Auth.Token) - resp, err := c.Client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() // ignore error - diff, err := ioutil.ReadAll(resp.Body) - if err != nil { - return err - } - if isError(string(diff)) { - return errors.New(trimErrors(string(diff))) - } - return nil -} - // ChangeDocumentPageLevel sets the levels of the pages in the PageLevelRequestModel for the given document. func (c *Client) ChangeDocumentPageLevel(documentID string, plrm *[]models.PageLevelRequestModel) error { b, err := json.Marshal(plrm)