appengine-apis 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,14 @@
1
1
  begin
2
2
  require 'spec'
3
+ require 'appengine-sdk'
3
4
  rescue LoadError
4
5
  require 'rubygems'
5
- gem 'rspec'
6
6
  require 'spec'
7
+ require 'appengine-sdk'
7
8
  end
8
9
 
9
10
  $:.unshift(File.dirname(__FILE__) + '/../lib')
11
+ AppEngine::SDK.load_apiproxy
10
12
  require 'appengine-apis/testing'
11
13
  AppEngine::Testing.install_test_env
12
14
 
@@ -0,0 +1,110 @@
1
+ # Copyright:: Copyright 2009 Google Inc.
2
+ # Original Author:: Ryan Brown (mailto:ribrdb@google.com)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require File.dirname(__FILE__) + '/spec_helper.rb'
17
+ AppEngine::SDK.load_labs
18
+ require 'appengine-apis/labs/taskqueue'
19
+
20
+ TaskQueueAddRequest = JavaUtilities.get_proxy_or_package_under_package(
21
+ com.google.appengine.api.labs.taskqueue,
22
+ 'TaskQueuePb$TaskQueueAddRequest'
23
+ )
24
+ TaskQueueAddResponse = JavaUtilities.get_proxy_or_package_under_package(
25
+ com.google.appengine.api.labs.taskqueue,
26
+ 'TaskQueuePb$TaskQueueAddResponse'
27
+ )
28
+
29
+ describe AppEngine::Labs::TaskQueue do
30
+
31
+ before :each do
32
+ @delegate = mock_delegate
33
+ AppEngine::ApiProxy.set_delegate(@delegate)
34
+ @Queue = AppEngine::Labs::TaskQueue::Queue
35
+ @Task = AppEngine::Labs::TaskQueue::Task
36
+ end
37
+
38
+
39
+ def expect_add(request, name = nil)
40
+ response = TaskQueueAddResponse.new
41
+ response.set_chosen_task_name(name) if name
42
+
43
+ @delegate.should_receive(:makeSyncCall).with(
44
+ anything, 'taskqueue', 'Add',
45
+ proto(TaskQueueAddRequest, request)).and_return(response.to_byte_array)
46
+ end
47
+
48
+ describe AppEngine::Labs::TaskQueue::Queue do
49
+ it 'should have name' do
50
+ @Queue.new('foo').name.should == 'foo'
51
+ @Queue.new('bar').name.should == 'bar'
52
+ end
53
+
54
+ it 'should have a default queue' do
55
+ @Queue.new().name.should == 'default'
56
+ end
57
+ end
58
+
59
+ describe AppEngine::Labs::TaskQueue::Task do
60
+ before :each do
61
+ @payload = 'this is the example payload'
62
+ @binary_payload = "f\0\0bar"
63
+ @params = {
64
+ 'one$funny&' => 'fish',
65
+ 'red' => 'blue with spaces',
66
+ 'fish' => ['guppy', 'flounder'],
67
+ }
68
+ @params_query = 'one%24funny%26=fish&fish=guppy&fish=flounder' +
69
+ '&red=blue+with+spaces'
70
+ end
71
+
72
+ it 'should set payload and method' do
73
+ expect_add({:body => @payload, :method => 2})
74
+ t = @Task.new(@payload).add
75
+ end
76
+
77
+ it 'should support Blob' do
78
+ expect_add({:body => @binary_payload})
79
+ t = @Task.new(AppEngine::Datastore::Blob.new(@binary_payload)).add
80
+ end
81
+
82
+ it 'should support bytes' do
83
+ expect_add({:body => @binary_payload})
84
+ t = @Task.new(:bytes => @binary_payload).add
85
+ end
86
+
87
+ end
88
+
89
+ it 'should support add' do
90
+ expect_add({:queue_name => 'default'}, 'foobar')
91
+ now = Time.now
92
+ t = AppEngine::Labs::TaskQueue.add
93
+ t.name.should == 'foobar'
94
+ t.queue.should == 'default'
95
+ t.eta.should be >= now
96
+ end
97
+
98
+ it 'should support add with options' do
99
+ expect_add({:body => 'payload', :method => 2, :queue_name => 'default'},
100
+ 'foobar')
101
+ now = Time.now
102
+ t = AppEngine::Labs::TaskQueue.add('payload')
103
+ t.name.should == 'foobar'
104
+ t.queue.should == 'default'
105
+ t.eta.should be >= now
106
+ end
107
+
108
+ # TODO add more specs
109
+
110
+ end
@@ -101,6 +101,11 @@ describe AppEngine::URLFetch do
101
101
  AppEngine::URLFetch.fetch(@url).body.should == 'bar\0'
