rodzilla 0.1.3 → 0.3.0

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.
@@ -3,84 +3,71 @@ require "test_helper"
3
3
 
4
4
  describe Rodzilla::Resource::Base do
5
5
  before do
6
- @base = Rodzilla::Resource::Base.new('http://example.io', 'uname', 'passwd')
6
+ @base_service = Rodzilla::Resource::Base.new(StubSettings::URL, StubSettings::USERNAME, StubSettings::PASSWORD)
7
+ def new_mock; MiniTest::Mock.new; end
7
8
  end
8
9
 
9
- describe "instance" do
10
-
11
- it "has base_url accessors" do
12
- @base.must_respond_to('base_url')
13
- @base.must_respond_to('base_url=')
14
- end
10
+ it "attribute accessors" do
11
+ [:base_url, :username, :password, :service, :format].each { |m| @base_service.must_respond_to(m) }
12
+ [:base_url=, :username=, :password=, :service=, :format=].each { |m| @base_service.must_respond_to(m) }
13
+ end
15
14
 
16
- it "has username accessors" do
17
- @base.must_respond_to('username')
18
- @base.must_respond_to('username=')
15
+ describe "set_endpoint_url" do
16
+ it "should accept one argument - format" do
17
+ lambda { @base_service.send(:set_endpoint_url) }.must_raise(ArgumentError)
19
18
  end
20
19
 
21
- it "has password accessors" do
22
- @base.must_respond_to('password')
23
- @base.must_respond_to('password=')
20
+ it "should return base_url joined with the jsonrpc endpoint when arg is json" do
21
+ @base_service.send(:set_endpoint_url, :json).must_equal(@base_service.base_url + '/jsonrpc.cgi' )
24
22
  end
23
+ end
25
24
 
26
- it "has format accessors" do
27
- @base.must_respond_to('format')
28
- @base.must_respond_to('format=')
25
+ describe "setup_service" do
26
+ it "should accept one argument - format" do
27
+ lambda { @base_service.send(:setup_service) }.must_raise(ArgumentError)
29
28
  end
30
29
 
31
- it "has request_url accessors" do
32
- @base.must_respond_to('request_url')
33
- @base.must_respond_to('request_url=')
30
+ it "should set @endpoint_url and instantiate JsonRpc::Service when format is json" do
31
+ @base_service.service = nil
32
+ @base_service.send(:setup_service, :json)
33
+ @base_service.instance_variable_get(:@endpoint_url).must_equal(@base_service.base_url + '/jsonrpc.cgi' )
34
+ @base_service.service.must_be_kind_of(Rodzilla::JsonRpc::Service)
34
35
  end
36
+ end
35
37
 
36
- it "has response accessors" do
37
- @base.must_respond_to('response')
38
- @base.must_respond_to('response=')
38
+ describe "rpc_call" do
39
+ it "should require at least one argument - rpc_method_name" do
40
+ lambda { @base_service.send(:rpc_call) }.must_raise(ArgumentError)
39
41
  end
42
+ end
40
43
 
41
- it "has result accessors" do
42
- @base.must_respond_to('result')
43
- @base.must_respond_to('result=')
44
+ describe "get_resource_rpc_method_name" do
45
+ it "should require at least one argument - rpc_method_name" do
46
+ lambda { @base_service.send(:get_resource_rpc_method_name) }.must_raise(ArgumentError)
44
47
  end
45
48
 
46
- it "has credentials accessors" do
47
- @base.must_respond_to('credentials')
48
- @base.must_respond_to('credentials=')
49
+ it "should return a String as Resource.method_name" do
50
+ @base_service.send(:get_resource_rpc_method_name, 'hello').must_equal('Base.hello')
49
51
  end
52
+ end
50
53
 
51
- it "has headers accessors" do
52
- @base.must_respond_to('headers')
53
- @base.must_respond_to('headers=')
54
- end
54
+ describe "check_params" do
55
+ it "should return true if required is a subset of actual" do
56
+ required = [:name, :age]
57
+ actual = [:name, :age, :country]
58
+ actual2 = { name: '', age: 33, country: 'DE' }
55
59
 
56
- describe "class methods" do
57
- it "has a demodularize method" do
58
- Rodzilla::Resource::Base.must_respond_to(:demodulize)
59
- end
60
+ @base_service.send(:check_params, required, actual ).must_equal(true)
61
+ @base_service.send(:check_params, required, actual2 ).must_equal(true)
60
62
  end
