sugarcrb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +8 -0
- data/test/test_helper.rb +3 -0
- data/test/test_sugarcrb.rb +194 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c280020944c65e66cfd5370c27d5a62db8222e1
|
4
|
+
data.tar.gz: e6fe013dfa212d24dc5af21278c0ab2a2791c72d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a37daebed6df401edd681af62d8abaa73f6b34847dbb15688f3c3f1e3e7116597b10b3406fac5e48fe08519851ce1cf315af03c466d97165201891dce72c508c
|
7
|
+
data.tar.gz: 8f77b7f83083a49759aa3722ca2f2a7ffada3ec2b6dbec37ad525d1ed0576315b8ce4e5636550826483d044b94e8ea56a3cc95ba0003f6086d6bed531b064bad
|
data/Rakefile
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'sugarcrb'
|
3
|
+
|
4
|
+
describe "Sugarcrm" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@sugarcrm = Sugarcrb.new("http://lowes.merxbp.loc","admin","Lowes2017","tests","sugar","")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Cuando se inicializa la Clase" do
|
11
|
+
it "Debe de tener valores" do
|
12
|
+
assert_equal "admin", @sugarcrm.username
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Cuando hace login" do
|
17
|
+
it "Debe de obtener respuesta valida" do
|
18
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
19
|
+
.with(body: {"grant_type":"password","client_id":"sugar","client_secret":"","username":"admin","password":"Lowes2017","platform":"tests"})
|
20
|
+
.to_return(status: 200, body: '{"access_token":"AAA","refresh_token":"RRR"}', headers: {})
|
21
|
+
|
22
|
+
response = JSON.load(@sugarcrm.oauth2_token)
|
23
|
+
assert_equal "AAA", response['access_token']
|
24
|
+
assert_equal "RRR", response['refresh_token']
|
25
|
+
assert_equal "AAA", @sugarcrm.access_token
|
26
|
+
assert_equal "RRR", @sugarcrm.refresh_token
|
27
|
+
end
|
28
|
+
|
29
|
+
it "Debe de obtener respuesta valida" do
|
30
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
31
|
+
.to_return(status: 401, body: '{"error":"need_login","error_message":"Debe especificar un usuario y contrase\u00f1a v\u00e1lidos."}', headers: {})
|
32
|
+
|
33
|
+
assert_raises RuntimeError do
|
34
|
+
@sugarcrm.oauth2_token
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_empty @sugarcrm.instance_variable_get("@access_token")
|
38
|
+
assert_empty @sugarcrm.instance_variable_get("@refresh_token")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "Debe de obtener respuesta valida" do
|
42
|
+
@sugarcrm.refresh_token = "RRR"
|
43
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
44
|
+
.with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
|
45
|
+
.to_return(status: 200, body: '{"access_token":"AA1","refresh_token":"RR1"}', headers: {})
|
46
|
+
|
47
|
+
response = JSON.load(@sugarcrm.oauth2_refresh_token)
|
48
|
+
assert_equal "AA1", response['access_token']
|
49
|
+
assert_equal "RR1", response['refresh_token']
|
50
|
+
assert_equal "AA1", @sugarcrm.access_token
|
51
|
+
assert_equal "RR1", @sugarcrm.refresh_token
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "Cuando llama el api" do
|
57
|
+
it "Debe de crear un registro con peticion valida" do
|
58
|
+
@sugarcrm.access_token = "AAA"
|
59
|
+
@sugarcrm.refresh_token = "RRR"
|
60
|
+
|
61
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
62
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
63
|
+
.to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
|
64
|
+
|
65
|
+
response = JSON.load(@sugarcrm.call("post", "Accounts",{
|
66
|
+
"name" => "Account name"
|
67
|
+
}))
|
68
|
+
|
69
|
+
assert_equal "SUGARID", response['id']
|
70
|
+
assert_equal "Account name", response['name']
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Debe de crear un registro con peticion invalida por token expirado" do
|
74
|
+
@sugarcrm.access_token = "AAA"
|
75
|
+
@sugarcrm.refresh_token = "RRR"
|
76
|
+
|
77
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
78
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
79
|
+
.to_return(status: 401, body: '{"error":"invalid_grant","error_message":"The access token provided is invalid."}', headers: {})
|
80
|
+
|
81
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
82
|
+
.with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
|
83
|
+
.to_return(status: 200, body: '{"access_token":"AA1","refresh_token":"RR1"}', headers: {})
|
84
|
+
|
85
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
86
|
+
.with(headers: { 'OAuth-Token' => "AA1" })
|
87
|
+
.to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
|
88
|
+
|
89
|
+
response = JSON.load(@sugarcrm.call("post", "Accounts",{
|
90
|
+
"name" => "Account name"
|
91
|
+
}))
|
92
|
+
|
93
|
+
assert_equal "SUGARID", response['id']
|
94
|
+
assert_equal "Account name", response['name']
|
95
|
+
assert_equal "AA1", @sugarcrm.access_token
|
96
|
+
assert_equal "RR1", @sugarcrm.refresh_token
|
97
|
+
end
|
98
|
+
|
99
|
+
it "Debe de crear un registro con peticion invalida por token expirado y refresh_token expirado" do
|
100
|
+
@sugarcrm.access_token = "AAA"
|
101
|
+
@sugarcrm.refresh_token = "RRR"
|
102
|
+
|
103
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
104
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
105
|
+
.to_return(status: 401, body: '{"error":"invalid_grant","error_message":"The access token provided is invalid."}', headers: {})
|
106
|
+
|
107
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
108
|
+
.with(body: {"grant_type":"refresh_token","refresh_token":"RRR","client_id":"sugar","client_secret":""})
|
109
|
+
.to_return(status: 401, body: '{"error":"need_login","error_message":"Debe especificar un usuario y contrase\u00f1a v\u00e1lidos."}', headers: {})
|
110
|
+
|
111
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/oauth2/token")
|
112
|
+
.with(body: {"grant_type":"password","client_id":"sugar","client_secret":"","username":"admin","password":"Lowes2017","platform":"tests"})
|
113
|
+
.to_return(status: 200, body: '{"access_token":"AA2","refresh_token":"RR2"}', headers: {})
|
114
|
+
|
115
|
+
stub_request(:post, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
116
|
+
.with(headers: { 'OAuth-Token' => "AA2" })
|
117
|
+
.to_return(status: 200, body: '{"id":"SUGARID","name":"Account name"}', headers: {})
|
118
|
+
|
119
|
+
response = JSON.load(@sugarcrm.call("post", "Accounts",{
|
120
|
+
"name" => "Account name"
|
121
|
+
}))
|
122
|
+
|
123
|
+
assert_equal "SUGARID", response['id']
|
124
|
+
assert_equal "Account name", response['name']
|
125
|
+
assert_equal "AA2", @sugarcrm.access_token
|
126
|
+
assert_equal "RR2", @sugarcrm.refresh_token
|
127
|
+
end
|
128
|
+
|
129
|
+
it "Debe de listar un registro con peticion valida empty" do
|
130
|
+
@sugarcrm.access_token = "AAA"
|
131
|
+
|
132
|
+
stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
133
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
134
|
+
.to_return(status: 200, body: '{"next_offset":-1,"records":[]}', headers: {})
|
135
|
+
|
136
|
+
response = JSON.load(@sugarcrm.call("get", "Accounts"))
|
137
|
+
|
138
|
+
assert_equal -1, response['next_offset']
|
139
|
+
assert_equal 0, response['records'].length
|
140
|
+
end
|
141
|
+
|
142
|
+
it "Debe de listar un registro con peticion valida con un elemento" do
|
143
|
+
@sugarcrm.access_token = "AAA"
|
144
|
+
|
145
|
+
stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts")
|
146
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
147
|
+
.to_return(status: 200, body: '{"next_offset":20,"records":[{"id":"AAA","name":"Account Name"}]}', headers: {})
|
148
|
+
|
149
|
+
response = JSON.load(@sugarcrm.call("get", "Accounts"))
|
150
|
+
|
151
|
+
assert_equal 20, response['next_offset']
|
152
|
+
assert_equal 1, response['records'].length
|
153
|
+
end
|
154
|
+
|
155
|
+
it "Debe de obtener un registro con peticion valida " do
|
156
|
+
@sugarcrm.access_token = "AAA"
|
157
|
+
|
158
|
+
stub_request(:get, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
|
159
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
160
|
+
.to_return(status: 200, body: '{"id":"AAA","name":"Account Name"}', headers: {})
|
161
|
+
|
162
|
+
response = JSON.load(@sugarcrm.call("get", "Accounts/AAA"))
|
163
|
+
|
164
|
+
assert_equal "AAA", response['id']
|
165
|
+
assert_equal "Account Name", response['name']
|
166
|
+
end
|
167
|
+
|
168
|
+
it "Debe de actualizar un registro con peticion valida " do
|
169
|
+
@sugarcrm.access_token = "AAA"
|
170
|
+
|
171
|
+
stub_request(:put, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
|
172
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
173
|
+
.to_return(status: 200, body: '{"id":"AAA","name":"Account Name Change"}', headers: {})
|
174
|
+
|
175
|
+
response = JSON.load(@sugarcrm.call("put", "Accounts/AAA", {"name"=>"Account Name Change"}))
|
176
|
+
|
177
|
+
assert_equal "AAA", response['id']
|
178
|
+
assert_equal "Account Name Change", response['name']
|
179
|
+
end
|
180
|
+
|
181
|
+
it "Debe de eliminar un registro con peticion valida " do
|
182
|
+
@sugarcrm.access_token = "AAA"
|
183
|
+
|
184
|
+
stub_request(:delete, "http://lowes.merxbp.loc/rest/v10/Accounts/AAA")
|
185
|
+
.with(headers: { 'OAuth-Token' => "AAA" })
|
186
|
+
.to_return(status: 200, headers: {})
|
187
|
+
|
188
|
+
response = @sugarcrm.call("delete", "Accounts/AAA")
|
189
|
+
assert_equal 200, response.code
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Bazan
|
@@ -44,8 +44,11 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- Rakefile
|
47
48
|
- lib/sugarcrb.rb
|
48
|
-
|
49
|
+
- test/test_helper.rb
|
50
|
+
- test/test_sugarcrb.rb
|
51
|
+
homepage: https://rubygems.org/gems/sugarcrb
|
49
52
|
licenses:
|
50
53
|
- MIT
|
51
54
|
metadata: {}
|
@@ -69,4 +72,6 @@ rubygems_version: 2.4.6
|
|
69
72
|
signing_key:
|
70
73
|
specification_version: 4
|
71
74
|
summary: Sugarcrm client
|
72
|
-
test_files:
|
75
|
+
test_files:
|
76
|
+
- test/test_sugarcrb.rb
|
77
|
+
- test/test_helper.rb
|