102
102
  end
103
103
 
104
+ it 'should support deadline' do
105
+ fetch_and_return(200, 'bar\0')
106
+ AppEngine::URLFetch.fetch(@url, :deadline => 2).body.should == 'bar\0'
107
+ end
108
+
104
109
  # TODO can't read fetch options, so there's no way to tell if they're set
105
110
  end
106
111
 
@@ -0,0 +1,223 @@
1
+ # Copyright:: Copyright 2009 Google Inc.
2
+ # Original Author:: Ryan Brown (mailto:ribrdb@google.com)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require File.dirname(__FILE__) + '/spec_helper.rb'
17
+ require 'appengine-apis/xmpp'
18
+
19
+ module Proto
20
+ %w(PresenceRequest PresenceResponse
21
+ XmppInviteRequest XmppInviteResponse
22
+ XmppMessageRequest XmppMessageResponse
23
+ XmppServiceError).each do |name|
24
+ const_set(name, JavaUtilities.get_proxy_or_package_under_package(
25
+ com.google.appengine.api.xmpp, "XMPPServicePb$#{name}"
26
+ ))
27
+ end
28
+ end
29
+
30
+
31
+ # TODO test error handling
32
+ describe AppEngine::XMPP do
33
+
34
+ before :each do
35
+ @delegate = mock_delegate
36
+ AppEngine::ApiProxy.set_delegate(@delegate)
37
+ end
38
+
39
+ def expect_presence(jid, available=true, from='')
40
+ request = {
41
+ :jid => jid,
42
+ :from_jid => from
43
+ }
44
+ response = Proto::PresenceResponse.new
45
+ response.set_is_available(available)
46
+
47
+ @delegate.should_receive(:makeSyncCall).with(
48
+ anything, 'xmpp', 'GetPresence', proto(Proto::PresenceRequest, request)
49
+ ).and_return(response.to_byte_array)
50
+ end
51
+
52
+ def expect_invitation(jid, from='')
53
+ request = {
54
+ :jid => jid,
55
+ :from_jid => from
56
+ }
57
+ @delegate.should_receive(:makeSyncCall).with(
58
+ anything, 'xmpp', 'SendInvite', proto(Proto::XmppInviteRequest, request)
59
+ ).and_return(Proto::XmppInviteResponse.new.to_byte_array)
60
+ end
61
+
62
+ def expect_send(request, *statuses)
63
+ response = Proto::XmppMessageResponse.new
64
+ statuses.each do |status|
65
+ status = case status
66
+ when :ok
67
+ Proto::XmppMessageResponse::XmppMessageStatus::NO_ERROR.value
68
+ when :invalid_jid
69
+ Proto::XmppMessageResponse::XmppMessageStatus::INVALID_JID.value
70
+ when :error
71
+ Proto::XmppMessageResponse::XmppMessageStatus::OTHER_ERROR.value
72
+ end
73
+ response.add_status(status)
74
+ end
75
+ @delegate.should_receive(:makeSyncCall).with(
76
+ anything, 'xmpp', 'SendMessage', proto(Proto::XmppMessageRequest, request)
77
+ ).and_return(response.to_byte_array)
78
+ end
79
+
80
+ describe 'get_presence' do
81
+ it 'should set jid' do
82
+ expect_presence('foo@example.com')
83
+ presence = AppEngine::XMPP.get_presence('foo@example.com')
84
+ presence.should be_a_kind_of AppEngine::XMPP::Presence
85
+ presence.available?.should == true
86
+ end
87
+
88
+ it 'should set sender' do
89
+ expect_presence('foo@example.com', true, 'bar@appspot.com')
90
+ presence = AppEngine::XMPP.get_presence(
91
+ 'foo@example.com', 'bar@appspot.com')
92
+ presence.should be_a_kind_of AppEngine::XMPP::Presence
93
+ presence.available?.should == true
94
+ end
95
+
96
+ it 'should set presence' do
97
+ expect_presence('foo@example.com', false)
98
+ presence = AppEngine::XMPP.get_presence(
99
+ 'foo@example.com')
100
+ presence.should be_a_kind_of AppEngine::XMPP::Presence
101
+ presence.available?.should == false
102
+ end
103
+ end
104
+
105
+ describe 'send_invitation' do
106
+ it 'should set jid' do
107
+ expect_invitation('foo@example.com')
108
+ AppEngine::XMPP.send_invitation('foo@example.com')
109
+ end
110
+
111
+ it 'should set sender' do
112
+ expect_invitation('foo@example.com', 'bar@appspot.com')
113
+ AppEngine::XMPP.send_invitation('foo@example.com', 'bar@appspot.com')
114
+ end
115
+ end
116
+
117
+ describe 'send_message' do
118
+ it 'should send message' do
119
+ expect_send({:jid => ['foo@example.com'], :body => 'Hello!'}, :ok)
120
+ status = AppEngine::XMPP.send_message('foo@example.com', 'Hello!')
121
+ status.should == [AppEngine::XMPP::Status::NO_ERROR]
122
+ end
123
+
124
+ it 'should set status' do
125
+ expect_send({:jid => ['a@example.com', 'b', 'c@foo.com']},
126
+ :ok, :invalid_jid, :error)
127
+ status = AppEngine::XMPP.send_message(
128
+ ['a@example.com', 'b', 'c@foo.com'], 'Hello!')
129
+ status.should == [
130
+ AppEngine::XMPP::Status::NO_ERROR,
131
+ AppEngine::XMPP::Status::INVALID_JID,
132
+ AppEngine::XMPP::Status::OTHER_ERROR
133
+ ]
134
+ end
135
+ end
136
+
137
+ describe AppEngine::XMPP::Message do
138
+ describe 'initialize' do
139
+ it 'should support minimal args' do
140
+ message = AppEngine::XMPP::Message.new('foo@example.com', 'Hi')
141
+ message.recipients.should == ['foo@example.com']
142
+ message.body.should == 'Hi'
143
+ message.sender.should == nil
144
+ message.type.should == :chat
145
+ message.xml?.should == false
146
+ end
147
+
148
+ it 'should require body' do
149
+ no_to = lambda{AppEngine::XMPP::Message.new(nil, 'Hi')}
150
+ no_body = lambda{AppEngine::XMPP::Message.new('foo@example.com')}
151
+ no_to.should raise_error(ArgumentError)
152
+ no_body.should raise_error(ArgumentError)
153
+ end
154
+
155
+ it 'should support positional args' do
156
+ message = AppEngine::XMPP::Message.new(
157
+ 'foo@example.com', 'Hello, world!', 'test@appspot.com', :error,
158
+ true)
159
+ message.recipients.should == ['foo@example.com']
160
+ message.sender.should == 'test@appspot.com'
161
+ message.body.should == 'Hello, world!'
162
+ message.type.should == :error
163
+ message.xml?.should == true
164
+ end
165
+
166
+ it 'should support hash args' do
167
+ message = AppEngine::XMPP::Message.new(
168
+ :to =>'foo@example.com',
169
+ :body => 'Hello, world!',
170
+ :from => 'test@appspot.com',
171
+ :type => :error,
172
+ :xml => true)
173
+ message.recipients.should == ['foo@example.com']
174
+ message.sender.should == 'test@appspot.com'
175
+ message.body.should == 'Hello, world!'
176
+ message.type.should == :error
177
+ message.xml?.should == true
178
+ end
179
+
180
+ it 'should support combo args' do
181
+ message = AppEngine::XMPP::Message.new(
182
+ 'foo@example.com', 'Hello, world!', :from => 'test@appspot.com')
183
+ message.recipients.should == ['foo@example.com']
184
+ message.body.should == 'Hello, world!'
185
+ message.sender.should == 'test@appspot.com'
186
+ end
187
+ end
188
+
189
+ describe 'command parsing' do
190
+ it 'should set arg for non-command message' do
191
+ message = AppEngine::XMPP::Message.new('a@example.com', 'Hello there')
192
+ message.command.should == nil
193
+ message.arg.should == 'Hello there'
194
+ end
195
+
196
+ it 'should parse slash commands' do
197
+ message = AppEngine::XMPP::Message.new('a@example.com', '/test foo bar')
198
+ message.command.should == 'test'
199
+ message.arg.should == 'foo bar'
200
+ end
201
+
202
+ it 'should parse backslash commands' do
203
+ message = AppEngine::XMPP::Message.new('a@example.com', '\test foo bar')
204
+ message.command.should == 'test'
205
+ message.arg.should == 'foo bar'
206
+ end
207
+ end
208
+
209
+ describe 'reply' do
210
+ it 'should send a reply' do
211
+ expect_send({
212
+ :jid => ['foo@example.com'],
213
+ :body => 'Bye',
214
+ :from_jid => 'test@appspot.com'
215
+ }, :ok)
216
+ message = AppEngine::XMPP::Message.new(
217
+ 'test@appspot.com', 'Hi', 'foo@example.com')
218
+ message.reply('Bye')
219
+ end
220
+ end
221
+ end
222
+
223
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appengine-apis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-13 00:00:00 -07:00
12
+ date: 2009-09-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,8 @@ description: |-
51
51
  - AppEngine::Memcache
