google_apps_api 0.1.0 → 0.2.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.
@@ -2,80 +2,251 @@ require 'test_helper'
2
2
 
3
3
  class GoogleAppsApiCalendarTest < Test::Unit::TestCase
4
4
  include GoogleAppsApi
5
-
6
-
7
- context "given a connection to apps.cul" do
8
- setup do
9
- gapps_config =YAML::load_file("private/gapps-config.yml")["apps_ocelot"].symbolize_keys!
10
- @api = Calendar::Api.new(gapps_config)
11
- end
12
5
 
13
- should "have a token" do
14
- assert @api.token
6
+ context "given users" do
7
+ setup do
8
+ @gapps_config =YAML::load_file("private/gapps-config.yml")["apps_ocelot"].symbolize_keys!
9
+ @u1 = UserEntity.new("__user1@ocelot.cul.columbia.edu")
10
+ @u2 = UserEntity.new("__user2@ocelot.cul.columbia.edu")
11
+ @u3 = UserEntity.new("__user3@ocelot.cul.columbia.edu")
15
12
  end
16
13
 
14
+ context "and a calendar api " do
15
+ setup do
16
+ @c_api = Calendar::Api.new(@gapps_config)
17
+ end
17
18
 
18
- # should "be able to retrieve all calendars" do
19
- # calendars = @api.retrieve_all_calendars
20
- #
21
- # assert calendars
22
- # end
23
- #
24
- # should "be able to retrieve all calendars for self" do
25
- # calendars = @api.retrieve_users_calendars(:username => "_sc_api@ocelot.cul.columbia.edu")
26
- # puts calendars.class
27
- # end
28
- #
29
- #
30
- should "be able to retrieve own calendars" do
31
- calendars = @api.retrieve_users_own_calendars(:username => "nco2104@ocelot.cul.columbia.edu")
19
+ should "have a token" do
20
+ assert @c_api.token
21
+ end
22
+
23
+
24
+ should "be associated with only one calendar" do
25
+ all_cals= @u1.get_calendars(@c_api)
26
+ assert_kind_of Array, all_cals
27
+ assert_equal all_cals.length, 1
28
+
29
+ base_cal = all_cals.first
30
+
31
+ assert_kind_of CalendarEntity, base_cal
32
+ assert_equal base_cal.full_id, @u1.full_id # entity_for_base_calendar
33
+ assert_equal base_cal, @u1.entity_for_base_calendar # entity_for_base_calendar
34
+
35
+ end
36
+
37
+ should "be able to retrieve a calendar's acl" do
38
+ u1_cal = @u1.get_calendars(@c_api).detect { |c| c == @u1.entity_for_base_calendar }
39
+ assert u1_cal
40
+
41
+ acls = u1_cal.get_acls(@c_api)
42
+ assert_kind_of Array, acls
43
+
44
+ dom_acl = acls.detect { |a| a.scope == Entity.new(:kind => "domain", :id => "ocelot.cul.columbia.edu")}
45
+ assert dom_acl
46
+ assert_equal dom_acl.role, "read"
47
+ end
48
+
49
+
50
+ should " be able to create, update, remove a calendar's acl" do
51
+ u1_cal = @u1.entity_for_base_calendar
52
+ acls = u1_cal.get_acls(@c_api)
53
+
54
+ u3_freebusy_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "freebusy")
55
+ u3_owner_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "owner")
56
+
57
+ @c_api.remove_calendar_acl(u3_freebusy_u1)
58
+
59
+ acls_before_create = u1_cal.get_acls(@c_api)
60
+ assert_nil acls_before_create.detect { |a| a.scope == @u3}
61
+
62
+ @c_api.set_calendar_acl(u3_freebusy_u1)
63
+
64
+ acls_after_create = u1_cal.get_acls(@c_api)
65
+ assert acls_after_create.detect { |a| a.scope == @u3 && a.role == "freebusy"}
66
+
67
+ @c_api.set_calendar_acl(u3_owner_u1)
68
+
69
+ acls_after_update = u1_cal.get_acls(@c_api)
70
+ assert acls_after_update.detect { |a| a.scope == @u3 && a.role == "owner"}
71
+
72
+
73
+ @c_api.remove_calendar_acl(u3_freebusy_u1)
74
+
75
+ acls_after_delete = u1_cal.get_acls(@c_api)
76
+ assert_nil acls_after_delete.detect { |a| a.scope == @u3}
77
+
78
+ end
79
+
80
+ should " be able to delete a calendar's acl by updating to none" do
81
+ u1_cal = @u1.entity_for_base_calendar
82
+
83
+ u3_freebusy_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "freebusy")
84
+ u3_none_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "none")
85
+
86
+ @c_api.set_calendar_acl(u3_freebusy_u1)
87
+
88
+ acls_after_create = @c_api.retrieve_acls_for_calendar(u1_cal)
89
+ assert acls_after_create.detect { |a| a.scope == @u3 && a.role == "freebusy"}
90
+
91
+ @c_api.set_calendar_acl(u3_none_u1)
92
+
93
+ acls_after_delete = @c_api.retrieve_acls_for_calendar(u1_cal)
94
+ assert_nil acls_after_delete.detect { |a| a.scope == @u3}
95
+ end
96
+
97
+ should " be able to add and remove a subscription if the person is the owner" do
98
+ u1_cal = @u1.entity_for_base_calendar
99
+ acls = u1_cal.get_acls(@c_api)
100
+
101
+ u3_owner_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "owner")
102
+ u3_editor_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "editor")
103
+ u3_none_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "none")
104
+
105
+ @c_api.set_calendar_acl(u3_owner_u1)
106
+ @c_api.add_calendar_to_user(u1_cal, @u3)
107
+
108
+
109
+ assert @c_api.retrieve_calendar_for_user(u1_cal, @u3)
110
+
111
+ @c_api.set_calendar_acl(u3_editor_u1)
32
112
 
