forked from hexya-addons/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webclient_test.go
83 lines (79 loc) · 2.58 KB
/
webclient_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2020 NDP Systèmes. All Rights Reserved.
// See LICENSE file for full licensing details.
package web
import (
"encoding/json"
"fmt"
"net/url"
"testing"
"time"
"github.com/erlangs/hexya-web/client"
"github.com/erlangs/hexya-web/controllers"
"github.com/erlangs/hexya-web/domains"
"github.com/erlangs/okoo/src/models/types"
"github.com/erlangs/okoo/src/server"
)
func TestWebclientCalls(t *testing.T) {
hexyaURL := url.URL{
Scheme: "http",
Host: "localhost:8585",
}
go func() { fmt.Println("server:", server.GetServer().Run(hexyaURL.Host)) }()
cl := client.NewHexyaClient(hexyaURL.String())
// Wait for server to come up
time.Sleep(500 * time.Millisecond)
Convey("Testing direct HTTP Calls to web client", t, func() {
err := cl.Login("admin", "admin")
So(err, ShouldBeNil)
cookies := cl.Jar.Cookies(&hexyaURL)
So(cookies, ShouldHaveLength, 1)
So(cookies[0].Name, ShouldEqual, "hexya-session")
Convey("Search-reading users", func() {
raw, err := cl.RPC("/web/dataset/search_read", "call", controllers.SearchReadParams{
Model: "User",
Context: *types.NewContext().
WithKey("company_id", 1).
WithKey("lang", "en_US").
WithKey("tz", "").
WithKey("uid", 1),
Domain: domains.Domain{},
Fields: []string{"action_id", "active", "company_id", "company_ids", "email", "group_ids", "id", "image",
"lang", "login", "name", "partner_id", "signature", "tz", "tz_offset", "display_name", "__last_update"},
Limit: 80,
Sort: "",
})
So(err, ShouldBeNil)
var res map[string]interface{}
err = json.Unmarshal(raw, &res)
So(err, ShouldBeNil)
So(res, ShouldContainKey, "records")
So(res, ShouldContainKey, "length")
So(res["length"], ShouldEqual, 4)
So(res["records"], ShouldHaveLength, 4)
})
Convey("Read on company", func() {
raw, err := cl.RPC("/web/dataset/call_kw", "call", controllers.CallParams{
Model: "Company",
Method: "read",
Args: []json.RawMessage{
json.RawMessage(`[1]`),
json.RawMessage(`["display_name","name"]`),
},
KWArgs: map[string]json.RawMessage{
"context": json.RawMessage(`{"company_id":1,"lang":"en_US","tz":"","uid":1}`),
},
})
So(err, ShouldBeNil)
var res []map[string]interface{}
err = json.Unmarshal(raw, &res)
So(err, ShouldBeNil)
So(res, ShouldHaveLength, 1)
So(res[0], ShouldContainKey, "display_name")
So(res[0]["display_name"], ShouldEqual, "Your Company")
So(res[0], ShouldContainKey, "name")
So(res[0]["name"], ShouldEqual, "Your Company")
So(res[0], ShouldContainKey, "id")
So(res[0]["id"], ShouldEqual, 1)
})
})
}