52
52
  - AppEngine::URLFetch
53
53
  - AppEngine::Datastore
54
+ - AppEngine::XMPP
55
+ - AppEngine::Labs::TaskQueue
54
56
 
55
57
  Unless you're implementing your own ORM, you probably want to use the
56
58
  DataMapper API instead of the lower level AppEngine::Datastore API.
@@ -72,6 +74,7 @@ files:
72
74
  - lib/appengine-apis/apiproxy.rb
73
75
  - lib/appengine-apis/datastore.rb
74
76
  - lib/appengine-apis/datastore_types.rb
77
+ - lib/appengine-apis/labs/taskqueue.rb
75
78
  - lib/appengine-apis/local_boot.rb
76
79
  - lib/appengine-apis/logger.rb
77
80
  - lib/appengine-apis/mail.rb
@@ -81,6 +84,8 @@ files:
81
84
  - lib/appengine-apis/testing.rb
82
85
  - lib/appengine-apis/urlfetch.rb
83
86
  - lib/appengine-apis/users.rb
87
+ - lib/appengine-apis/xmpp.rb
88
+ - lib/appengine-apis/tempfile.rb
84
89
  - script/console
85
90
  - script/destroy
86
91
  - script/generate
@@ -91,8 +96,10 @@ files:
91
96
  - spec/memcache_spec.rb
92
97
  - spec/spec.opts
93
98
  - spec/spec_helper.rb
99
+ - spec/taskqueue_spec.rb
94
100
  - spec/urlfetch_spec.rb
95
101
  - spec/users_spec.rb
102
+ - spec/xmpp_spec.rb
96
103
  - tasks/rspec.rake
97
104
  has_rdoc: true
98
105
  homepage: http://code.google.com/p/appengine-jruby