113
+ assert @c_api.retrieve_calendar_for_user(u1_cal, @u3)
33
114
 
34
- calendars.each { |c| assert_kind_of CalendarEntry, c }
35
- end
36
-
37
- should "be able to retrieve all calendars subscribed to" do
38
- calendars = @api.retrieve_users_calendars(:username => "nco2104@ocelot.cul.columbia.edu")
115
+ @c_api.set_calendar_acl(u3_none_u1)
116
+ @c_api.remove_calendar_from_user(u1_cal, @u3)
117
+
118
+ assert_nil @c_api.retrieve_calendar_for_user(u1_cal, @u3)
119
+ end
120
+
121
+
122
+ should "be able to retrieve a calendar's title and other details" do
123
+ u1_cal = @u1.entity_for_base_calendar
124
+ u1_cal = @c_api.retrieve_calendar_for_user(u1_cal, @u1)
125
+
126
+ assert u1_cal.details.has_key?(:title)
127
+ assert u1_cal.details[:title], "__user1@ocelot.cul.columbia.edu"
128
+
129
+ end
130
+
131
+
132
+
133
+ should "be able to update a calendar's title and selectedness" do
134
+
135
+
136
+
137
+ u1_cal = @u1.get_base_calendar(@c_api)
138
+
139
+ @c_api.update_calendar_for_user(u1_cal, @u1, :summary => "test", :title => "User 1 Calendar", :selected => false)
140
+
141
+ u1_cal = @u1.get_base_calendar(@c_api)
142
+
143
+ assert_equal u1_cal.details[:title], "User 1 Calendar"
144
+ assert_equal u1_cal.details[:timezone], "UTC"
145
+ assert_equal u1_cal.details[:color], "#2952A3"
146
+ assert_equal u1_cal.details[:summary], "test"
147
+ assert_equal u1_cal.details[:accesslevel], "owner"
148
+ assert_equal u1_cal.details[:where], ""
149
+
150
+ assert_false u1_cal.details[:selected]
151
+ assert_false u1_cal.details[:hidden]
152
+
153
+ @c_api.update_calendar_for_user(u1_cal, @u1, :title => "__user1@ocelot.cul.columbia.edu", :summary => "", :selected => true)
154
+
155
+ u1_cal = @u1.get_base_calendar(@c_api)
156
+
157
+
158
+ assert_equal u1_cal.details[:title], "__user1@ocelot.cul.columbia.edu"
159
+ assert_equal u1_cal.details[:timezone], "UTC"
160
+ assert_equal u1_cal.details[:color], "#2952A3"
161
+ assert_equal u1_cal.details[:summary], ""
162
+ assert_equal u1_cal.details[:accesslevel], "owner"
163
+ assert_equal u1_cal.details[:where], ""
164
+
165
+ assert u1_cal.details[:selected]
166
+ assert_false u1_cal.details[:hidden]
167
+
168
+
169
+
170
+ end
39
171
 