61
63
 
62
- describe "protected_methods" do
63
- it "has a prepare_request method" do
64
- @base.protected_methods.must_include(:prepare_request)
65
- end
66
- it "has a build_url method" do
67
- @base.protected_methods.must_include(:build_url)
68
- end
69
- it "has a build_params method" do
70
- @base.protected_methods.must_include(:build_params)
71
- end
72
- it "has a make_id method" do
73
- @base.protected_methods.must_include(:make_id)
74
- end
75
-
76
- it "has a rpc_call method" do
77
- @base.protected_methods.must_include(:rpc_call)
78
- end
79
-
80
- it "has a parse_rpc_response! method" do
81
- @base.protected_methods.must_include(:parse_rpc_response!)
82
- end
64
+ it "should return false if required is not a subset of actual" do
65
+ required = [:a,:b, :c]
66
+ actual = [:a, :b, :foo]
67
+ actual2 = { a: '', b: 2, foo: 45 }
68
+ @base_service.send(:check_params, required, actual ).must_equal(false)
69
+ @base_service.send(:check_params, required, actual2 ).must_equal(false)
83
70
  end
84
-
85
71
  end
72
+
86
73
  end
@@ -1,44 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe Rodzilla::Resource::Bug do
4
- before do
5
- @bug = Rodzilla::Resource::Bug.new('http://asdf.net', 'asdf', 'asdf', :json)
6
- end
7
4
 
8
- describe "bug instance" do
9
- it "should inherit from Rodzilla::Resource::Base" do
10
- @bug.class.superclass.must_equal(Rodzilla::Resource::Base)
11
- end
12
-
13
- it "should respond_to create" do
14
- @bug.must_respond_to(:create)
15
- end
16
-
17
- it "should respond_to create!" do
18
- @bug.must_respond_to(:create!)
19
- end
20
-
21
- it "should respond_to fields" do
22
- @bug.must_respond_to(:fields)
23
- end
24
-
25
- it "should respond_to search" do
26
- @bug.must_respond_to(:search)
27
- end
28
-
29
- end
30
-
31
- describe "validations" do
32
-
33
- it "should have all Bugzilla REQUIRED_FIELDS for bug creation" do
34
- Rodzilla::Resource::Bug.constants.must_include(:REQUIRED_FIELDS)
35
- [:product, :component, :summary,
36
- :version, :description, :op_sys,
37
- :platform, :priority, :severity].each do |field|
38
- Rodzilla::Resource::Bug::REQUIRED_FIELDS.must_include(field)
39
- end
40
- end
41
-
42
- end
43
5
 
44
6
  end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe Rodzilla::Util do
4
+
5
+ describe "methods" do
6
+
7
+ it "should have a module method demodulize" do
8
+ Rodzilla::Util.must_respond_to(:demodulize)
9
+ end
10
+
11
+ end
12
+
13
+ describe "demodulize" do
14
+
15
+ it "should extract the classname from a module hierarchy" do
16
+ Rodzilla::Util.demodulize(Rodzilla::Resource::Base).must_equal('Base')
17
+ end
18
+
19
+ it "should return the to_s version of other arguments" do
20
+ Rodzilla::Util.demodulize(nil).must_equal("")
21
+ Rodzilla::Util.demodulize(Rodzilla).must_equal("Rodzilla")
22
+ end
23
+ end
24
+
25
+ end
@@ -6,15 +6,11 @@ describe Rodzilla::WebService do
6
6
  @service = Rodzilla::WebService.new('http://example.io', 'asdf', 'asdf')
7
7
  end
8
8
 
9
- after do
10
- @service
11
- end
12
-
13
- describe "initialization" do
9
+ describe "Constructor" do
14
10
  it "should accept 4 parameters: base_url, username, password, and format" do
15
11
  s = Rodzilla::WebService.new('http://example.io', 'uname', 'passwd', :json)
16
- s.username.must_equal('uname')
17
- s.password.must_equal('passwd')
12
+ s.instance_variable_get(:@username).must_equal('uname')
13
+ s.instance_variable_get(:@password).must_equal('passwd')
18
14
  s.base_url.must_equal('http://example.io')
19
15
  s.format.must_equal(:json)
20
16
  end
@@ -31,11 +27,26 @@ describe Rodzilla::WebService do
31
27
  end
