rtmilk 0.0.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/rtm_api_test.rb CHANGED
@@ -1,20 +1,34 @@
1
1
  #
2
- # tests for rtm.rb
2
+ # tests for RTM::API.
3
3
  #
4
4
  # see http://d.hatena.ne.jp/secondlife/20060927/1159334813
5
5
  #
6
- # $Id: test_rtm_api.rb 10 2006-12-30 06:37:24Z takayama $
7
- #
8
6
 
9
7
  require File.dirname(__FILE__) + '/test_helper.rb'
10
8
 
9
+ # fake class
10
+ class TestAPI
11
+ include RTM::API
12
+
13
+ def initialize
14
+ @method = 'rtm.test.echo'
15
+ @param = {'method' => @method}
16
+ end
17
+
18
+ def parse_result(result)
19
+ if result['stat'] == 'ok'
20
+ [result['method'].first, result['stat']]
21
+ else
22
+ ["error", result['stat']]
23
+ end
24
+ end
25
+ end # TestAPI
26
+
11
27
  class RTMAPITest < Test::Unit::TestCase
12
28
  CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
13
29
 
14
30
  KEY = 'aaa' # XXX specify API key
15
31
  SEC = 'bbb' # XXX specify shared secret
16
- FROB = 'ccc' # XXX enter some frob
17
- TOKEN = 'ddd' # XXX enter some token
18
32
 
19
33
  def setup
20
34
  conf = begin
@@ -22,143 +36,48 @@ class RTMAPITest < Test::Unit::TestCase
22
36
  rescue
23
37
  {
24
38
  :key => KEY,
25
- :secret => SEC,
26
- :frob => FROB,
27
- :token => TOKEN }
39
+ :sec => SEC,
40
+ }
28
41
  end
29
42
 
30
- RTM::API.init(conf)
31
- # @base = RTM::API.new(KEY, SIG)
32
- # @test = RTM::TestAPI.new(KEY, SIG)
33
- # @auth = RTM::AuthAPI.new(KEY, SIG)
34
- # @lists = RTM::ListsAPI.new(KEY, SIG)
35
- # @tasks = RTM::TasksAPI.new(KEY, SIG)
36
- end
37
-
38
- def test_init
39
- assert_equal(1, RTM::API.params.size)
40
- end
41
-
42
- def test_instance
43
- # assert_instance_of RTM::API, @base
44
- # assert_instance_of RTM::TestAPI, @test
45
- # assert_instance_of RTM::AuthAPI, @auth
46
- # assert_instance_of RTM::ListsAPI, @lists
47
- # assert_instance_of RTM::TasksAPI, @tasks
48
- end
49
-
50
- # -------------------------------------------------------------------
51
- # API
52
- #
53
- def test_sign
54
- sign = RTM::API.sign(RTM::API.params)
55
- assert_equal(32, sign.length)
56
- end
57
-
58
- def test_uri_req
59
- assert_equal(1, RTM::API.params.keys.size)
60
- ur = RTM::API.uri_req(RTM::API.params)
61
- assert_not_nil(ur)
62
- assert_equal(1, RTM::API.params.keys.size)
63
- end
64
-
65
- def test_uri_auth
66
- assert_equal(1, RTM::API.params.keys.size)
67
- ra = RTM::API.uri_auth(RTM::API.params, 'read')
68
- assert_not_nil(ra)
69
- assert_equal(1, RTM::API.params.keys.size)
43
+ RTM::API.init(conf[:key], conf[:sec], conf)
70
44
  end
71
45
 
72
- def test_auth_uri
73
- au = RTM::API.auth_uri(RTM::API.params, 'read')
74
- assert_not_nil(au)
46
+ def teardown
75
47
  end
76
48
 