40
- calendars.each { |c| assert_kind_of CalendarEntry, c }
41
172
 
42
- end
43
173
 
174
+ should "be able to update a calendar's selectedness and hiddenness for another user" do
175
+ u1_cal = @u1.entity_for_base_calendar
176
+
177
+
178
+ u3_owner_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "owner")
179
+ u3_freebusy_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "freebusy")
180
+ u3_none_u1 = CalendarAcl.new(:calendar => u1_cal, :scope => @u3, :role => "none")
181
+
182
+ @c_api.set_calendar_acl(u3_owner_u1)
183
+ @c_api.add_calendar_to_user(u1_cal, @u3)
184
+
185
+ @c_api.set_calendar_acl(u3_freebusy_u1)
186
+
187
+
188
+ @c_api.update_calendar_for_user(u1_cal, @u3, :hidden => true, :selected => false)
189
+ u1_cal_u3 = @c_api.retrieve_calendar_for_user(u1_cal, @u3)
190
+
191
+ assert_false u1_cal_u3.details[:selected]
192
+ assert u1_cal_u3.details[:hidden]
193
+
194
+ @c_api.update_calendar_for_user(u1_cal, @u3, :hidden => false, :selected => true)
195
+
196
+ sleep 1
197
+
198
+ u1_cal_u3 = @c_api.retrieve_calendar_for_user(u1_cal, @u3)
199
+
200
+ assert u1_cal_u3
201
+ assert u1_cal_u3.details[:selected]
202
+ assert_false u1_cal_u3.details[:hidden]
203
+
204
+
205
+ @c_api.set_calendar_acl(u3_none_u1)
206
+ @c_api.remove_calendar_from_user(u1_cal, @u3)
207
+
208
+ end
44
209
 
45
- should "be able to add and remove other calendars" do
46
- jws_cal = CalendarEntry.new
47
- jws_cal.id = "jws2135%40ocelot.cul.columbia.edu"
48
- jws_cal.title = "James Stuart"
49
210
 
50
- res = @api.delete_calendar_from_user(jws_cal, "nco2104@ocelot.cul.columbia.edu")
211
+ should "be able to update a calendar's details via set_calendar" do
212
+ u1_cal = @u1.entity_for_base_calendar
51
213
 
52
- count = @api.retrieve_users_calendars(:username => "nco2104@ocelot.cul.columbia.edu").length
214
+ @c_api.remove_calendar_from_user(u1_cal, @u3)
53
215
 