32
28
  end
33
29
 
34
- describe "instance methods" do
35
-
36
- it "products should return ::Resource::Product class" do
37
- @service.products.must_be_kind_of(Rodzilla::Resource::Product)
30
+ describe "Attributes" do
31
+
32
+ it "should have attr_accessor for base_url" do
33
+ @service.must_respond_to(:base_url)
34
+ @service.must_respond_to(:base_url=)
38
35
  end
36
+
37
+ it "should have attr_accessor for format" do
38
+ @service.must_respond_to(:format)
39
+ @service.must_respond_to(:format=)
40
+ end
41
+
42
+ it "should have attr_accessor for resource" do
43
+ @service.must_respond_to(:resource)
44
+ @service.must_respond_to(:resource=)
45
+ end
46
+
47
+ end
48
+
49
+ describe "Resources" do
39
50
 
40
51
  it "bugs should return a Resource::Bug class" do
41
52
  @service.bugs.must_be_kind_of(Rodzilla::Resource::Bug)
@@ -49,10 +60,22 @@ describe Rodzilla::WebService do
49
60
  @service.classifications.must_be_kind_of(Rodzilla::Resource::Classification)
50
61
  end
51
62
 
63
+ it "groups should return a Resource::Group class" do
64
+ @service.groups.must_be_kind_of(Rodzilla::Resource::Group)
65
+ end
66
+
67
+ it "products should return ::Resource::Product class" do
68
+ @service.products.must_be_kind_of(Rodzilla::Resource::Product)
69
+ end
70
+
71
+ it "users should return ::Resource::User class" do
72
+ @service.users.must_be_kind_of(Rodzilla::Resource::User)
73
+ end
74
+
52
75
  it "bugzilla_resource should raise a Rodzilla::ResourceNotFoundError exception for undefined resources" do
53
76
  Proc.new do
54
77
  @service.send(:bugzilla_resource, "Nada")
55
- end.must_raise(Rodzilla::ResourceNotFoundError)
78
+ end.must_raise(Rodzilla::Error::ResourceNotFoundError)
56
79
  end
57
80
 
58
81
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,52 @@
1
1
  require 'minitest/spec'
2
2
  require 'minitest/autorun'
3
- require "rodzilla"
3
+ require 'webmock/minitest'
4
+ require "rodzilla"
5
+
6
+ # ========================
7
+ # Fixtures
8
+ # ========================
9
+ def method_fixture(name); fixture(name, :methods); end
10
+ def error_fixture(name); fixture(name, :errors); end
11
+
12
+ def fixture(name, type)
13
+ path = fixture_path(name, type)
14
+ File.new(path)
15
+ end
16
+
17
+ def fixture_path(filename, type=:methods)
18
+ File.expand_path(File.join(Dir.getwd, "test/fixtures", type.to_s, filename))
19
+ end
20
+
21
+ # ========================
22
+ # Stubs
23
+ # ========================
24
+
25
+ class StubSettings
26
+ URL = 'http://bugzilla.test.com'
27
+ USERNAME = 'bugzilla'
28
+ PASSWORD = 'bugzilla'
29
+
30
+ JSON_URL = URL + '/jsonrpc.cgi'
31
+ JSON_HEADERS = {
32
+ "Server" => "Apache/2.2.22 (Debian)",
33
+ "X-xss-protection" => "1; mode=block",
34
+ "X-frame-options" => "SAMEORIGIN",
35
+ "X-content-type-options" => "nosniff",
36
+ "Keep-Alive" => "timeout=5, max=100",
37
+ "Connection" => "Keep-Alive",
38
+ "Transfer-Encoding" => "chunked",
39
+ "Content-Type" => "application/json; charset=UTF-8"
40
+ }
41
+
42
+ end
43
+
44
+ def new_resource(resource)
45
+ Object.module_eval("Rodzilla::Resource::#{resource}").new(StubSettings::URL, StubSettings::USERNAME, StubSettings::PASSWORD)
46
+ end
47
+
48
+ def stub_bugzilla_request(rpc_name, type=:methods, http_method=:post)
49
+ filename = rpc_name.gsub('.', '_') + ".json"
50
+ raw_json = fixture(filename, type).read
51
+ WebMock.stub_request(http_method, StubSettings::JSON_URL ).to_return( body: raw_json, headers: StubSettings::JSON_HEADERS )
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodzilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Faucett
@@ -38,7 +38,7 @@ cert_chain:
38
38
  alZXVFhBWFBFN1FUSWp1NlcrRU12enNqbVNICndEZDdGSlE4bkdEaFlxaUtI
