usergrid_iron 0.0.1

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.
@@ -0,0 +1,12 @@
1
+ :api_url: http://localhost:8080
2
+ :management:
3
+ :username: test
4
+ :password: test
5
+ :organization:
6
+ :name: test-organization
7
+ :username: test
8
+ :password: test
9
+ :application:
10
+ :name: test-app
11
+ :username: test-app-user
12
+ :password: test
@@ -0,0 +1,271 @@
1
+ describe Usergrid::Application do
2
+
3
+ before :all do
4
+ @application = create_random_application
5
+ @user = create_random_user @application, true
6
+ end
7
+
8
+ after :all do
9
+ @user.delete
10
+ delete_application @application
11
+ end
12
+
13
+ it "should be able to create and delete a user" do
14
+ random = SecureRandom.hex
15
+ response = @application.create_user("username_#{random}", "#{random} name", "#{random}@email.com", random)
16
+ entity = response.entity
17
+ begin
18
+ response.code.should eq 200
19
+ response.entities.size.should eq 1
20
+ entity.uuid.should_not be_nil
21
+ response = @application["users/#{entity.uuid}"].get
22
+ response.code.should eq 200
23
+ ensure
24
+ entity.delete
25
+ expect { @application["users/#{entity.uuid}"].get }.to raise_error(RestClient::ResourceNotFound)
26
+ end
27
+ end
28
+
29
+ it "should be able to retrieve users" do
30
+ entity1 = create_random_user @application
31
+ entity2 = create_random_user @application
32
+ begin
33
+ response = @application.users
34
+ response.entities.size.should be >= 2
35
+ match1 = match2 = false
36
+ response.entities.each do |e|
37
+ match1 ||= e.username == entity1.username
38
+ match2 ||= e.username == entity2.username
39
+ end
40
+ match1.should be_true
41
+ match2.should be_true
42
+ ensure
43
+ entity1.delete
44
+ entity2.delete
45
+ end
46
+ response = @application.users
47
+ response.code.should eq 200
48
+ response.entities.should be_an Array
49
+ end
50
+
51
+ it "should be able to query users" do
52
+ entity1 = create_random_user @application
53
+ entity2 = create_random_user @application
54
+ begin
55
+ response = @application.users "select * where username = \'#{entity1.username}\'"
56
+ response.entities.size.should eq 1
57
+ response.entity.username.should eq entity1.username
58
+ ensure
59
+ entity1.delete
60
+ entity2.delete
61
+ end
62
+ end
63
+
64
+ it "should be able to update a user" do
65
+ entity = create_random_user @application
66
+ begin
67
+ updates = { email: 'testuser6@email.com', city: 'santa clarita' }
68
+ response = @application.put updates
69
+ updates.each {|k,v| response.entity[k.to_s].should eq v }
70
+ ensure
71
+ entity.delete
72
+ end
73
+ end
74
+
75
+ it "should be able to retrieve the logged in user" do
76
+ user = @application.current_user
77
+ user.uuid.should_not be_nil
78
+ end
79
+
80
+ it "should be able to add and retrieve activities" do
81
+ user = @application.current_user
82
+ activity = {
83
+ verb: "post",
84
+ content: "testy, testy",
85
+ actor: {
86
+ uuid: user.uuid,
87
+ email: user.email,
88
+ username: user.username,
89
+ displayName: user.username,
90
+ image: {
91
+ height: 80,
92
+ width: 80,
93
+ url: user.picture
94
+ }}}
95
+ response = @application['activities'].post activity
96
+ activity_path = response.entity['metadata']['path']
97
+ response.code.should eq 200
98
+
99
+ begin
100
+ entity = @application.activities.entity
101
+ activity.add_dot_notation!
102
+ entity.verb.should eq activity.verb
103
+ entity.content.should eq activity.content
104
+ entity.actor.uuid.should eq activity.actor.uuid
105
+ ensure
106
+ @application[activity_path].delete
107
+ end
108
+ end
109
+
110
+ it "should be able to retrieve a user's feed" do
111
+ response = @application.current_user.resource['feed'].get
112
+ response.code.should eq 200
113
+ response.entities.should be_an Array
114
+ end
115
+
116
+ it "should be able to follow a user" do
117
+ follower = create_random_user @application
118
+ begin
119
+ me = @application.current_user
120
+ @application["users/#{follower.uuid}/following/users/#{me.uuid}"].post "{}"
121
+
122
+ response = @application["users/#{follower.uuid}/following"].get
123
+ response.entities.size.should == 1
124
+ response.entity.uuid.should eq me.uuid
125
+
126
+ response = @application.current_user.resource['followers'].get
127
+ response.entities.size.should be > 0
128
+ ensure
129
+ follower.delete
130
+ end
131
+ end
132
+
133
+ it "should be able to create and retrieve groups" do
134
+ response = @application.groups
135
+ size = response.entities.size
136
+ random = SecureRandom.hex
137
+ @application.create_entity :groups, path: "test-#{random}"
138
+ response = @application.groups
139
+ response.entities.size.should eq size+1
140
+ end
141
+
142
+ it "should be able to create and retrieve devices" do
143
+ response = @application.devices
144
+ size = response.entities.size
145
+ random = SecureRandom.hex
146
+ @application.create_entity :devices, path: "test-#{random}"
147
+ response = @application.devices
148
+ response.entities.size.should eq size+1
149
+ end
150
+
151
+ it "should be able to create and retrieve assets" do
152
+ response = @application.assets
153
+ size = response.entities.size
154
+ random = SecureRandom.hex
155
+ @application.create_entity :assets, path: "test-#{random}", owner: @application.current_user.uuid
156
+ response = @application.assets
157
+ response.entities.size.should eq size+1
158
+ end
159
+
160
+ it "should be able to create and retrieve folders" do
161
+ response = @application.folders
162
+ size = response.entities.size
163
+ random = SecureRandom.hex
164
+ @application.create_entity :folders, path: "test-#{random}", owner: @application.current_user.uuid
165
+ response = @application.folders
166
+ response.entities.size.should eq size+1
167
+ end
168
+
169
+ it "should be able to create and retrieve events and retrieve counters" do
170
+ # clear events
171
+ {} while @application.events.entities.size > 0
172
+
173
+ events_in = []
174
+ events_in << {timestamp: 0, category: 'test', counters: { test: 1 }}
175
+ events_in << {timestamp: 0, category: 'testme', counters: { testme: 1 }}
176
+ events_in << {timestamp: 0, counters: { test: 1 }}
177
+ events_in.each {|e| @application.create_entity :events, e }
178
+
179
+ events_out = []
180
+ events_out << @application.events.entity
181
+ events_out << @application.events.entity
182
+ events_out << @application.events.entity
183
+
184
+ (0..2).each do |i|
185
+ events_in[i][:category].should eq events_out[i]['category']
186
+ end
187
+
188
+ response = @application.events
189
+ response.entities.size.should eq 0
190
+
191
+ # get and test counters
192
+ counter_names = @application.counter_names
193
+ counter_names.should include 'test'
194
+ counter_names.should include 'testme'
195
+
196
+ response = @application.counter 'test'
197
+ counter = response.data.counters.first
198
+ counter.name.should eq 'test'
199
+ counter.values.last.first.value.should eq 2
200
+ end
201
+
202
+ it "should be able to create, retrieve, and delete roles via rolenames" do
203
+ size = @application.rolenames.size
204
+
205
+ role_name = "test-#{SecureRandom.hex}"
206
+ @application.create_entity :rolenames, name: role_name
207
+ role_names = @application.rolenames
208
+ role_names.size.should eq size+1
209
+ role_names.should include role_name
210
+
211
+ @application['rolenames'][role_name].delete
212
+ @application.rolenames.size.should eq size
213
+ end
214
+
215
+ it "should be able to create, retrieve, and delete roles" do
216
+ size = @application.roles.collection.size
217
+
218
+ role_name = "test-#{SecureRandom.hex}"
219
+ @application.create_entity :role, name: role_name, title: 'title', inactivity: 0
220
+ roles = @application.roles.collection
221
+ roles.size.should eq size+1
222
+ role = roles.detect {|r| r.name == role_name }
223
+ role.should_not be_nil
224
+
225
+ role.delete
226
+ @application.roles.collection.size.should eq size
227
+ end
228
+
229
+ it "should be able to add/remove permissions from a user" do
230
+ user = create_random_user @application
231
+ permission = 'post:/users/*'
232
+ user.resource['permissions'].post permission: permission
233
+
234
+ permissions = user.resource['permissions'].get.data.data
235
+ permissions.size.should eq 1
236
+ permissions.first.should eq permission
237
+
238
+ user.resource['permissions'].delete({params: { permission: permission }})
239
+
240
+ permissions = user.resource['permissions'].get.collection.entities
241
+ permissions.size.should eq 0
242
+ end
243
+
244
+ it "should be able to add/remove a user from a roles" do
245
+ user = create_random_user @application
246
+
247
+ roles = user.resource['roles'].get.entities
248
+ size = roles.size
249
+
250
+ @application["roles/admin/users/#{user.uuid}"].post nil
251
+
252
+ roles = user.resource['roles'].get.entities
253
+ roles.size.should == size+1
254
+
255
+ @application["roles/admin/users/#{user.uuid}"].delete
256
+
257
+ roles = user.resource['roles'].get.entities
258
+ roles.size.should == size
259
+ end
260
+
261
+ it "should be able to create a new collection and access it" do # todo
262
+ entities = (1..4).collect do |i|
263
+ { name: "test_#{i}" }
264
+ end
265
+ @application.create_entities 'tests', entities
266
+ response = @application['tests'].get
267
+ collection = response.collection
268
+ collection.size.should eq 4
269
+ end
270
+
271
+ end
@@ -0,0 +1,65 @@
1
+ describe Usergrid::Collection do
2
+
3
+ before :all do
4
+ @application = create_random_application
5
+
6
+ @collection = @application['tests'].collection
7
+ @entity_data = []
8
+ (1..10).each do |i|
9
+ test = { name: "test_#{i}" }
10
+ @entity_data << test
11
+ @collection.create_entity test
12
+ end
13
+
14
+ @user = create_random_user @application, true
15
+ end
16
+
17
+ after :all do
18
+ @user.delete
19
+ delete_application @application
20
+ end
21
+
22
+ it "should be able to query a collection" do
23
+ @collection.query "select * where name = \'#{@entity_data[0][:name]}\'"
24
+ @collection.size.should eq 1
25
+ end
26
+
27
+ it "should be able to find an entity" do
28
+ @collection.query
29
+ entity = @collection.detect { |e| e.name == @entity_data[5][:name] }
30
+ entity.should_not be_nil
31
+ entity.name.should eq @entity_data[5][:name]
32
+ end
33
+
34
+ it "should be able to respect query reversal and limits" do
35
+ @collection.query nil, reversed: true, start: 5, cursor: nil, limit: 2, permission: nil
36
+ @collection.size.should eq 2
37
+ @collection[0].name.should eq @entity_data[9][:name]
38
+ @collection[1].name.should eq @entity_data[8][:name]
39
+ end
40
+
41
+ it "should be able to select the start by uuid" do
42
+ @collection.query
43
+ uuid = @collection[4].uuid
44
+ @collection.query nil, reversed: false, start: uuid, cursor: nil, limit: 3, permission: nil
45
+ @collection.size.should eq 3
46
+ @collection.first.uuid.should eq uuid
47
+ @collection[2].name.should eq @entity_data[6][:name]
48
+ end
49
+
50
+ it "should be able to page forward by cursor" do
51
+ @collection.query nil, limit: 2
52
+ @collection.next_page
53
+ @collection.size.should eq 2
54
+ @collection[0].name.should eq @entity_data[2][:name]
55
+ end
56
+
57
+ #it "should be able to update based on a query" do # todo: enable when server is fixed
58
+ # @collection.update({new_field: 'new_value'}, "select * where name = \'#{@entity_data[4][:name]}\'")
59
+ # @collection.query
60
+ # entity = @collection.detect { |e| e.new_field == 'new_value' }
61
+ # entity.should_not be_nil
62
+ # entity.name.should eq @entity_data[4][:name]
63
+ #end
64
+
65
+ end
@@ -0,0 +1,45 @@
1
+ describe Usergrid::Entity do
2
+
3
+ before :all do
4
+ @application = create_random_application
5
+ @user = create_random_user @application, true
6
+ end
7
+
8
+ after :all do
9
+ @user.delete
10
+ delete_application @application
11
+ end
12
+
13
+ it "should be able to retrieve its collection" do
14
+ collection = @user.collection
15
+ collection.should_not be_nil
16
+ u = collection.detect {|u| u.uuid == @user.uuid }
17
+ u.uuid.should eq @user.uuid
18
+ end
19
+
20
+ it "should be able to reload its data" do
21
+ old_name = @user.name
22
+ @user.name = 'new name'
23
+ @user.name.should eq 'new name'
24
+ @user.get
25
+ @user.name.should eq old_name
26
+ end
27
+
28
+ it "should be able to save" do
29
+ @user.name = 'new name'
30
+ @user.save
31
+ @user.name.should eq 'new name'
32
+ end
33
+
34
+ it "should be able to print itself" do
35
+ p = @user.to_s
36
+ p.start_with?('resource').should be_true
37
+ end
38
+
39
+ it "should know if it has data" do
40
+ @user.data?.should be_true
41
+ empty = Usergrid::Entity.new 'url', 'url'
42
+ empty.data?.should be_false
43
+ end
44
+
45
+ end
@@ -0,0 +1,36 @@
1
+ describe Usergrid::Management do
2
+
3
+ before :all do
4
+ @base_resource = Usergrid::Resource.new(SPEC_SETTINGS[:api_url])
5
+ @management = @base_resource.management
6
+ @management.login SPEC_SETTINGS[:management][:username], SPEC_SETTINGS[:management][:password]
7
+ end
8
+
9
+ it "should be able to create an organization" do
10
+ # can't delete an org or a user, so we create new random ones and leave them
11
+ random = SecureRandom.hex
12
+ org_name = "test_org_#{random}"
13
+ user_name = "test_admin_#{random}"
14
+ response = @management.create_organization("#{org_name}",
15
+ "#{user_name}",
16
+ "#{user_name}",
17
+ "#{user_name}@email.com",
18
+ "#{random}")
19
+ response.code.should eq 200
20
+ #@base_resource["users/#{user_name}"].delete
21
+ end
22
+
23
+ # this is broken on the server
24
+ #it "should be able to get organizations" do
25
+ # response = @management.organizations
26
+ #end
27
+
28
+ it "should be able to get an organization" do
29
+ organization = @management.organization SPEC_SETTINGS[:organization][:name]
30
+ organization.should be_a Usergrid::Organization
31
+ org_ent = organization.get.entity
32
+ org_ent.uuid.should_not be_nil
33
+ org_ent.name.should eq SPEC_SETTINGS[:organization][:name]
34
+ end
35
+
36
+ end
@@ -0,0 +1,72 @@
1
+ describe Usergrid::Organization do
2
+
3
+ before :all do
4
+ @management = Usergrid::Resource.new(SPEC_SETTINGS[:api_url]).management
5
+ @management.login SPEC_SETTINGS[:organization][:username], SPEC_SETTINGS[:organization][:password]
6
+ @organization = @management.organization SPEC_SETTINGS[:organization][:name]
7
+ end
8
+
9
+ it "should be able to create (and delete) an application" do
10
+ app_name = "test_app_#{SecureRandom.hex}"
11
+ app = @organization.create_application app_name
12
+ app.should be_an Usergrid::Application
13
+
14
+ response = @organization["applications/#{app_name}"].delete
15
+ response.code.should eq 200
16
+ end
17
+
18
+ it "should be able to get applications" do
19
+ response = @organization.applications
20
+ response.should be_an Array
21
+ if response.size > 0
22
+ app = response.first
23
+ app.should be_an Usergrid::Application
24
+ end
25
+ end
26
+
27
+ it "should be able to get users" do
28
+ response = @organization.users
29
+ response.code.should eq 200
30
+ response.entities.should be_an Array
31
+ response.entities[0].uuid.should_not be_nil
32
+ end
33
+
34
+ it "should be able to get a user" do
35
+ response = @organization.user(SPEC_SETTINGS[:organization][:username])
36
+ response.code.should eq 200
37
+ response.entity.uuid.should_not be_nil
38
+ end
39
+
40
+ it "should be able to get an application" do
41
+ app_name = "test_app_#{SecureRandom.hex}"
42
+ @organization.create_application app_name
43
+ begin
44
+ app = @organization.application app_name
45
+ app.should be_an Usergrid::Application
46
+ ensure
47
+ @organization["applications/#{app_name}"].delete
48
+ end
49
+ end
50
+
51
+ it "should be able to get feed" do
52
+ response = @organization.feed
53
+ entities = response.entities
54
+ entities.size.should be > 0
55
+ entities.first.uuid.should_not be_nil
56
+ end
57
+
58
+ it "should be able to get credentials" do
59
+ response = @organization.credentials
60
+ response.code.should eq 200
61
+ response.data.credentials.client_id.should_not be_nil
62
+ response.data.credentials.client_secret.should_not be_nil
63
+ end
64
+
65
+ it "should be able to generate credentials" do
66
+ response = @organization.generate_credentials
67
+ response.code.should eq 200
68
+ response.data.credentials.client_id.should_not be_nil
69
+ response.data.credentials.client_secret.should_not be_nil
70
+ end
71
+
72
+ end