54
- res = @api.add_calendar_to_user(jws_cal, "nco2104@ocelot.cul.columbia.edu")
55
- assert_kind_of CalendarEntry, res
216
+ @c_api.set_calendar_for_user(u1_cal, @u3, :accesslevel => "editor", :hidden => true, :selected => false)
217
+
218
+ u1_cal_u3 = @c_api.retrieve_calendar_for_user(u1_cal, @u3)
219
+
220
+ assert u1_cal_u3
221
+ assert_equal u1_cal_u3.details[:accesslevel], "editor"
222
+ assert_false u1_cal_u3.details[:selected]
223
+ assert u1_cal_u3.details[:hidden]
224
+
225
+ @c_api.set_calendar_for_user(u1_cal, @u3, :hidden => false, :selected => true)
226
+ u1_cal_u3 = @c_api.retrieve_calendar_for_user(u1_cal, @u3)
227
+
228
+ assert u1_cal_u3.details[:selected]
229
+ assert_false u1_cal_u3.details[:hidden]
230
+
231
+ @c_api.set_calendar_for_user(u1_cal, @u3, :accesslevel => "none")
232
+
56
233
 
57
- assert_equal count + 1, @api.retrieve_users_calendars(:username => "nco2104@ocelot.cul.columbia.edu").length
234
+ end
58
235
 
59
- res = @api.delete_calendar_from_user(res, "nco2104@ocelot.cul.columbia.edu")
60
236
 
61
- assert_equal count , @api.retrieve_users_calendars(:username => "nco2104@ocelot.cul.columbia.edu").length
237
+ should "be able to set a title for a calendar via set_calendar" do
238
+ @c_api.set_calendar_for_user(@u1.entity_for_base_calendar, @u1, :title => "User 1 Calendar")
239
+
240
+ assert_equal @u1.get_base_calendar(@c_api).details[:title], "User 1 Calendar"
62
241
 
63
- end
242
+ @c_api.set_calendar_for_user(@u1.entity_for_base_calendar, @u1, :title => "__user1@ocelot.cul.columbia.edu")
64
243
 
65
244
 
66
- end
245
+ assert_equal @u1.get_base_calendar(@c_api).details[:title], "__user1@ocelot.cul.columbia.edu"
246
+
247
+ end
67
248
 
68
- context "given a calendar entry" do
69
- setup do
70
- @jws_cal = CalendarEntry.new
71
- @jws_cal.id = "jws2135%40ocelot.cul.columbia.edu"
72
- @jws_cal.title = "James Stuart"
73
- end
74
-
75
- should "generate an add message" do
76
- assert_kind_of String, @jws_cal.add_message
77
249
  end
78
-
79
- end
80
250
 
251
+ end
81
252
  end