39
39
  L01DYXE3SEQ3L0ptZ0ZZalpOUENzeTBsVGtCdXIrVkMxbnN1ZFE9Ci0tLS0t
40
40
  RU5EIENFUlRJRklDQVRFLS0tLS0K
41
- date: 2013-10-14 00:00:00.000000000 Z
41
+ date: 2013-10-23 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: httparty
@@ -54,34 +54,6 @@ dependencies:
54
54
  - - ! '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
- - !ruby/object:Gem::Dependency
58
- name: libxml-ruby
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- type: :runtime
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- - !ruby/object:Gem::Dependency
72
- name: yajl-ruby
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :runtime
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ! '>='
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
57
  - !ruby/object:Gem::Dependency
86
58
  name: bundler
87
59
  requirement: !ruby/object:Gem::Requirement
@@ -96,48 +68,6 @@ dependencies:
96
68
  - - ~>
97
69
  - !ruby/object:Gem::Version
98
70
  version: '1.3'
99
- - !ruby/object:Gem::Dependency
100
- name: minitest
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ! '>='
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- - !ruby/object:Gem::Dependency
114
- name: rake
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ! '>='
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: debugger
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - ~>
132
- - !ruby/object:Gem::Version
133
- version: 1.6.2
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - ~>
139
- - !ruby/object:Gem::Version
140
- version: 1.6.2
141
71
  description: A Bugzilla ReST API Client
142
72
  email:
143
73
  - jwaterfaucett@gmail.com
@@ -153,16 +83,31 @@ files:
153
83
  - Rakefile
154
84
  - gem-public_cert.pem
155
85
  - lib/rodzilla.rb
156
- - lib/rodzilla/exception.rb
86
+ - lib/rodzilla/error.rb
87
+ - lib/rodzilla/json_rpc/error.rb
88
+ - lib/rodzilla/json_rpc/request.rb
89
+ - lib/rodzilla/json_rpc/response.rb
90
+ - lib/rodzilla/json_rpc/service.rb
157
91
  - lib/rodzilla/resource/base.rb
158
92
  - lib/rodzilla/resource/bug.rb
159
93
  - lib/rodzilla/resource/bugzilla.rb
160
94
  - lib/rodzilla/resource/classification.rb
95
+ - lib/rodzilla/resource/group.rb
161
96
  - lib/rodzilla/resource/product.rb
97
+ - lib/rodzilla/resource/user.rb
98
+ - lib/rodzilla/util.rb
162
99
  - lib/rodzilla/version.rb
100
+ - lib/rodzilla/web_service.rb
163
101
  - rodzilla.gemspec
102
+ - test/fixtures/methods/Bugzilla_extensions.json
103
+ - test/fixtures/methods/Bugzilla_version.json
104
+ - test/rodzilla/json_rpc/error_test.rb
105
+ - test/rodzilla/json_rpc/request_test.rb
106
+ - test/rodzilla/json_rpc/response_test.rb
107
+ - test/rodzilla/json_rpc/service_test.rb
164
108
  - test/rodzilla/resource/base_test.rb
165
109
  - test/rodzilla/resource/bug_test.rb
110
+ - test/rodzilla/resource/util_test.rb
166
111
  - test/rodzilla/web_service_test.rb
167
112
  - test/test_helper.rb
168
113
  homepage: https://github.com/jwaterfaucett/rodzilla
@@ -190,7 +135,14 @@ signing_key:
190
135
  specification_version: 4
191
136
  summary: Bugzilla API Client
192
137
  test_files:
138
+ - test/fixtures/methods/Bugzilla_extensions.json
139
+ - test/fixtures/methods/Bugzilla_version.json
140
+ - test/rodzilla/json_rpc/error_test.rb
141
+ - test/rodzilla/json_rpc/request_test.rb
142
+ - test/rodzilla/json_rpc/response_test.rb
143
+ - test/rodzilla/json_rpc/service_test.rb
193
144
  - test/rodzilla/resource/base_test.rb
194
145
  - test/rodzilla/resource/bug_test.rb
146
+ - test/rodzilla/resource/util_test.rb
195
147
  - test/rodzilla/web_service_test.rb
196
148
  - test/test_helper.rb