komoju 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +0,0 @@
1
- require 'helper'
2
-
3
- class RubyNameTest < MiniTest::Unit::TestCase
4
- # ruby_name is a no-op when an empty string is provided.
5
- def test_ruby_name_with_empty_name
6
- assert_equal('', Heroics.ruby_name(''))
7
- end
8
-
9
- # ruby_name converts capitals in a name to lowercase.
10
- def test_ruby_name_with_capitals
11
- assert_equal('capitalizedname', Heroics.ruby_name('CapitalizedName'))
12
- end
13
-
14
- # ruby_name converts dashes in a name to underscores.
15
- def test_ruby_name_with_dashes
16
- assert_equal('dashed_name', Heroics.ruby_name('dashed-name'))
17
- end
18
-
19
- # ruby_name converts spaces in a name to underscores.
20
- def test_ruby_name_with_spaces
21
- assert_equal('spaced_name', Heroics.ruby_name('spaced name'))
22
- end
23
- end
24
-
25
- class PrettyNameTest < MiniTest::Unit::TestCase
26
- # pretty_name is a no-op when an empty string is provided.
27
- def test_pretty_name_with_empty_name
28
- assert_equal('', Heroics.pretty_name(''))
29
- end
30
-
31
- # pretty_name converts capitals in a name to lowercase.
32
- def test_pretty_name_with_capitals
33
- assert_equal('capitalizedname', Heroics.pretty_name('CapitalizedName'))
34
- end
35
-
36
- # pretty_name converts underscores in a name to dashes.
37
- def test_pretty_name_with_underscores
38
- assert_equal('dashed-name', Heroics.pretty_name('dashed_name'))
39
- end
40
-
41
- # pretty_name converts spaces in a name to underscores.
42
- def test_pretty_name_with_spaces
43
- assert_equal('spaced-name', Heroics.pretty_name('spaced name'))
44
- end
45
- end
@@ -1,35 +0,0 @@
1
- require 'helper'
2
-
3
- class ResourceTest < MiniTest::Unit::TestCase
4
- include ExconHelper
5
-
6
- # Resource.<link> raises a NoMethodError when a method is invoked without a
7
- # matching link.
8
- def test_invalid_link
9
- resource = Heroics::Resource.new({})
10
- error = assert_raises NoMethodError do
11
- resource.unknown
12
- end
13
- assert_match(
14
- /undefined method `unknown' for #<Heroics::Resource:0x.*>/,
15
- error.message)
16
- end
17
-
18
- # Resource.<link> finds the appropriate link and invokes it.
19
- def test_link
20
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
21
- link = Heroics::Link.new('https://username:secret@example.com',
22
- schema.resource('resource').link('list'))
23
- resource = Heroics::Resource.new({'link' => link})
24
- Excon.stub(method: :get) do |request|
25
- assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
26
- request[:headers]['Authorization'])
27
- assert_equal('example.com', request[:host])
28
- assert_equal(443, request[:port])
29
- assert_equal('/resource', request[:path])
30
- Excon.stubs.pop
31
- {status: 200, body: 'Hello, world!'}
32
- end
33
- assert_equal('Hello, world!', resource.link)
34
- end
35
- end
@@ -1,287 +0,0 @@
1
- require 'helper'
2
-
3
- class SchemaTest < MiniTest::Unit::TestCase
4
- # Schema.to_s returns a simple human-readable description of the schema
5
- # instance with the description embedded in it.
6
- def test_to_s
7
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
8
- assert_equal(
9
- '#<Heroics::Schema description="Sample schema for use in tests.">',
10
- schema.to_s)
11
- end
12
-
13
- # Schema.resource returns a ResourceSchema for the named resource.
14
- def test_resource
15
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
16
- assert_equal('resource', schema.resource('resource').name)
17
- end
18
-
19
- # Schema.resource raises a SchemaError is an unknown resource is requested.
20
- def test_resource_with_unknown_name
21
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
22
- error = assert_raises Heroics::SchemaError do
23
- schema.resource('unknown-resource')
24
- end
25
- assert_equal("Unknown resource 'unknown-resource'.", error.message)
26
- end
27
-
28
- # Schema.resources returns a sequence of ResourceSchema children.
29
- def test_resources
30
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
31
- assert_equal(['resource', 'another-resource'],
32
- schema.resources.map(&:name))
33
- end
34
- end
35
-
36
- class ResourceSchemaTest < MiniTest::Unit::TestCase
37
- # ResourceSchema.link returns a LinkSchema for the named link.
38
- def test_link
39
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
40
- link = schema.resource('resource').link('list')
41
- assert_equal('list', link.name)
42
- end
43
-
44
- # ResourceSchema.link raises a SchemaError is an unknown link is requested.
45
- def test_link_with_unknown_name
46
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
47
- error = assert_raises Heroics::SchemaError do
48
- schema.resource('resource').link('unknown-link')
49
- end
50
- assert_equal("Unknown link 'unknown-link'.", error.message)
51
- end
52
-
53
- # ResourceSchema.links returns an array of LinkSchema children.
54
- def test_links
55
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
56
- assert_equal(
57
- ['list', 'info', 'identify_resource', 'create', 'submit', 'update', 'delete'],
58
- schema.resource('resource').links.map { |link| link.name })
59
- end
60
- end
61
-
62
- class LinkSchemaTest < MiniTest::Unit::TestCase
63
- # LinkSchema.name returns the sanitized link name.
64
- def test_name
65
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
66
- assert_equal('list', schema.resource('resource').link('list').name)
67
- end
68
-
69
- # LinkSchema.resource_name returns the parent resource name.
70
- def test_resource_name
71
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
72
- assert_equal('resource',
73
- schema.resource('resource').link('list').resource_name)
74
- end
75
-
76
- # LinkSchema.description returns the link description.
77
- def test_description
78
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
79
- assert_equal('Show all sample resources',
80
- schema.resource('resource').link('list').description)
81
- end
82
-
83
- # LinkSchema.parameters returns an empty array if the link doesn't require
84
- # parameters.
85
- def test_parameters_without_parameters
86
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
87
- link = schema.resource('resource').link('list')
88
- assert_equal([], link.parameters)
89
- end
90
-
91
- # LinkSchema.parameters returns an array of named parameter required to
92
- # invoke the link correctly.
93
- def test_parameters
94
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
95
- link = schema.resource('resource').link('info')
96
- assert_equal(['uuid_field'], link.parameters)
97
- end
98
-
99
- # LinkSchema.parameters returns a parameter name for multiple parameters
100
- # when the parameter contains a 'oneOf' element that references more than
101
- # one parameter.
102
- def test_parameters_with_one_of_field
103
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
104
- link = schema.resource('resource').link('identify_resource')
105
- assert_equal(['uuid_field|email_field'], link.parameters)
106
- end
107
-
108
- # LinkSchema.parameter_details returns an empty array if the link doesn't
109
- # require parameters.
110
- def test_parameter_details_without_parameters
111
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
112
- link = schema.resource('another-resource').link('create')
113
- assert_equal([], link.parameter_details)
114
- end
115
-
116
- # LinkSchema.parameter_details returns an options parameter if the
117
- # link is for a collection of instances.
118
- def test_parameter_details_with_collection_options_parameter
119
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
120
- link = schema.resource('resource').link('list')
121
- parameters = link.parameter_details
122
- parameter = parameters[0]
123
- assert_equal('collection_options', parameter.name)
124
- assert_equal('collection_options = {}', parameter.signature)
125
- assert_equal('additional collection options to pass with the request', parameter.description)
126
- end
127
-
128
- # LinkSchema.parameter_details returns an array of Parameter with information
129
- # about the parameters accepted by the link.
130
- def test_parameter_details
131
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
132
- link = schema.resource('resource').link('info')
133
- parameters = link.parameter_details
134
- assert_equal(1, parameters.length)
135
- parameter = parameters[0]
136
- assert_equal('resource_uuid_field', parameter.name)
137
- assert_equal('resource_uuid_field', parameter.signature)
138
- assert_equal('A sample UUID field', parameter.description)
139
- end
140
-
141
- # LinkSchema.parameter_details returns an array of ParameterChoices, when
142
- # more than one value may be used with a property, with information about
143
- # the parameters accepted by the link.
144
- def test_parameter_details_with_one_of_field
145
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
146
- link = schema.resource('resource').link('identify_resource')
147
- parameters = link.parameter_details
148
- assert_equal(1, parameters.length)
149
- parameter = parameters[0]
150
- assert_equal('resource_uuid_field_or_resource_email_field', parameter.name)
151
- assert_equal('resource_uuid_field_or_resource_email_field', parameter.signature)
152
- assert_equal('A sample UUID field or A sample email address field',
153
- parameter.description)
154
- end
155
-
156
- # LinkSchema.body returns nil if the link doesn't accept a request body.
157
- def test_example_body_without_body
158
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
159
- link = schema.resource('resource').link('info')
160
- assert_equal(nil, link.example_body)
161
- end
162
-
163
- # LinkSchema.body returns a sample body generated from the properties and
164
- # embedded examples.
165
- def test_example_body
166
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
167
- link = schema.resource('resource').link('create')
168
- assert_equal({'date_field' => '2013-10-19 22:10:29Z',
169
- 'string_field' => 'Sample text.',
170
- 'boolean_field' => true,
171
- 'uuid_field' => '44724831-bf66-4bc2-865f-e2c4c2b14c78',
172
- 'email_field' => 'username@example.com'},
173
- link.example_body)
174
- end
175
-
176
- # LinkSchema.format_path converts an array of parameters into a path.
177
- def test_format_path
178
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
179
- link = schema.resource('resource').link('info')
180
- assert_equal(['/resource/44724831-bf66-4bc2-865f-e2c4c2b14c78', nil],
181
- link.format_path(['44724831-bf66-4bc2-865f-e2c4c2b14c78']))
182
- end
183
-
184
- # LinkSchema.format_path escapes special URL characters in parameters.
185
- def test_format_path_with_illegal_literals
186
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
187
- link = schema.resource('resource').link('info')
188
- assert_equal(['/resource/foobar%25', nil],
189
- link.format_path(['foobar%']))
190
- end
191
-
192
- # LinkSchema.format_path correctly returns a parameter as a body if a path
193
- # doesn't have any parameters.
194
- def test_format_path_with_body
195
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
196
- link = schema.resource('resource').link('create')
197
- assert_equal(['/resource', {'new' => 'resource'}],
198
- link.format_path([{'new' => 'resource'}]))
199
- end
200
-
201
- # LinkSchema.format_path correctly returns a parameter as a body if a path
202
- # doesn't have any parameters.
203
- def test_format_path_with_path_and_body
204
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
205
- link = schema.resource('resource').link('update')
206
- assert_equal(['/resource/44724831-bf66-4bc2-865f-e2c4c2b14c78',
207
- {'new' => 'resource'}],
208
- link.format_path(['44724831-bf66-4bc2-865f-e2c4c2b14c78',
209
- {'new' => 'resource'}]))
210
- end
211
-
212
- # LinkSchema.format_path raises an ArgumentError if too few parameters are
213
- # provided
214
- def test_format_path_with_too_few_parameters
215
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
216
- link = schema.resource('resource').link('info')
217
- error = assert_raises ArgumentError do
218
- link.format_path([])
219
- end
220
- assert_equal('wrong number of arguments (0 for 1)', error.message)
221
- end
222
-
223
- # LinkSchema.format_path raises an ArgumentError if too many parameters are
224
- # provided
225
- def test_format_path_with_too_many_parameters
226
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
227
- link = schema.resource('resource').link('info')
228
- error = assert_raises ArgumentError do
229
- link.format_path(['too', 'many', 'parameters'])
230
- end
231
- assert_equal('wrong number of arguments (3 for 1)', error.message)
232
- end
233
-
234
- # LinkSchema.pretty_resource_name returns the resource name in a pretty
235
- # form, with underscores converted to dashes.
236
- def test_pretty_resource_name
237
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
238
- link = schema.resource('another-resource').link('list')
239
- assert_equal('another-resource', link.pretty_resource_name)
240
- end
241
-
242
- # LinkSchema.pretty_name returns the link name in a pretty form, with
243
- # underscores converted to dashes.
244
- def test_pretty_resource_name
245
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
246
- link = schema.resource('resource').link('identify_resource')
247
- assert_equal('identify-resource', link.pretty_name)
248
- end
249
-
250
- # LinkSchema.content_type returns the media type associated with this
251
- # resource.
252
- def test_content_type
253
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
254
- link = schema.resource('resource').link('submit')
255
- assert_equal('application/x-www-form-urlencoded', link.content_type)
256
- end
257
-
258
- # The content type should default to application/json
259
- def test_default_content_type
260
- schema = Heroics::Schema.new(SAMPLE_SCHEMA)
261
- link = schema.resource('resource').link('identify_resource')
262
- assert_equal('application/json', link.content_type)
263
- end
264
- end
265
-
266
- class DownloadSchemaTest < MiniTest::Unit::TestCase
267
- include ExconHelper
268
-
269
- # download_schema makes a request to fetch the schema, decodes the
270
- # downloaded JSON and returns a Ruby hash.
271
- def test_download_schema
272
- Excon.stub(method: :get) do |request|
273
- assert_equal('example.com', request[:host])
274
- assert_equal('/schema', request[:path])
275
- assert_equal('application/vnd.heroku+json; version=3',
276
- request[:headers]['Accept'])
277
- Excon.stubs.pop
278
- {status: 200, headers: {'Content-Type' => 'application/json'},
279
- body: MultiJson.dump(SAMPLE_SCHEMA)}
280
- end
281
-
282
- schema = Heroics::download_schema(
283
- 'https://username:token@example.com/schema',
284
- default_headers: {'Accept' => 'application/vnd.heroku+json; version=3'})
285
- assert_equal(SAMPLE_SCHEMA, schema.schema)
286
- end
287
- end
@@ -1,9 +0,0 @@
1
- require 'helper'
2
-
3
- class VersionTest < MiniTest::Unit::TestCase
4
- # Heroics::VERSION defines the version for the project in MAJOR.MINOR.PATCH
5
- # format.
6
- def test_version
7
- assert_match(/\d+.\d+.\d+/, Heroics::VERSION)
8
- end
9
- end