@@ -1,27 +1,103 @@
1
- # require 'test_helper'
2
- #
3
- # class GappsContactsTest < Test::Unit::TestCase
4
- #
5
- # context "given a connection to apps.cul" do
6
- # setup do
7
- # gapps_config =YAML::load_file("private/gapps-config.yml")["apps_ocelot"].symbolize_keys!
8
- # @api = GoogleAppsApi::SharedContacts::Api.new(gapps_config)
9
- # end
10
- #
11
- # should "have a token" do
12
- # assert @api.token
13
- # end
14
- #
15
- # should "be able to create user" do
16
- # @api.create_contact(:name => "Nada API O'Neal", :email => { "home" => "nco2104@columbia.edu", "work" => "nco2104@apps.cul.columbia.edu"})
17
- # end
18
- #
19
- # should "be able to retrieve user" do
20
- # assert @api.retrieve_all
21
- # end
22
- #
23
- #
24
- #
25
- # end
26
- #
27
- # end
1
+ require 'test_helper'
2
+
3
+ class GoogleAppsApiContactsTest < Test::Unit::TestCase
4
+ include GoogleAppsApi
5
+
6
+ context "given a connection to apps.cul" do
7
+ setup do
8
+ gapps_config =YAML::load_file("private/gapps-config.yml")["apps_cul"].symbolize_keys!
9
+ @co_api = Contacts::Api.new(gapps_config)
10
+ end
11
+
12
+ should "have a token" do
13
+ assert @co_api.token
14
+ end
15
+ #
16
+ # should "be able to retrieve user" do
17
+ # resp = @api.retrieve_user("jws2135")
18
+ #
19
+ # assert_kind_of UserEntity, resp
20
+ #
21
+ # assert_equal resp.id, "jws2135"
22
+ # end
23
+ #
24
+ # should "throw an error if given an invalid user" do
25
+ # assert_raises GDataError do
26
+ # resp = @api.retrieve_user("xx_jws2135")
27
+ # end
28
+ # end
29
+ #
30
+ #
31
+ should "be able to retrieve all contacts" do
32
+ cons = @co_api.retrieve_all_contacts
33
+ assert_kind_of Array, cons
34
+
35
+ end
36
+
37
+ # should "be able to remove all contacts" do
38
+ # cons = @co_api.retrieve_all_contacts
39
+ #
40
+ # cons.each do |con|
41
+ # @co_api.remove_contact(con, :debug => true)
42
+ # end
43
+ # end
44
+
45
+ #
46
+ # should "be able to create a contact" do
47
+ # contact = ContactEntity.new(:id => "_new_", :name => "Bizarre Test", :emails => {:work => "james.stuart+bizarretest@columbia.edu", :home => "james.stuart+bizarretest@gmail.com"}, :primary_email => :work)
48
+ # res = @co_api.create_contact(contact, :debug => true)
49
+ #
50
+ # assert_kind_of ContactEntity, res
51
+ #
52
+ # puts res.inspect
53
+ #
54
+ # # @co_api.remove_contact(res, :debug => true)
55
+ #
56
+ # end
57
+ #
58
+
59
+
60
+ #
61
+ #
62
+ #
63
+ # should "be able to create and delete a user" do
64
+ # uid = random_letters(9, "_t_")
65
+ #
66
+ # assert_raises GDataError do
67
+ # @api.retrieve_user(uid)
68
+ # end
69
+ #
70
+ # @api.create_user(uid, :given_name => random_letters(5), :family_name => random_letters(5), :password => random_letters(10))
71
+ #
72
+ # assert_kind_of UserEntity, @api.retrieve_user(uid)
73
+ #
74
+ # @api.delete_user(uid)
75
+ #
76
+ #
77
+ # assert_raises GDataError do
78
+ # @api.retrieve_user(uid)
79
+ # end
80
+ #
81
+ #
82
+ # end
83
+ #
84
+ #
85
+ #
86
+ #
87
+ # should "be able to update a user" do
88
+ # uid = "jws2135"
89
+ #
90
+ # @api.update_user(uid, :given_name => "Jimmy", :family_name => "Stuart")
91
+ #
92
+ # assert_equal "Jimmy", @api.retrieve_user(uid).given_name
93
+ #
94
+ # @api.update_user(uid, :given_name => "James", :family_name => "Stuart")
95
+ #
96
+ # assert_equal "James", @api.retrieve_user(uid).given_name
97
+ #
98
+ # end
99
+ #
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class GoogleAppsApiOffDomainCalendarTest < Test::Unit::TestCase
4
+ include GoogleAppsApi
5
+
6
+ context "given users" do
7
+ setup do
8
+ @gapps_config =YAML::load_file("private/gapps-config.yml")["apps_ocelot"].symbolize_keys!
9
+ @u1 = UserEntity.new("__user1@ocelot.cul.columbia.edu")
10
+ @u2 = UserEntity.new("__user2@ocelot.cul.columbia.edu")
11
+ @u3 = UserEntity.new("__user3@ocelot.cul.columbia.edu")
12
+ end
13
+
14
+ context "and a calendar api " do
15
+ setup do
16
+ @c_api = Calendar::Api.new(@gapps_config)
17
+ end
18
+
19
+ should "be able to set off domain acls" do
20
+ u1_cal = @u1.entity_for_base_calendar
21
+ james_off = CalendarAcl.new(:calendar => u1_cal, :scope => UserEntity.new("apps.cul.columbia.edu_@domain.calendar.google.com"), :role => "read")
22
+
23
+ @c_api.set_calendar_acl(james_off)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -16,9 +16,9 @@ class GoogleAppsApiProvisioningTest < Test::Unit::TestCase
16
16
  should "be able to retrieve user" do
