jirarest2 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  require "minitest/autorun"
2
- require "connect"
3
- require "credentials"
2
+ require "jirarest2/connect"
3
+ require "jirarest2/credentials"
4
4
  require "jirarest2/result"
5
+ require "webmock/minitest"
5
6
 
6
7
  class TestResult < MiniTest::Unit::TestCase
7
8
  def setup
@@ -10,19 +11,32 @@ class TestResult < MiniTest::Unit::TestCase
10
11
  end
11
12
 
12
13
  def test_code
13
- assert "200", @con.execute("Get","issue/createmeta/","").code
14
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {})
15
+ assert_equal "200", @con.execute("Get","issue/createmeta/","").code
14
16
  end
15
17
 
18
+ def test_code_400
19
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Content-Type'=>'application/json;charset=UTF-8'}).to_return(:status => 400, :body => "", :headers => {})
20
+ assert_equal "400", @con.execute("Get","issue/createmeta/","").code
21
+ end
22
+
23
+
16
24
  def test_header
17
- assert "test", @con.execute("Get","issue/createmeta/","").header["x-ausername"]
25
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => "", :headers => {"X-AUSERNAME" => "test"})
26
+ assert_equal ["test"], @con.execute("Get","issue/createmeta/","").header["x-ausername"]
18
27
  end
19
28
 
29
+
20
30
  def test_result
