twurl 0.9.2 → 0.9.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/.travis.yml +1 -2
- data/Gemfile +2 -3
- data/INSTALL +7 -2
- data/README +2 -2
- data/lib/twurl/cli.rb +14 -6
- data/lib/twurl/oauth_client.rb +5 -3
- data/lib/twurl/version.rb +3 -3
- data/twurl.gemspec +2 -2
- metadata +5 -26
- data/.gemtest +0 -0
- data/test/account_information_controller_test.rb +0 -61
- data/test/alias_controller_test.rb +0 -53
- data/test/authorization_controller_test.rb +0 -30
- data/test/cli_options_test.rb +0 -23
- data/test/cli_test.rb +0 -192
- data/test/configuration_controller_test.rb +0 -44
- data/test/oauth_client_test.rb +0 -165
- data/test/rcfile_test.rb +0 -147
- data/test/request_controller_test.rb +0 -58
- data/test/test_helper.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e7d92fe7658f9a73363898ecd95200cc63a87f8
|
4
|
+
data.tar.gz: 2130791a02fb9f2d44647b545a38d9db69c4e507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c340de22153f5d19dd058644f5e54f9ac5f8a77b6daa7a126d715335c758f5a665bba41a75edbc3864f9a45b929a60d1a8a57afcd96d1b4160207b905df90f7e
|
7
|
+
data.tar.gz: e8f0da68afdb20e93704b826beb3247b1e11c9533b2fd33c4bb375f5d98da3e4916a24b70d9e33906ce1fcda22c8a82aa38b7112f78fea17a4176e1a7595aaae
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -4,11 +4,10 @@ gem 'jruby-openssl', :platforms => :jruby
|
|
4
4
|
gem 'rake'
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem 'coveralls'
|
8
|
-
gem 'mime-types', '~> 1.25', :platforms => :ruby_18
|
7
|
+
gem 'coveralls'
|
9
8
|
gem 'minitest', '>= 5'
|
10
9
|
gem 'rr', '>= 1.1'
|
11
|
-
gem 'simplecov',
|
10
|
+
gem 'simplecov', '>= 0.9'
|
12
11
|
end
|
13
12
|
|
14
13
|
gemspec
|
data/INSTALL
CHANGED
@@ -4,12 +4,17 @@
|
|
4
4
|
|
5
5
|
sudo gem i twurl --source http://rubygems.org
|
6
6
|
|
7
|
+
+---------------------+
|
8
|
+
| Build from source |
|
9
|
+
+---------------------+
|
10
|
+
|
11
|
+
rake build
|
12
|
+
|
7
13
|
+---------------------+
|
8
14
|
| Install from source |
|
9
15
|
+---------------------+
|
10
16
|
|
11
|
-
rake
|
12
|
-
sudo gem i pkg/twurl*gem
|
17
|
+
rake install
|
13
18
|
|
14
19
|
+--------------+
|
15
20
|
| Dependencies |
|
data/README
CHANGED
@@ -18,7 +18,7 @@ applications and Twitter accounts.
|
|
18
18
|
The first thing you have to do is register an OAuth application
|
19
19
|
to get a consumer key and secret.
|
20
20
|
|
21
|
-
|
21
|
+
https://apps.twitter.com/app/new
|
22
22
|
|
23
23
|
When you have your consumer key and its secret you authorize
|
24
24
|
your Twitter account to make API requests with your consumer key
|
@@ -29,7 +29,7 @@ and secret.
|
|
29
29
|
|
30
30
|
This will return an URL that you should open up in your browser.
|
31
31
|
Authenticate to Twitter, and then enter the returned PIN back into
|
32
|
-
the terminal. Assuming all that works well, you will
|
32
|
+
the terminal. Assuming all that works well, you will be authorized
|
33
33
|
to make requests with the API. Twurl will tell you as much.
|
34
34
|
|
35
35
|
If your consumer application has xAuth enabled, then you can use
|
data/lib/twurl/cli.rb
CHANGED
@@ -76,6 +76,7 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
76
76
|
o.section "Common options:" do
|
77
77
|
trace
|
78
78
|
data
|
79
|
+
raw_data
|
79
80
|
headers
|
80
81
|
host
|
81
82
|
quiet
|
@@ -236,6 +237,14 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
236
237
|
end
|
237
238
|
end
|
238
239
|
|
240
|
+
def raw_data
|
241
|
+
on('-r', '--raw-data [data]', 'Sends the specified data as it is in a POST request to the HTTP server.') do |data|
|
242
|
+
CGI::parse(data).each_pair do |key, value|
|
243
|
+
options.data[key] = value.first
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
239
248
|
def headers
|
240
249
|
on('-A', '--header [header]', 'Adds the specified header to the request to the HTTP server.') do |header|
|
241
250
|
key, value = header.split(': ')
|
@@ -296,20 +305,20 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
296
305
|
on('-f', '--file [path_to_file]', 'Specify the path to the file to upload') do |file|
|
297
306
|
if File.file?(file)
|
298
307
|
options.upload['file'] << file
|
299
|
-
else
|
308
|
+
else
|
300
309
|
CLI.puts "ERROR: File not found"
|
301
310
|
exit
|
302
311
|
end
|
303
312
|
end
|
304
313
|
end
|
305
|
-
|
306
|
-
def filefield
|
314
|
+
|
315
|
+
def filefield
|
307
316
|
on('-F', '--file-field [field_name]', 'Specify the POST parameter name for the file upload data (default: media)') do |filefield|
|
308
317
|
options.upload['filefield'] = filefield
|
309
318
|
end
|
310
319
|
end
|
311
|
-
|
312
|
-
def base64
|
320
|
+
|
321
|
+
def base64
|
313
322
|
on('-b', '--base64', 'Encode the uploaded file as base64 (default: false)') do |base64|
|
314
323
|
options.upload['base64'] = base64
|
315
324
|
end
|
@@ -317,7 +326,6 @@ Supported Commands: #{SUPPORTED_COMMANDS.sort.join(', ')}
|
|
317
326
|
end
|
318
327
|
end
|
319
328
|
|
320
|
-
|
321
329
|
class Options < OpenStruct
|
322
330
|
DEFAULT_REQUEST_METHOD = 'get'
|
323
331
|
DEFAULT_HOST = 'api.twitter.com'
|
data/lib/twurl/oauth_client.rb
CHANGED
@@ -99,15 +99,17 @@ module Twurl
|
|
99
99
|
if options.upload['base64']
|
100
100
|
enc = Base64.encode64(File.read(filename))
|
101
101
|
multipart_body << enc
|
102
|
-
else
|
102
|
+
else
|
103
103
|
multipart_body << File.read(filename)
|
104
104
|
end
|
105
105
|
}
|
106
106
|
|
107
107
|
multipart_body << "\r\n--#{boundary}--\r\n"
|
108
|
-
|
108
|
+
|
109
109
|
request.body = multipart_body.join
|
110
|
-
request
|
110
|
+
request.content_type = "multipart/form-data, boundary=\"#{boundary}\""
|
111
|
+
elsif request.content_type && options.data
|
112
|
+
request.body = options.data.keys.first
|
111
113
|
elsif options.data
|
112
114
|
request.set_form_data(options.data)
|
113
115
|
end
|
data/lib/twurl/version.rb
CHANGED
@@ -2,13 +2,13 @@ module Twurl
|
|
2
2
|
class Version
|
3
3
|
MAJOR = 0 unless defined? Twurl::Version::MAJOR
|
4
4
|
MINOR = 9 unless defined? Twurl::Version::MINOR
|
5
|
-
PATCH =
|
6
|
-
|
5
|
+
PATCH = 3 unless defined? Twurl::Version::PATCH
|
6
|
+
PRE = nil unless defined? Twurl::Version::PRE # Time.now.to_i.to_s
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# @return [String]
|
10
10
|
def to_s
|
11
|
-
[MAJOR, MINOR, PATCH,
|
11
|
+
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/twurl.gemspec
CHANGED
@@ -11,15 +11,15 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ['marcel@twitter.com']
|
12
12
|
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
13
|
spec.extra_rdoc_files = %w(COPYING INSTALL README)
|
14
|
-
spec.files = `git ls-files`.split("\
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('test/') }
|
15
15
|
spec.homepage = 'http://github.com/twitter/twurl'
|
16
16
|
spec.licenses = ['MIT']
|
17
17
|
spec.name = 'twurl'
|
18
18
|
spec.rdoc_options = ['--title', 'twurl -- OAuth-enabled curl for the Twitter API', '--main', 'README', '--line-numbers', '--inline-source']
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
spec.required_ruby_version = '>= 1.9.3'
|
20
21
|
spec.required_rubygems_version = '>= 1.3.5'
|
21
22
|
spec.rubyforge_project = 'twurl'
|
22
23
|
spec.summary = spec.description
|
23
|
-
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
24
|
spec.version = Twurl::Version
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Molina
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
@@ -50,7 +50,6 @@ extra_rdoc_files:
|
|
50
50
|
- INSTALL
|
51
51
|
- README
|
52
52
|
files:
|
53
|
-
- ".gemtest"
|
54
53
|
- ".gitignore"
|
55
54
|
- ".travis.yml"
|
56
55
|
- COPYING
|
@@ -70,16 +69,6 @@ files:
|
|
70
69
|
- lib/twurl/rcfile.rb
|
71
70
|
- lib/twurl/request_controller.rb
|
72
71
|
- lib/twurl/version.rb
|
73
|
-
- test/account_information_controller_test.rb
|
74
|
-
- test/alias_controller_test.rb
|
75
|
-
- test/authorization_controller_test.rb
|
76
|
-
- test/cli_options_test.rb
|
77
|
-
- test/cli_test.rb
|
78
|
-
- test/configuration_controller_test.rb
|
79
|
-
- test/oauth_client_test.rb
|
80
|
-
- test/rcfile_test.rb
|
81
|
-
- test/request_controller_test.rb
|
82
|
-
- test/test_helper.rb
|
83
72
|
- twurl.gemspec
|
84
73
|
homepage: http://github.com/twitter/twurl
|
85
74
|
licenses:
|
@@ -99,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
88
|
requirements:
|
100
89
|
- - ">="
|
101
90
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
91
|
+
version: 1.9.3
|
103
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
93
|
requirements:
|
105
94
|
- - ">="
|
@@ -107,18 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
96
|
version: 1.3.5
|
108
97
|
requirements: []
|
109
98
|
rubyforge_project: twurl
|
110
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.8
|
111
100
|
signing_key:
|
112
101
|
specification_version: 4
|
113
102
|
summary: Curl for the Twitter API
|
114
|
-
test_files:
|
115
|
-
- test/account_information_controller_test.rb
|
116
|
-
- test/alias_controller_test.rb
|
117
|
-
- test/authorization_controller_test.rb
|
118
|
-
- test/cli_options_test.rb
|
119
|
-
- test/cli_test.rb
|
120
|
-
- test/configuration_controller_test.rb
|
121
|
-
- test/oauth_client_test.rb
|
122
|
-
- test/rcfile_test.rb
|
123
|
-
- test/request_controller_test.rb
|
124
|
-
- test/test_helper.rb
|
103
|
+
test_files: []
|
data/.gemtest
DELETED
File without changes
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::AccountInformationController::DispatchWithNoAuthorizedAccountsTest < Minitest::Test
|
4
|
-
attr_reader :options, :client, :controller
|
5
|
-
def setup
|
6
|
-
@options = Twurl::Options.new
|
7
|
-
@client = Twurl::OAuthClient.load_new_client_from_options(options)
|
8
|
-
@controller = Twurl::AccountInformationController.new(client, options)
|
9
|
-
mock(Twurl::OAuthClient.rcfile).empty? { true }
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_message_indicates_when_no_accounts_are_authorized
|
13
|
-
mock(Twurl::CLI).puts(Twurl::AccountInformationController::NO_AUTHORIZED_ACCOUNTS_MESSAGE).times(1)
|
14
|
-
|
15
|
-
controller.dispatch
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Twurl::AccountInformationController::DispatchWithOneAuthorizedAccountTest < Minitest::Test
|
20
|
-
attr_reader :options, :client, :controller
|
21
|
-
def setup
|
22
|
-
@options = Twurl::Options.test_exemplar
|
23
|
-
@client = Twurl::OAuthClient.load_new_client_from_options(options)
|
24
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
25
|
-
Twurl::OAuthClient.rcfile << client
|
26
|
-
@controller = Twurl::AccountInformationController.new(client, options)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_authorized_account_is_displayed_and_marked_as_the_default
|
30
|
-
mock(Twurl::CLI).puts(client.username).times(1).ordered
|
31
|
-
mock(Twurl::CLI).puts(" #{client.consumer_key} (default)").times(1).ordered
|
32
|
-
|
33
|
-
controller.dispatch
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Twurl::AccountInformationController::DispatchWithOneUsernameThatHasAuthorizedMultipleAccountsTest < Minitest::Test
|
38
|
-
attr_reader :default_client_options, :default_client, :other_client_options, :other_client, :controller
|
39
|
-
def setup
|
40
|
-
@default_client_options = Twurl::Options.test_exemplar
|
41
|
-
@default_client = Twurl::OAuthClient.load_new_client_from_options(default_client_options)
|
42
|
-
|
43
|
-
@other_client_options = Twurl::Options.test_exemplar
|
44
|
-
other_client_options.consumer_key = default_client_options.consumer_key.reverse
|
45
|
-
@other_client = Twurl::OAuthClient.load_new_client_from_options(other_client_options)
|
46
|
-
mock(Twurl::OAuthClient.rcfile).save.times(2)
|
47
|
-
|
48
|
-
Twurl::OAuthClient.rcfile << default_client
|
49
|
-
Twurl::OAuthClient.rcfile << other_client
|
50
|
-
|
51
|
-
@controller = Twurl::AccountInformationController.new(other_client, other_client_options)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_authorized_account_is_displayed_and_marked_as_the_default
|
55
|
-
mock(Twurl::CLI).puts(default_client.username).times(1)
|
56
|
-
mock(Twurl::CLI).puts(" #{default_client.consumer_key} (default)").times(1)
|
57
|
-
mock(Twurl::CLI).puts(" #{other_client.consumer_key}").times(1)
|
58
|
-
|
59
|
-
controller.dispatch
|
60
|
-
end
|
61
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::AliasesController::DispatchTest < Minitest::Test
|
4
|
-
attr_reader :options, :client
|
5
|
-
def setup
|
6
|
-
@options = Twurl::Options.test_exemplar
|
7
|
-
@client = Twurl::OAuthClient.test_exemplar
|
8
|
-
|
9
|
-
# Clean slate
|
10
|
-
if Twurl::OAuthClient.rcfile.aliases
|
11
|
-
Twurl::OAuthClient.rcfile.aliases.clear
|
12
|
-
end
|
13
|
-
|
14
|
-
stub(Twurl::OAuthClient.rcfile).save
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_when_no_subcommands_are_provided_and_no_aliases_exist_nothing_is_displayed
|
18
|
-
assert options.subcommands.empty?
|
19
|
-
mock(Twurl::CLI).puts(Twurl::AliasesController::NO_ALIASES_MESSAGE).times(1)
|
20
|
-
|
21
|
-
controller = Twurl::AliasesController.new(client, options)
|
22
|
-
controller.dispatch
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_when_no_subcommands_are_provided_and_aliases_exist_they_are_displayed
|
26
|
-
assert options.subcommands.empty?
|
27
|
-
|
28
|
-
Twurl::OAuthClient.rcfile.alias('h', '/1.1/statuses/home_timeline.json')
|
29
|
-
mock(Twurl::CLI).puts("h: /1.1/statuses/home_timeline.json").times(1)
|
30
|
-
|
31
|
-
controller = Twurl::AliasesController.new(client, options)
|
32
|
-
controller.dispatch
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_when_alias_and_value_are_provided_they_are_added
|
36
|
-
options.subcommands = ['h']
|
37
|
-
options.path = '/1.1/statuses/home_timeline.json'
|
38
|
-
mock(Twurl::OAuthClient.rcfile).alias('h', '/1.1/statuses/home_timeline.json').times(1)
|
39
|
-
|
40
|
-
controller = Twurl::AliasesController.new(client, options)
|
41
|
-
controller.dispatch
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_when_no_path_is_provided_nothing_happens
|
45
|
-
options.subcommands = ['a']
|
46
|
-
assert_nil options.path
|
47
|
-
|
48
|
-
mock(Twurl::CLI).puts(Twurl::AliasesController::NO_PATH_PROVIDED_MESSAGE).times(1)
|
49
|
-
|
50
|
-
controller = Twurl::AliasesController.new(client, options)
|
51
|
-
controller.dispatch
|
52
|
-
end
|
53
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::AuthorizationController::DispatchTest < Minitest::Test
|
4
|
-
attr_reader :options, :client, :controller
|
5
|
-
def setup
|
6
|
-
@options = Twurl::Options.new
|
7
|
-
@client = Twurl::OAuthClient.load_new_client_from_options(options)
|
8
|
-
@controller = Twurl::AuthorizationController.new(client, options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_successful_authentication_saves_retrieved_access_token
|
12
|
-
mock(client).exchange_credentials_for_access_token.times(1)
|
13
|
-
mock(client).save.times(1)
|
14
|
-
mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).never
|
15
|
-
mock(Twurl::CLI).puts(Twurl::AuthorizationController::AUTHORIZATION_SUCCEEDED_MESSAGE).times(1)
|
16
|
-
|
17
|
-
controller.dispatch
|
18
|
-
end
|
19
|
-
|
20
|
-
module ErrorCases
|
21
|
-
def test_failed_authorization_does_not_save_client
|
22
|
-
mock(client).exchange_credentials_for_access_token { raise OAuth::Unauthorized }
|
23
|
-
mock(client).save.never
|
24
|
-
mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).times(1)
|
25
|
-
|
26
|
-
controller.dispatch
|
27
|
-
end
|
28
|
-
end
|
29
|
-
include ErrorCases
|
30
|
-
end
|
data/test/cli_options_test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::Options::Test < Minitest::Test
|
4
|
-
attr_reader :options
|
5
|
-
def setup
|
6
|
-
@options = Twurl::Options.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_base_url_is_built_from_protocol_and_host
|
10
|
-
options.protocol = 'http'
|
11
|
-
options.host = 'api.twitter.com'
|
12
|
-
|
13
|
-
assert_equal 'http://api.twitter.com', options.base_url
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_ssl_is_enabled_if_the_protocol_is_https
|
17
|
-
options.protocol = 'http'
|
18
|
-
assert !options.ssl?
|
19
|
-
|
20
|
-
options.protocol = 'https'
|
21
|
-
assert options.ssl?
|
22
|
-
end
|
23
|
-
end
|
data/test/cli_test.rb
DELETED
@@ -1,192 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::CLI::OptionParsingTest < Minitest::Test
|
4
|
-
TEST_PATH = '/1.1/url/does/not/matter.json'
|
5
|
-
|
6
|
-
module CommandParsingTests
|
7
|
-
def test_no_command_specified_falls_to_default_command
|
8
|
-
options = Twurl::CLI.parse_options([TEST_PATH])
|
9
|
-
assert_equal Twurl::CLI::DEFAULT_COMMAND, options.command
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_supported_command_specified_extracts_the_command
|
13
|
-
expected_command = Twurl::CLI::SUPPORTED_COMMANDS.first
|
14
|
-
options = Twurl::CLI.parse_options([expected_command])
|
15
|
-
assert_equal expected_command, options.command
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_unsupported_command_specified_sets_default_command
|
19
|
-
unsupported_command = 'unsupported'
|
20
|
-
options = Twurl::CLI.parse_options([TEST_PATH, unsupported_command])
|
21
|
-
assert_equal Twurl::CLI::DEFAULT_COMMAND, options.command
|
22
|
-
end
|
23
|
-
end
|
24
|
-
include CommandParsingTests
|
25
|
-
|
26
|
-
module PathParsingTests
|
27
|
-
def test_missing_path_throws_no_path_found
|
28
|
-
stub(Twurl::CLI).puts
|
29
|
-
assert_raises Twurl::CLI::NoPathFound do
|
30
|
-
Twurl::CLI.parse_options([])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_uri_params_are_encoded
|
35
|
-
options = Twurl::CLI.parse_options(["/1.1/url?baz=bamf:rofl"])
|
36
|
-
assert_equal options.path, "/1.1/url?baz=bamf%3Arofl"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
include PathParsingTests
|
40
|
-
|
41
|
-
module RequestMethodParsingTests
|
42
|
-
def test_request_method_is_default_if_unspecified
|
43
|
-
options = Twurl::CLI.parse_options([TEST_PATH])
|
44
|
-
assert_equal Twurl::Options::DEFAULT_REQUEST_METHOD, options.request_method
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_specifying_a_request_method_extracts_and_normalizes_request_method
|
48
|
-
variations = [%w[-X put], %w[-X PUT], %w[--request-method PUT], %w[--request-method put]]
|
49
|
-
variations.each do |option_variation|
|
50
|
-
order_variant_1 = [option_variation, TEST_PATH].flatten
|
51
|
-
order_variant_2 = [TEST_PATH, option_variation].flatten
|
52
|
-
[order_variant_1, order_variant_2].each do |args|
|
53
|
-
options = Twurl::CLI.parse_options(args)
|
54
|
-
assert_equal 'put', options.request_method
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_specifying_unsupported_request_method_returns_an_error
|
60
|
-
Twurl::CLI.parse_options([TEST_PATH, '-X', 'UNSUPPORTED'])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
include RequestMethodParsingTests
|
64
|
-
|
65
|
-
module OAuthClientOptionParsingTests
|
66
|
-
def test_extracting_the_consumer_key
|
67
|
-
mock(Twurl::CLI).prompt_for('Consumer key').never
|
68
|
-
|
69
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-c', 'the-key'])
|
70
|
-
assert_equal 'the-key', options.consumer_key
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_consumer_key_option_with_no_value_prompts_user_for_value
|
74
|
-
mock(Twurl::CLI).prompt_for('Consumer key').times(1) { 'inputted-key'}
|
75
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-c'])
|
76
|
-
assert_equal 'inputted-key', options.consumer_key
|
77
|
-
end
|
78
|
-
end
|
79
|
-
include OAuthClientOptionParsingTests
|
80
|
-
|
81
|
-
module DataParsingTests
|
82
|
-
def test_extracting_a_single_key_value_pair
|
83
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value'])
|
84
|
-
assert_equal({'key' => 'value'}, options.data)
|
85
|
-
|
86
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '--data', 'key=value'])
|
87
|
-
assert_equal({'key' => 'value'}, options.data)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_passing_data_and_no_explicit_request_method_defaults_request_method_to_post
|
91
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value'])
|
92
|
-
assert_equal 'post', options.request_method
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_passing_data_and_an_explicit_request_method_uses_the_specified_method
|
96
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value', '-X', 'DELETE'])
|
97
|
-
assert_equal({'key' => 'value'}, options.data)
|
98
|
-
assert_equal 'delete', options.request_method
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_multiple_pairs_when_option_is_specified_multiple_times_on_command_line_collects_all
|
102
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value', '-d', 'another=pair'])
|
103
|
-
assert_equal({'key' => 'value', 'another' => 'pair'}, options.data)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_multiple_pairs_separated_by_ampersand_are_all_captured
|
107
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value&another=pair'])
|
108
|
-
assert_equal({'key' => 'value', 'another' => 'pair'}, options.data)
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_extracting_an_empty_key_value_pair
|
112
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key='])
|
113
|
-
assert_equal({'key' => ''}, options.data)
|
114
|
-
|
115
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '--data', 'key='])
|
116
|
-
assert_equal({'key' => ''}, options.data)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
include DataParsingTests
|
120
|
-
|
121
|
-
module HeaderParsingTests
|
122
|
-
def test_extracting_a_single_header
|
123
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-A', 'Key: Value'])
|
124
|
-
assert_equal({'Key' => 'Value'}, options.headers)
|
125
|
-
|
126
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '--header', 'Key: Value'])
|
127
|
-
assert_equal({'Key' => 'Value'}, options.headers)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_multiple_headers_when_option_is_specified_multiple_times_on_command_line_collects_all
|
131
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-A', 'Key: Value', '-A', 'Another: Pair'])
|
132
|
-
assert_equal({'Key' => 'Value', 'Another' => 'Pair'}, options.headers)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
include HeaderParsingTests
|
136
|
-
|
137
|
-
module SSLDisablingTests
|
138
|
-
def test_ssl_is_on_by_default
|
139
|
-
options = Twurl::CLI.parse_options([TEST_PATH])
|
140
|
-
assert options.ssl?
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_passing_no_ssl_option_disables_ssl
|
144
|
-
['-U', '--no-ssl'].each do |switch|
|
145
|
-
options = Twurl::CLI.parse_options([TEST_PATH, switch])
|
146
|
-
assert !options.ssl?
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
include SSLDisablingTests
|
151
|
-
|
152
|
-
module HostOptionTests
|
153
|
-
def test_not_specifying_host_sets_it_to_the_default
|
154
|
-
options = Twurl::CLI.parse_options([TEST_PATH])
|
155
|
-
assert_equal Twurl::Options::DEFAULT_HOST, options.host
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_setting_host_updates_to_requested_value
|
159
|
-
custom_host = 'localhost:3000'
|
160
|
-
assert Twurl::Options::DEFAULT_HOST != custom_host
|
161
|
-
|
162
|
-
[[TEST_PATH, '-H', custom_host], [TEST_PATH, '--host', custom_host]].each do |option_combination|
|
163
|
-
options = Twurl::CLI.parse_options(option_combination)
|
164
|
-
assert_equal custom_host, options.host
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_protocol_is_stripped_from_host
|
169
|
-
custom_host = 'localhost:3000'
|
170
|
-
options = Twurl::CLI.parse_options([TEST_PATH, '-H', "https://"+custom_host])
|
171
|
-
assert_equal custom_host, options.host
|
172
|
-
end
|
173
|
-
end
|
174
|
-
include HostOptionTests
|
175
|
-
|
176
|
-
module ProxyOptionTests
|
177
|
-
def test_not_specifying_proxy_sets_it_to_nil
|
178
|
-
options = Twurl::CLI.parse_options([TEST_PATH])
|
179
|
-
assert_equal nil, options.proxy
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_setting_proxy_updates_to_requested_value
|
183
|
-
custom_proxy = 'localhost:80'
|
184
|
-
|
185
|
-
[[TEST_PATH, '-P', custom_proxy], [TEST_PATH, '--proxy', custom_proxy]].each do |option_combination|
|
186
|
-
options = Twurl::CLI.parse_options(option_combination)
|
187
|
-
assert_equal custom_proxy, options.proxy
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
include ProxyOptionTests
|
192
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::ConfigurationController::DispatchTest < Minitest::Test
|
4
|
-
def test_error_message_is_displayed_if_setting_is_unrecognized
|
5
|
-
options = Twurl::Options.test_exemplar
|
6
|
-
client = Twurl::OAuthClient.test_exemplar
|
7
|
-
|
8
|
-
options.subcommands = ['unrecognized', 'value']
|
9
|
-
|
10
|
-
mock(Twurl::CLI).puts(Twurl::ConfigurationController::UNRECOGNIZED_SETTING_MESSAGE % 'unrecognized').times(1)
|
11
|
-
mock(Twurl::OAuthClient.rcfile).save.times(0)
|
12
|
-
|
13
|
-
controller = Twurl::ConfigurationController.new(client, options)
|
14
|
-
controller.dispatch
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Twurl::ConfigurationController::DispatchDefaultSettingTest < Minitest::Test
|
19
|
-
def test_setting_default_profile_just_by_username
|
20
|
-
options = Twurl::Options.test_exemplar
|
21
|
-
client = Twurl::OAuthClient.test_exemplar
|
22
|
-
|
23
|
-
options.subcommands = ['default', client.username]
|
24
|
-
mock(Twurl::OAuthClient).load_client_for_username(client.username).times(1) { client }
|
25
|
-
mock(Twurl::OAuthClient.rcfile).default_profile = client
|
26
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
27
|
-
|
28
|
-
controller = Twurl::ConfigurationController.new(client, options)
|
29
|
-
controller.dispatch
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_setting_default_profile_by_username_and_consumer_key
|
33
|
-
options = Twurl::Options.test_exemplar
|
34
|
-
client = Twurl::OAuthClient.test_exemplar
|
35
|
-
|
36
|
-
options.subcommands = ['default', client.username, client.consumer_key]
|
37
|
-
mock(Twurl::OAuthClient).load_client_for_username_and_consumer_key(client.username, client.consumer_key).times(1) { client }
|
38
|
-
mock(Twurl::OAuthClient.rcfile).default_profile = client
|
39
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
40
|
-
|
41
|
-
controller = Twurl::ConfigurationController.new(client, options)
|
42
|
-
controller.dispatch
|
43
|
-
end
|
44
|
-
end
|
data/test/oauth_client_test.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::OAuthClient::AbstractOAuthClientTest < Minitest::Test
|
4
|
-
attr_reader :client, :options
|
5
|
-
def setup
|
6
|
-
Twurl::OAuthClient.instance_variable_set(:@rcfile, nil)
|
7
|
-
|
8
|
-
@options = Twurl::Options.test_exemplar
|
9
|
-
@client = Twurl::OAuthClient.test_exemplar
|
10
|
-
options.base_url = 'api.twitter.com'
|
11
|
-
options.request_method = 'get'
|
12
|
-
options.path = '/path/does/not/matter.json'
|
13
|
-
options.data = {}
|
14
|
-
options.headers = {}
|
15
|
-
|
16
|
-
Twurl.options = options
|
17
|
-
end
|
18
|
-
|
19
|
-
def teardown
|
20
|
-
super
|
21
|
-
Twurl.options = Twurl::Options.new
|
22
|
-
# Make sure we don't do any disk IO in these tests
|
23
|
-
assert !File.exists?(Twurl::RCFile.file_path)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_nothing
|
27
|
-
# Appeasing test/unit
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Twurl::OAuthClient::BasicRCFileLoadingTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
32
|
-
def test_rcfile_is_memoized
|
33
|
-
mock.proxy(Twurl::RCFile).new.times(1)
|
34
|
-
|
35
|
-
Twurl::OAuthClient.rcfile
|
36
|
-
Twurl::OAuthClient.rcfile
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_forced_reloading
|
40
|
-
mock.proxy(Twurl::RCFile).new.times(2)
|
41
|
-
|
42
|
-
Twurl::OAuthClient.rcfile
|
43
|
-
Twurl::OAuthClient.rcfile(:reload)
|
44
|
-
Twurl::OAuthClient.rcfile
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Twurl::OAuthClient::ClientLoadingFromOptionsTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
49
|
-
def test_if_username_is_supplied_and_no_profile_exists_for_username_then_new_client_is_created
|
50
|
-
mock(Twurl::OAuthClient).load_client_for_username(options.username).never
|
51
|
-
mock(Twurl::OAuthClient).load_new_client_from_options(options).times(1)
|
52
|
-
mock(Twurl::OAuthClient).load_default_client.never
|
53
|
-
|
54
|
-
Twurl::OAuthClient.load_from_options(options)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_if_username_is_supplied_and_profile_exists_for_username_then_client_is_loaded
|
58
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
59
|
-
Twurl::OAuthClient.rcfile << client
|
60
|
-
|
61
|
-
mock(Twurl::OAuthClient).load_client_for_username_and_consumer_key(options.username, options.consumer_key).times(1)
|
62
|
-
mock(Twurl::OAuthClient).load_new_client_from_options(options).never
|
63
|
-
mock(Twurl::OAuthClient).load_default_client.never
|
64
|
-
|
65
|
-
Twurl::OAuthClient.load_from_options(options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_if_username_is_not_provided_then_the_default_client_is_loaded
|
69
|
-
options.username = nil
|
70
|
-
|
71
|
-
mock(Twurl::OAuthClient).load_client_for_username(options.username).never
|
72
|
-
mock(Twurl::OAuthClient).load_new_client_from_options(options).never
|
73
|
-
mock(Twurl::OAuthClient).load_default_client.times(1)
|
74
|
-
|
75
|
-
Twurl::OAuthClient.load_from_options(options)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class Twurl::OAuthClient::ClientLoadingForUsernameTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
80
|
-
def test_attempting_to_load_a_username_that_is_not_in_the_file_fails
|
81
|
-
assert_nil Twurl::OAuthClient.rcfile[client.username]
|
82
|
-
|
83
|
-
assert_raises Twurl::Exception do
|
84
|
-
Twurl::OAuthClient.load_client_for_username_and_consumer_key(client.username, client.consumer_key)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_loading_a_username_that_exists
|
89
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
90
|
-
|
91
|
-
Twurl::OAuthClient.rcfile << client
|
92
|
-
|
93
|
-
client_from_file = Twurl::OAuthClient.load_client_for_username_and_consumer_key(client.username, client.consumer_key)
|
94
|
-
assert_equal client.to_hash, client_from_file.to_hash
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class Twurl::OAuthClient::DefaultClientLoadingTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
99
|
-
def test_loading_default_client_when_there_is_none_fails
|
100
|
-
assert_nil Twurl::OAuthClient.rcfile.default_profile
|
101
|
-
|
102
|
-
assert_raises Twurl::Exception do
|
103
|
-
Twurl::OAuthClient.load_default_client
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_loading_default_client_from_file
|
108
|
-
mock(Twurl::OAuthClient.rcfile).save.times(1)
|
109
|
-
|
110
|
-
Twurl::OAuthClient.rcfile << client
|
111
|
-
assert_equal [client.username, client.consumer_key], Twurl::OAuthClient.rcfile.default_profile
|
112
|
-
|
113
|
-
client_from_file = Twurl::OAuthClient.load_default_client
|
114
|
-
|
115
|
-
assert_equal client.to_hash, client_from_file.to_hash
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class Twurl::OAuthClient::NewClientLoadingFromOptionsTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
120
|
-
attr_reader :new_client
|
121
|
-
def setup
|
122
|
-
super
|
123
|
-
@new_client = Twurl::OAuthClient.load_new_client_from_options(options)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_password_is_included
|
127
|
-
assert_equal options.password, new_client.password
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_oauth_options_are_passed_through
|
131
|
-
assert_equal client.to_hash, new_client.to_hash
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
class Twurl::OAuthClient::PerformingRequestsFromOptionsTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
136
|
-
def test_request_is_made_using_request_method_and_path_and_data_in_options
|
137
|
-
client = Twurl::OAuthClient.test_exemplar
|
138
|
-
mock(client.consumer.http).request(satisfy { |req|
|
139
|
-
req.is_a?(Net::HTTP::Get) && (req.path == options.path)
|
140
|
-
})
|
141
|
-
|
142
|
-
client.perform_request_from_options(options)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
class Twurl::OAuthClient::CredentialsForAccessTokenExchangeTest < Twurl::OAuthClient::AbstractOAuthClientTest
|
147
|
-
def test_successful_exchange_parses_token_and_secret_from_response_body
|
148
|
-
parsed_response = {:oauth_token => "123456789",
|
149
|
-
:oauth_token_secret => "abcdefghi",
|
150
|
-
:user_id => "3191321",
|
151
|
-
:screen_name => "noradio",
|
152
|
-
:x_auth_expires => "0"}
|
153
|
-
|
154
|
-
mock(client.consumer).
|
155
|
-
token_request(:post,
|
156
|
-
client.consumer.access_token_path,
|
157
|
-
nil,
|
158
|
-
{},
|
159
|
-
client.client_auth_parameters) { parsed_response }
|
160
|
-
|
161
|
-
assert client.needs_to_authorize?
|
162
|
-
client.exchange_credentials_for_access_token
|
163
|
-
assert !client.needs_to_authorize?
|
164
|
-
end
|
165
|
-
end
|
data/test/rcfile_test.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::RCFile::PathConstructionTest < Minitest::Test
|
4
|
-
def test_file_path_appends_file_to_directory
|
5
|
-
assert_equal File.join(Twurl::RCFile.directory, Twurl::RCFile::FILE), Twurl::RCFile.file_path
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Twurl::RCFile::LoadingTest < Minitest::Test
|
10
|
-
def test_load_parses_and_loads_file_if_it_exists
|
11
|
-
mock(YAML).load_file(Twurl::RCFile.file_path).times(1)
|
12
|
-
mock(Twurl::RCFile).default_rcfile_structure.never
|
13
|
-
|
14
|
-
Twurl::RCFile.load
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_load_returns_default_file_structure_if_file_does_not_exist
|
18
|
-
mock(YAML).load_file(Twurl::RCFile.file_path) { raise Errno::ENOENT }.times(1)
|
19
|
-
mock(Twurl::RCFile).default_rcfile_structure.times(1)
|
20
|
-
|
21
|
-
Twurl::RCFile.load
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Twurl::RCFile::InitializationTest < Minitest::Test
|
26
|
-
def test_initializing_when_the_file_does_not_exist_loads_default_rcfile_structure
|
27
|
-
mock(YAML).load_file(Twurl::RCFile.file_path) { raise Errno::ENOENT }.times(1)
|
28
|
-
|
29
|
-
rcfile = Twurl::RCFile.new
|
30
|
-
assert_equal Twurl::RCFile.default_rcfile_structure, rcfile.data
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_initializing_when_the_file_does_exists_loads_content_of_file
|
34
|
-
mock_content_of_rcfile = {'this data' => 'does not matter'}
|
35
|
-
mock(YAML).load_file(Twurl::RCFile.file_path) { mock_content_of_rcfile }.times(1)
|
36
|
-
mock(Twurl::RCFile).default_rcfile_structure.never
|
37
|
-
|
38
|
-
rcfile = Twurl::RCFile.new
|
39
|
-
assert_equal mock_content_of_rcfile, rcfile.data
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Twurl::RCFile::DefaultProfileFromDefaultRCFileTest < Minitest::Test
|
44
|
-
attr_reader :rcfile
|
45
|
-
def setup
|
46
|
-
mock(YAML).load_file(Twurl::RCFile.file_path) { raise Errno::ENOENT }.times(1)
|
47
|
-
mock.proxy(Twurl::RCFile).default_rcfile_structure.times(any_times)
|
48
|
-
|
49
|
-
@rcfile = Twurl::RCFile.new
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_default_rcfile_structure_has_no_default_profile
|
53
|
-
assert_nil rcfile.default_profile
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_rcfile_is_considered_empty_at_first
|
57
|
-
assert rcfile.empty?
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_setting_default_profile
|
61
|
-
options = Twurl::Options.test_exemplar
|
62
|
-
|
63
|
-
client = Twurl::OAuthClient.load_new_client_from_options(options)
|
64
|
-
rcfile.default_profile = client
|
65
|
-
assert_equal [options.username, options.consumer_key], rcfile.default_profile
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class Twurl::RCFile::UpdatingTest < Minitest::Test
|
70
|
-
attr_reader :rcfile
|
71
|
-
def setup
|
72
|
-
mock(YAML).load_file(Twurl::RCFile.file_path) { raise Errno::ENOENT }.times(1)
|
73
|
-
|
74
|
-
@rcfile = Twurl::RCFile.new
|
75
|
-
assert rcfile.profiles.empty?
|
76
|
-
assert_nil rcfile.default_profile
|
77
|
-
mock(rcfile).save.times(any_times)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_adding_the_first_client_sets_it_as_default_profile
|
81
|
-
client = Twurl::OAuthClient.test_exemplar
|
82
|
-
|
83
|
-
rcfile << client
|
84
|
-
assert_equal [client.username, client.consumer_key], rcfile.default_profile
|
85
|
-
assert rcfile.has_oauth_profile_for_username_with_consumer_key?(client.username, client.consumer_key)
|
86
|
-
assert_equal({client.username => {client.consumer_key => client.to_hash}}, rcfile.profiles)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_adding_additional_clients_does_not_change_default_profile
|
90
|
-
first_client = Twurl::OAuthClient.test_exemplar
|
91
|
-
|
92
|
-
rcfile << first_client
|
93
|
-
assert_equal [first_client.username, first_client.consumer_key], rcfile.default_profile
|
94
|
-
assert rcfile.has_oauth_profile_for_username_with_consumer_key?(first_client.username, first_client.consumer_key)
|
95
|
-
|
96
|
-
additional_client = Twurl::OAuthClient.test_exemplar(:username => 'additional_exemplar_username')
|
97
|
-
|
98
|
-
rcfile << additional_client
|
99
|
-
assert_equal [first_client.username, first_client.consumer_key], rcfile.default_profile
|
100
|
-
assert rcfile.has_oauth_profile_for_username_with_consumer_key?(additional_client.username, additional_client.consumer_key)
|
101
|
-
|
102
|
-
expected_profiles = {
|
103
|
-
first_client.username => {first_client.consumer_key => first_client.to_hash},
|
104
|
-
additional_client.username => {additional_client.consumer_key => additional_client.to_hash}
|
105
|
-
}
|
106
|
-
|
107
|
-
assert_equal expected_profiles, rcfile.profiles
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class Twurl::RCFile::SavingTest < Minitest::Test
|
112
|
-
attr_reader :rcfile
|
113
|
-
def setup
|
114
|
-
delete_rcfile
|
115
|
-
assert !rcfile_exists?
|
116
|
-
@rcfile = Twurl::RCFile.new
|
117
|
-
assert !rcfile_exists?
|
118
|
-
end
|
119
|
-
|
120
|
-
def teardown
|
121
|
-
super
|
122
|
-
delete_rcfile
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_save_writes_profiles_to_disk
|
126
|
-
client = Twurl::OAuthClient.test_exemplar
|
127
|
-
rcfile << client
|
128
|
-
assert rcfile_exists?
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_file_is_not_world_readable
|
132
|
-
client = Twurl::OAuthClient.test_exemplar
|
133
|
-
rcfile << client
|
134
|
-
assert_equal 33152, File.stat(Twurl::RCFile.file_path).mode
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
def rcfile_exists?
|
139
|
-
File.exists?(Twurl::RCFile.file_path)
|
140
|
-
end
|
141
|
-
|
142
|
-
def delete_rcfile
|
143
|
-
File.unlink(Twurl::RCFile.file_path)
|
144
|
-
rescue Errno::ENOENT
|
145
|
-
# Do nothing
|
146
|
-
end
|
147
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class Twurl::RequestController::AbstractTestCase < Minitest::Test
|
4
|
-
attr_reader :options, :client, :controller
|
5
|
-
def setup
|
6
|
-
Twurl::CLI.output = StringIO.new
|
7
|
-
@options = Twurl::Options.test_exemplar
|
8
|
-
@client = Twurl::OAuthClient.test_exemplar
|
9
|
-
@controller = Twurl::RequestController.new(client, options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
super
|
14
|
-
Twurl::CLI.output = STDOUT
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_nothing
|
18
|
-
# Appeasing test/unit
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Twurl::RequestController::DispatchTest < Twurl::RequestController::AbstractTestCase
|
23
|
-
def test_request_will_be_made_if_client_is_authorized
|
24
|
-
mock(client).needs_to_authorize? { false }.times(1)
|
25
|
-
mock(controller).perform_request.times(1)
|
26
|
-
|
27
|
-
controller.dispatch
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_request_will_not_be_made_if_client_is_not_authorized
|
31
|
-
mock(client).needs_to_authorize? { true }.times(1)
|
32
|
-
mock(controller).perform_request.never
|
33
|
-
|
34
|
-
assert_raises Twurl::Exception do
|
35
|
-
controller.dispatch
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Twurl::RequestController::RequestTest < Twurl::RequestController::AbstractTestCase
|
41
|
-
def test_request_response_is_written_to_output
|
42
|
-
expected_body = 'this is a fake response body'
|
43
|
-
response = Object.new
|
44
|
-
mock(response).read_body { |block| block.call expected_body }
|
45
|
-
mock(client).perform_request_from_options(options).times(1) { |options, block| block.call(response) }
|
46
|
-
|
47
|
-
controller.perform_request
|
48
|
-
|
49
|
-
assert_equal expected_body, Twurl::CLI.output.string
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_invalid_or_unspecified_urls_report_error
|
53
|
-
mock(Twurl::CLI).puts(Twurl::RequestController::NO_URI_MESSAGE).times(1)
|
54
|
-
mock(client).perform_request_from_options(options).times(1) { raise URI::InvalidURIError }
|
55
|
-
|
56
|
-
controller.perform_request
|
57
|
-
end
|
58
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
require 'coveralls'
|
3
|
-
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
-
SimpleCov::Formatter::HTMLFormatter,
|
6
|
-
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
8
|
-
SimpleCov.start
|
9
|
-
|
10
|
-
require 'twurl'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'rr'
|
13
|
-
|
14
|
-
Twurl::RCFile.directory = ENV['TMPDIR']
|
15
|
-
|
16
|
-
module Twurl
|
17
|
-
class Options
|
18
|
-
class << self
|
19
|
-
def test_exemplar
|
20
|
-
options = new
|
21
|
-
options.username = 'exemplar_user_name'
|
22
|
-
options.password = 'secret'
|
23
|
-
options.consumer_key = '123456789'
|
24
|
-
options.consumer_secret = '987654321'
|
25
|
-
options.subcommands = []
|
26
|
-
options
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class OAuthClient
|
32
|
-
class << self
|
33
|
-
def test_exemplar(overrides = {})
|
34
|
-
options = Twurl::Options.test_exemplar
|
35
|
-
|
36
|
-
overrides.each do |attribute, value|
|
37
|
-
options.send("#{attribute}=", value)
|
38
|
-
end
|
39
|
-
|
40
|
-
load_new_client_from_options(options)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|