17
17
  resp = @api.retrieve_user("jws2135")
18
18
 
19
- assert_kind_of UserEntry, resp
19
+ assert_kind_of UserEntity, resp
20
20
 
21
- assert_equal resp.username, "jws2135"
21
+ assert_equal resp.id, "jws2135"
22
22
  end
23
23
 
24
24
  should "throw an error if given an invalid user" do
@@ -41,10 +41,9 @@ class GoogleAppsApiProvisioningTest < Test::Unit::TestCase
41
41
  @api.retrieve_user(uid)
42
42
  end
43
43
 
44
- ue = UserEntry.new()
45
44
  @api.create_user(uid, :given_name => random_letters(5), :family_name => random_letters(5), :password => random_letters(10))
46
45
 
47
- assert_kind_of UserEntry, @api.retrieve_user(uid)
46
+ assert_kind_of UserEntity, @api.retrieve_user(uid)
48
47
 
49
48
  @api.delete_user(uid)
50
49
 
data/test/test_helper.rb CHANGED
@@ -9,6 +9,11 @@ require 'google_apps_api'
9
9
 
10
10
  class Test::Unit::TestCase
11
11
 
12
+ def assert_false(object, message="")
13
+ assert_equal(false, object, message)
14
+ end
15
+
16
+
12
17
  def random_letters(num, prefix = "", suffix = "")
13
18
  prefix + (0...num).map{65.+(rand(25)).chr}.join + suffix
14
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_apps_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stuart
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-05 00:00:00 -04:00
12
+ date: 2010-05-25 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,8 @@ files:
70
70
  - VERSION
71
71
  - google_apps_api.gemspec
72
72
  - lib/config/calendar.yml
73
+ - lib/config/contacts.yml
74
+ - lib/config/profiles.yml
73
75
  - lib/config/provisioning.yml
74
76
  - lib/google_apps_api.rb
75
77
  - lib/google_apps_api/base_api.rb
@@ -80,11 +82,12 @@ files:
80
82
  - lib/google_apps_api/provisioning.rb
81
83
  - lib/google_apps_api/user_profiles.rb
82
84
  - lib/load_config.rb
83
- - private/gapps-config.yml
84
- - private/userscalendars.xml
85
+ - test/example_connection_config.yml
85
86
  - test/google_apps_api-calendar_resources_test.rb
87
+ - test/google_apps_api_base_api_test.rb
86
88
  - test/google_apps_api_calendar_test.rb
87
89
  - test/google_apps_api_contacts_test.rb
90
+ - test/google_apps_api_off_domain_calendar_test.rb
88
91
  - test/google_apps_api_provisioning_test.rb
89
92
  - test/google_apps_api_user_profiles_test.rb
90
93
  - test/helper.rb
@@ -119,8 +122,10 @@ specification_version: 3
119
122
  summary: Various APIs for Google Apps
120
123
  test_files:
121
124
  - test/google_apps_api-calendar_resources_test.rb
125
+ - test/google_apps_api_base_api_test.rb
122
126
  - test/google_apps_api_calendar_test.rb
123
127
  - test/google_apps_api_contacts_test.rb
128
+ - test/google_apps_api_off_domain_calendar_test.rb
124
129
  - test/google_apps_api_provisioning_test.rb
125
130
  - test/google_apps_api_user_profiles_test.rb
126
131
  - test/helper.rb
@@ -1,5 +0,0 @@
1
- apps_ocelot:
2
- domain: ocelot.cul.columbia.edu
3
- admin_user: _sc_api
4
- admin_password: G6Jb1sYEbYVwye
5
- admin_email: _sc_api@ocelot.cul.columbia.edu