21
- assert "projects", @con.execute("Get","issue/createmeta/","").result["expand"]
31
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"expand":"projects","projects":[{"self":"http://localhost:2990/jira/rest/api/2/project/MFTP","id":"10000","key":"MFTP","name":"My first Test Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"},"issuetypes":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/1","id":"1","description":"A problem which impairs or prevents the functions of the product.","iconUrl":"http://localhost:2990/jira/images/icons/bug.gif","name":"Bug","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/3","id":"3","description":"A task that needs to be done.","iconUrl":"http://localhost:2990/jira/images/icons/task.gif","name":"Task","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/5","id":"5","description":"The sub-task of the issue","iconUrl":"http://localhost:2990/jira/images/icons/issue_subtask.gif","name":"Sub-task","subtask":true},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/4","id":"4","description":"An improvement or enhancement to an existing feature or task.","iconUrl":"http://localhost:2990/jira/images/icons/improvement.gif","name":"Improvement","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/2","id":"2","description":"A new feature of the product, which has yet to be developed.","iconUrl":"http://localhost:2990/jira/images/icons/newfeature.gif","name":"New Feature","subtask":false}]},{"self":"http://localhost:2990/jira/rest/api/2/project/SP","id":"10100","key":"SP","name":"Second Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10100&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10100&avatarId=10011"},"issuetypes":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/1","id":"1","description":"A problem which impairs or prevents the functions of the product.","iconUrl":"http://localhost:2990/jira/images/icons/bug.gif","name":"Bug","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/2","id":"2","description":"A new feature of the product, which has yet to be developed.","iconUrl":"http://localhost:2990/jira/images/icons/newfeature.gif","name":"New Feature","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/3","id":"3","description":"A task that needs to be done.","iconUrl":"http://localhost:2990/jira/images/icons/task.gif","name":"Task","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/4","id":"4","description":"An improvement or enhancement to an existing feature or task.","iconUrl":"http://localhost:2990/jira/images/icons/improvement.gif","name":"Improvement","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/5","id":"5","description":"The sub-task of the issue","iconUrl":"http://localhost:2990/jira/images/icons/issue_subtask.gif","name":"Sub-task","subtask":true},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/7","id":"7","description":"","iconUrl":"http://localhost:2990/jira/images/icons/genericissue.gif","name":"Trys","subtask":false}]}]}', :headers => {})
32
+
33
+ assert_equal "projects", @con.execute("Get","issue/createmeta/","").result["expand"]
22
34
  end
23
35
 
24
36
 
25
37
  def test_body
38
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/createmeta/").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"expand":"projects","projects":[{"self":"http://localhost:2990/jira/rest/api/2/project/MFTP","id":"10000","key":"MFTP","name":"My first Test Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10000&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10000&avatarId=10011"},"issuetypes":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/1","id":"1","description":"A problem which impairs or prevents the functions of the product.","iconUrl":"http://localhost:2990/jira/images/icons/bug.gif","name":"Bug","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/3","id":"3","description":"A task that needs to be done.","iconUrl":"http://localhost:2990/jira/images/icons/task.gif","name":"Task","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/5","id":"5","description":"The sub-task of the issue","iconUrl":"http://localhost:2990/jira/images/icons/issue_subtask.gif","name":"Sub-task","subtask":true},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/4","id":"4","description":"An improvement or enhancement to an existing feature or task.","iconUrl":"http://localhost:2990/jira/images/icons/improvement.gif","name":"Improvement","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/2","id":"2","description":"A new feature of the product, which has yet to be developed.","iconUrl":"http://localhost:2990/jira/images/icons/newfeature.gif","name":"New Feature","subtask":false}]},{"self":"http://localhost:2990/jira/rest/api/2/project/SP","id":"10100","key":"SP","name":"Second Project","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/projectavatar?size=small&pid=10100&avatarId=10011","48x48":"http://localhost:2990/jira/secure/projectavatar?pid=10100&avatarId=10011"},"issuetypes":[{"self":"http://localhost:2990/jira/rest/api/2/issuetype/1","id":"1","description":"A problem which impairs or prevents the functions of the product.","iconUrl":"http://localhost:2990/jira/images/icons/bug.gif","name":"Bug","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/2","id":"2","description":"A new feature of the product, which has yet to be developed.","iconUrl":"http://localhost:2990/jira/images/icons/newfeature.gif","name":"New Feature","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/3","id":"3","description":"A task that needs to be done.","iconUrl":"http://localhost:2990/jira/images/icons/task.gif","name":"Task","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/4","id":"4","description":"An improvement or enhancement to an existing feature or task.","iconUrl":"http://localhost:2990/jira/images/icons/improvement.gif","name":"Improvement","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/5","id":"5","description":"The sub-task of the issue","iconUrl":"http://localhost:2990/jira/images/icons/issue_subtask.gif","name":"Sub-task","subtask":true},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/6","id":"6","description":"An own issue type","iconUrl":"http://localhost:2990/jira/images/icons/ico_epic.png","name":"My issue type","subtask":false},{"self":"http://localhost:2990/jira/rest/api/2/issuetype/7","id":"7","description":"","iconUrl":"http://localhost:2990/jira/images/icons/genericissue.gif","name":"Trys","subtask":false}]}]}', :headers => {})
39
+
26
40
  assert_match "http://localhost:2990/jira/rest/api/2/project", @con.execute("Get","issue/createmeta/","").body
27
41
  end
28
42
 
@@ -1,8 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "minitest/autorun"
3
- require "credentials"
4
- require "connect"
5
- require "services/watcher"
3
+ require "jirarest2/credentials"
4
+ require "jirarest2/connect"
5
+ require "jirarest2/services/watcher"
6
+ require "webmock/minitest"
6
7
 
7
8
  class TestWatcher < MiniTest::Unit::TestCase
8
9
  def setup
@@ -10,24 +11,37 @@ class TestWatcher < MiniTest::Unit::TestCase
10
11
  @con = Connect.new(cred)
11
12
  end
12
13
 
13
- def test_get_watchers
14
+ def test_get_watchers_filled
15
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/MFTP-7/watchers").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"self":"http://localhost:2990/jira/rest/api/2/issue/MFTP-7/watchers","isWatching":true,"watchCount":3,"watchers":[{"self":"http://localhost:2990/jira/rest/api/2/user?username=admin","name":"admin","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10122","48x48":"http://localhost:2990/jira/secure/useravatar?avatarId=10122"},"displayName":"admin","active":true},{"self":"http://localhost:2990/jira/rest/api/2/user?username=cebit","name":"cebit","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10122","48x48":"http://localhost:2990/jira/secure/useravatar?avatarId=10122"},"displayName":"Cyril Bitterich","active":true},{"self":"http://localhost:2990/jira/rest/api/2/user?username=test","name":"test","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10122","48x48":"http://localhost:2990/jira/secure/useravatar?avatarId=10122"},"displayName":"Test User","active":true}]}', :headers => {})
14
16
  watchers = Watcher.new(@con,"MFTP-7")
15
- assert ["admin","cebit","test"], watchers.get_watchers
16
- assert [], Watcher.new(@con,"MFTP-3")
17
+ assert_equal ["admin","cebit","test"], watchers.get_watchers
18
+ end
19
+
20
+ def test_get_watchers_empty
21
+ stub_request(:get, "http://test:1234@localhost:2990/jira/rest/api/2/issue/MFTP-3/watchers").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => '{"self":"http://localhost:2990/jira/rest/api/2/issue/MFTP-3/watchers","isWatching":false,"watchCount":0,"watchers":[]}', :headers => {})
22
+ watchers = Watcher.new(@con,"MFTP-3")
23
+ assert_equal [], watchers.get_watchers
17
24
  end