77
- def test_uri_auth_frob
78
- frob = RTM::API::Auth.getFrob
79
- assert_not_nil(frob)
80
- assert_equal(40, frob.length)
81
-
82
- RTM::API::PERMS.each do |p|
83
- ra = RTM::API.uri_auth(RTM::API.params, {'perm'=>p, 'frob'=>frob})
84
- assert_not_nil(ra)
85
- assert_equal(1, RTM::API::params.keys.size)
49
+ def test_get_auth_url
50
+ def check_include(url)
51
+ assert_equal(0, url =~ /http:\/\//)
52
+ assert_equal(7, url =~ /www\.rememberthemilk\.com/)
53
+ assert_not_nil(url =~ /api_key/)
54
+ assert_not_nil(url =~ /perms/)
55
+ assert_not_nil(url =~ /api_sig/)
86
56
  end
87
- end
88
-
89
- # -------------------------------------------------------------------
90
- # Auth
91
- #
92
- def test_authGetFrob
93
- frob = RTM::API::Auth.getFrob
94
- assert_not_nil(frob)
95
- assert_equal(40, frob.length)
96
- end
97
57
 
98
- =begin
99
- def test_authGetToken
100
- frob = @auth.getFrob
101
- assert_not_nil(frob)
102
- assert_equal(40, frob.length)
58
+ url = RTM::API.get_auth_url('read')
59
+ check_include(url)
103
60
 
104
- ra = @base.uri_auth('read', frob)
105
- assert_not_nil(ra)
61
+ url = RTM::API.get_auth_url('delete', 'asb')
62
+ check_include(url)
63
+ assert_not_nil(url =~ /frob/)
106
64
 
107
- puts 'auth this url : ' + 'http://' + RTM::RTM_URI + ra
108
- # @base.auth(ra)
109
- gets
110
-
111
- token = @auth.getToken(frob)
112
- assert_not_nil(token)
113
- p token
114
- assert_equal(40, token.length)
115
- end
116
- =end
117
-
118
- def test_authCheckToken
119
- assert_raise(RTM::API::Error) {
120
- RTM::API::Auth.checkToken(TOKEN + 'a')
121
- }
122
- assert_nothing_raised {
123
- checked = RTM::API::Auth.checkToken(RTM::API.token)
124
- assert_not_nil(checked)
125
- }
126
65
  end
127
66
 
128
- def test_taskGetList
129
- tasks = RTM::API::Tasks.getList
130
- assert_not_nil(tasks)
131
- end
132
-
133
-
134
- =begin
135
- def test_testEcho
136
- @test.echo
137
- end
138
-
139
- def test_testLogin
140
- @test.login
141
- end
142
-
143
- def test_getList
144
- @lists.get
145
- end
146
- =end
147
-
148
- # -------------------------------------------------------------------
149
- # API test
150
- #
151
- def test_api_init
152
- RTM::API.init(:key => KEY)
67
+ def test_sign
68
+ tapi = TestAPI.new
69
+ signed = tapi.sign
70
+ assert_equal(32, signed.length)
153
71
 
154
- assert_equal(KEY, RTM::API.key)
72
+ signed = RTM::API.sign({'method' => 'get'})
73
+ assert_equal(32, signed.length)
155
74
  end
156
75
 
157
- # -------------------------------------------------------------------
158
- # TimeLines API test
159
- #
160
- def test_timelines_create
161
- timeline = RTM::API::TimeLines.create
162
- assert_not_nil(timeline)
76
+ def test_invoke
77
+ tapi = TestAPI.new
78
+ res, err = tapi.invoke
79
+ assert_equal('rtm.test.echo', res)
80
+ assert_equal('ok', err)
163
81
  end
164
82
  end
83
+ # vim:fdm=indent
@@ -0,0 +1,88 @@
1
+ #
2
+ # tests for RTM::Tasks API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMTasksAPITest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ conf = begin
12
+ Marshal.load(open(CONFIG))
13
+ rescue
14
+ puts 'please run make_config.rb first.'
15
+ exit
16
+ end
17
+
18
+ RTM::API.init(conf[:key], conf[:sec], conf)
19
+ @perms = 'delete'
20
+ @token = conf[:token]
21
+ end
22
+
23
+ def teardown
24
+ end
25
+
26
+ # -----------------------------------------------------------------
27
+ # helper
28
+ #
29
+
30
+ # -----------------------------------------------------------------
31
+ # tests
32
+ #
33
+ def not_test_getList
34
+ lists, err = RTM::Tasks::GetList.new(@token).invoke
35
+ assert_equal('ok', err)
36
+ assert_instance_of(Array, lists)
37
+ end
38
+
39
+ def not_test_add
40
+ timeline = RTM::Timelines::Create.new(@token).invoke
41
+ assert_equal(7, timeline.length)
42
+
43
+ lists, err = RTM::Lists::GetList.new(@token).invoke
44
+ assert_equal('ok', err)
45
+ assert_instance_of(Array, lists)
46
+
47
+ list, err, transaction = RTM::Tasks::Add.new(
48
+ @token, timeline, lists.first['id'], 'testTaskAdd').invoke
49
+ assert_equal('ok', err)
50
+ end
51
+
52
+ def not_test_delete
53
+ timeline = RTM::Timelines::Create.new(@token).invoke
54
+ assert_equal(7, timeline.length)
55
+
56
+ lists, err = RTM::Lists::GetList.new(@token).invoke
57
+ assert_equal('ok', err)
58
+ assert_instance_of(Array, lists)
59
+
60
+ taskseries = '2855723' # XXX
61
+ task = '4001630' # XXX
62
+
63
+ list, err, transaction = RTM::Tasks::Delete.new(
64
+ @token, timeline, lists.first['id'], taskseries, task).invoke
65
+ assert_equal('ok', err)
66
+ end
67
+
68
+ def test_add_delete
69
+ timeline = RTM::Timelines::Create.new(@token).invoke
70
+ assert_equal(7, timeline.length)
71
+
72
+ lists = RTM::Lists::GetList.new(@token).invoke
73
+ assert_instance_of(Array, lists)
74
+ list = lists.first['id']
75
+
76
+ list_a, transaction_add = RTM::Tasks::Add.new(
77
+ @token, timeline, list, 'testTaskAdd').invoke
78
+
79
+ taskseries = list_a['taskseries'].first['id']
80
+ task = list_a['taskseries'].first['task'].first['id']
81
+
82
+ list_d, transaction = RTM::Tasks::Delete.new(
83
+ @token, timeline, lists.first['id'], taskseries, task).invoke
84
+ assert_equal(list_a['id'], list_d['id'])
85
+ end
86
+ end
87
+
88
+ # vim:fdm=indent
@@ -0,0 +1,44 @@
1
+ #
2
+ # tests for RTM::Timelines API.
3
+ #
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ class RTMTimelinesAPITest < Test::Unit::TestCase
8
+ CONFIG = File.dirname(__FILE__) + '/../config.dat' # config data file
9
+
10
+ def setup
11
+ conf = begin
12
+ Marshal.load(open(CONFIG))
13
+ rescue
14
+ puts 'please run make_config.rb first.'
15
+ exit
16
+ end
17
+
18
+ RTM::API.init(conf[:key], conf[:sec], conf)
19
+ @token = conf[:token]
20
+ end
21
+
22
+ def teardown
23
+ end
24
+
25
+ # -----------------------------------------------------------------
26
+ # helper
27
+ #
28
+
29
+ # -----------------------------------------------------------------
30
+ # tests
31
+ #
32
+ def test_create
33
+ timeline = RTM::Timelines::Create.new(@token).invoke
34
+ assert_equal(7, timeline.length)
35
+ end
36
+
37
+ def test_instance
38
+ timeline = RTM::Timeline.new(@token)
39
+ assert_equal(7, timeline.length)
40
+ end
41
+ end
42
+
43
+ # vim:fdm=indent
44
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: rtmilk
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-02-05 00:00:00 +09:00
6
+ version: 0.3.0
7
+ date: 2007-03-17 00:00:00 +09:00
8
8
  summary: a "Remember the Milk" wrapper library.
9
9
  require_paths:
10
10
  - lib
@@ -29,20 +29,40 @@ post_install_message:
29
29
  authors:
30
30
  - takayama
31
31
  files:
32
- - Rakefile
33
32
  - README.txt
33
+ - Rakefile
34
34
  - CHANGELOG.txt
35
35
  - Manifest.txt
36
+ - History.txt
36
37
  - setup.rb
38
+ - example/get.rb
39
+ - lib/rtmilk/api/auth.rb
40
+ - lib/rtmilk/api/lists.rb
41
+ - lib/rtmilk/api/notes.rb
42
+ - lib/rtmilk/api/tasks.rb
43
+ - lib/rtmilk/api/timelines.rb
37
44
  - lib/rtmilk/api.rb
45
+ - lib/rtmilk/error.rb
38
46
  - lib/rtmilk/version.rb
39
47
  - lib/rtmilk.rb
48
+ - test/auth_api_test.rb
49
+ - test/error_test.rb
50
+ - test/lists_api_test.rb
51
+ - test/make_config.rb
52
+ - test/notes_api_test.rb
53
+ - test/Rakefile
54
+ - test/tasks_api_test.rb
40
55
  - test/test_helper.rb
41
- - test/rtm_test.rb
42
- - test/rtm_api_test.rb
56
+ - test/timelines_api_test.rb
43
57
  test_files:
58
+ - test/auth_api_test.rb
59
+ - test/error_test.rb
60
+ - test/lists_api_test.rb
61
+ - test/notes_api_test.rb
44
62
  - test/rtm_api_test.rb
45
63
  - test/rtm_test.rb
64
+ - test/tasks_api_test.rb
65
+ - test/timelines_api_test.rb
46
66
  rdoc_options: []
47
67
 
48
68
  extra_rdoc_files: []