18
25
 
19
26
  def test_delete_watcher
27
+ stub_request(:delete, "http://test:1234@localhost:2990/jira/rest/api/2/issue/MFTP-7/watchers?username=cebit").with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 401, :body => '{"errorMessages":["User \'test\' is not allowed to remove watchers from issue \'MFTP-7\'"],"errors":{}}', :headers => {})
28
+
20
29
  watchers = Watcher.new(@con,"MFTP-7")
21
30
  assert_raises(Jirarest2::AuthentificationError) {
22
31
  watchers.remove_watcher("cebit")
23
32
  }
24
33
  end
25
34
 
26
- def test_add_watcher
35
+ def test_add_watcher_fail
36
+ stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issue/MFTP-2/watchers").with(:body => "\"cebit\"", :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 401, :body => '{"errorMessages":["User \'test\' is not allowed to add watchers to issue \'MFTP-2\'"],"errors":{}}', :headers => {})
37
+
27
38
  watcherna = Watcher.new(@con, "MFTP-2")
28
39
  assert_raises(Jirarest2::AuthentificationError) {
29
40
  watcherna.add_watcher("cebit")
30
41
  }
42
+ end
43
+ def test_add_watcher_success
44
+ stub_request(:post, "http://test:1234@localhost:2990/jira/rest/api/2/issue/SP-1/watchers").with(:body => "\"cebit\"",:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json;charset=UTF-8', 'User-Agent'=>'Ruby'}).to_return(:status => 204, :headers => {})
31
45
  watchers = Watcher.new(@con, "SP-1")
32
46
  assert true, watchers.add_watcher("cebit")
33
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jirarest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,7 +50,7 @@ cert_chain:
50
50
  -----END CERTIFICATE-----
51
51
 
52
52
  '
53
- date: 2012-07-18 00:00:00.000000000 Z
53
+ date: 2012-07-23 00:00:00.000000000 Z
54
54
  dependencies:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
@@ -100,6 +100,22 @@ dependencies:
100
100
  - - ! '>='
101
101
  - !ruby/object:Gem::Version
102
102
  version: 0.1.2
103
+ - !ruby/object:Gem::Dependency
104
+ name: webmock
105
+ requirement: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.7.0
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: 1.7.0
103
119
  - !ruby/object:Gem::Dependency
104
120
  name: hoe
105
121
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +144,7 @@ email:
128
144
  - cebit-jirarest@gunnet.de
129
145
  executables:
130
146
  - create_issue.rb
147
+ - jira_create_issue
131
148
  - jira_create_issue.rb
132
149
  extensions: []
133
150
  extra_rdoc_files:
@@ -142,19 +159,21 @@ files:
142
159
  - README.txt
143
160
  - Rakefile
144
161
  - bin/create_issue.rb
162
+ - bin/jira_create_issue
145
163
  - bin/jira_create_issue.rb
146
164
  - copyright
147
- - lib/connect.rb
148
- - lib/credentials.rb
149
- - lib/exceptions.rb
150
- - lib/issue.rb
151
165
  - lib/jirarest2.rb
166
+ - lib/jirarest2/connect.rb
167
+ - lib/jirarest2/credentials.rb
168
+ - lib/jirarest2/exceptions.rb
169
+ - lib/jirarest2/issue.rb
170
+ - lib/jirarest2/madbitconfig.rb
152
171
  - lib/jirarest2/result.rb
153
- - lib/madbitconfig.rb
154
- - lib/services.rb
155
- - lib/services/issuelink.rb
156
- - lib/services/issuelinktype.rb
157
- - lib/services/watcher.rb
172
+ - lib/jirarest2/services.rb
173
+ - lib/jirarest2/services/issuelink.rb
174
+ - lib/jirarest2/services/issuelinktype.rb
175
+ - lib/jirarest2/services/watcher.rb
176
+ - test/data/issuespec.txt
158
177
  - test/data/test.config.data
159
178
  - test/data/test.json
160
179
  - test/data/test.nojson
metadata.gz.sig CHANGED
Binary file
@@ -1,91 +0,0 @@
1
- #
2
- # Copyright (C) 2012 Cyril Bitterich
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- #
17
-
18
- require "services"
19
-
20
- # An IssueLinkType Object represents one or all IssueLinkTypes
21
- class IssueLinkType < Services
22
-
23
-
24
- # @param [Connection] connection
25
- # @param [String] data issueLinkType ID
26
- # @return [Jirarest2::Result]
27
- def initialize(connection,data = "")
28
- if data == "" then
29
- @uritail = "issueLinkType"
30
- else
31
- @uritail = "issueLinkType/#{data}"
32
- end
33
- super(connection)
34
- @all = get
35
- end
36
-
37
- private
38
-
39
- # do the search for each block
40
- # @param [Hash] hash One LinkIssueType in a hash representation
41
- # @param [String] uiname the way the linktype is shown in the browser
42
- # @return [Array] Actual name oft the LinkIssueType
43
- def name_block_search(hash,uiname)
44
- name = nil
45
- direction = nil
46
- if ( hash["inward"] == uiname) then
47
- direction = "inward"
48
- name = hash["name"]
49
- return name, direction
50
- elsif (hash["outward"] == uiname) then
51
- direction = "outward"
52
- name = hash["name"]
53
- return name, direction
54
- else
55
- return nil # Save my butt
56
- end
57
- end
58
-
59
-
60
- public
61
-
62
- #Get the internal name and direction instead of the one in the UI.
63
- # @param [String] uiname the way the linktype is shown in the browser
64
- # @return [Array, nil] Array with the name and the direction ("inward" or "outward") if successfull , nil if not
65
- def name(uiname)
66
- if @all["issueLinkTypes"].instance_of?(Array) then
67
- @all["issueLinkTypes"].each{ |hash|
68
- result = name_block_search(hash,uiname)
69
- return result if result # Return if we got an actual result
70
- }
71
- else
72
- return name_block_search(@all,uiname)
73
- end
74
- return nil # Nothing found don't want to return @all
75
- end # name
76
-
77
- # Is the name realy the internal name we need to use?
78
- # @param [String] test String to test agains the names of IssueLinkTypes
79
- # @return [Boolean]
80
- def internal_name?(test)
81
- if @all["issueLinkTypes"].instance_of?(Array) then
82
- @all["issueLinkTypes"].each{ |hash|
83
- return true if ( hash["name"] == test)
84
- }
85
- else
86
- return ( @all["name"] == test )
87
- end
88
- return false # Nothing found don't want to return @all
89
- end
90
-
91
- end #class