bicho 0.0.10 → 0.0.12

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.
@@ -37,7 +37,7 @@ module Bicho
37
37
  # your oscrc.
38
38
  #
39
39
  class Novell
40
- OSCRC_CREDENTIALS = 'https://api.opensuse.org' unless defined? OSCRC_CREDENTIALS
40
+ OSCRC_CREDENTIALS = 'https://api.opensuse.org'.freeze unless defined? OSCRC_CREDENTIALS
41
41
  DEFAULT_OSCRC_PATH = File.join(ENV['HOME'], '.oscrc') unless defined? DEFAULT_OSCRC_PATH
42
42
 
43
43
  class << self
@@ -60,11 +60,9 @@ module Bicho
60
60
  next unless oscrc.has_section?(section)
61
61
  user = oscrc[section]['user']
62
62
  pass = oscrc[section]['pass']
63
- if user && pass
64
- return { user: user, password: pass }
65
- end
63
+ return { user: user, password: pass } if user && pass
66
64
  end
67
- fail "No valid .oscrc credentials for Novell/SUSE bugzilla (#{oscrc_path})"
65
+ raise "No valid .oscrc credentials for Novell/SUSE bugzilla (#{oscrc_path})"
68
66
  end
69
67
 
70
68
  def transform_site_url_hook(url, _logger)
@@ -80,16 +78,20 @@ module Bicho
80
78
  domains = ['bugzilla.novell.com', 'bugzilla.suse.com']
81
79
  return url unless domains.map { |domain| url.host.include?(domain) }.any?
82
80
 
83
- auth = Novell.oscrc_credentials
81
+ begin
82
+ auth = Novell.oscrc_credentials
84
83
 
85
- url = url.clone
86
- url.user = auth[:user]
87
- url.password = auth[:password]
88
- url.host = url.host.gsub(/bugzilla\.novell.com/, 'apibugzilla.novell.com')
89
- url.host = url.host.gsub(/bugzilla\.suse.com/, 'apibugzilla.novell.com')
90
- url.scheme = 'https'
84
+ url = url.clone
85
+ url.user = auth[:user]
86
+ url.password = auth[:password]
87
+ url.host = url.host.gsub(/bugzilla\.novell.com/, 'apibugzilla.novell.com')
88
+ url.host = url.host.gsub(/bugzilla\.suse.com/, 'apibugzilla.suse.com')
89
+ url.scheme = 'https'
91
90
 
92
- logger.debug("#{self} : Rewrote url to '#{url.to_s.gsub(/#{url.user}:#{url.password}/, 'USER:PASS')}'")
91
+ logger.debug("#{self} : Rewrote url to '#{url.to_s.gsub(/#{url.user}:#{url.password}/, 'USER:PASS')}'")
92
+ rescue StandardError => e
93
+ logger.warn e
94
+ end
93
95
  url
94
96
  end
95
97
  end
@@ -2,9 +2,10 @@ require 'yaml'
2
2
 
3
3
  module Bicho
4
4
  module Plugins
5
-
5
+ # Plugin to get preferences from the user home directory
6
+ # .config/bicho/config.yml
7
+ #
6
8
  class User
7
-
8
9
  DEFAULT_CONFIG_PATH = File.join(ENV['HOME'], '.config', 'bicho', 'config.yml') unless defined? DEFAULT_CONFIG_PATH
9
10
 
10
11
  class << self
@@ -17,9 +18,7 @@ module Bicho
17
18
 
18
19
  def initialize
19
20
  @config = {}
20
- if File.exist?(Bicho::Plugins::User.config_path)
21
- @config = YAML.load_file(Bicho::Plugins::User.config_path)
22
- end
21
+ @config = YAML.load_file(Bicho::Plugins::User.config_path) if File.exist?(Bicho::Plugins::User.config_path)
23
22
  end
24
23
 
25
24
  def default_site_url_hook(logger)
@@ -41,9 +40,6 @@ module Bicho
41
40
  url
42
41
  end
43
42
  end
44
-
45
-
46
43
  end
47
-
48
44
  end
49
45
  end
@@ -41,7 +41,7 @@ module Bicho
41
41
  ret = Bicho.client.search_bugs(self)
42
42
  return ret.each unless block_given?
43
43
  ret.each { |bug| yield bug }
44
- end
44
+ end
45
45
 
46
46
  # obtains the parameter that can be passed to the XMLRPC API
47
47
  # @private
@@ -92,9 +92,7 @@ module Bicho
92
92
  #
93
93
  # @private
94
94
  def append_query(param, value)
95
- unless @query_map.key?(param)
96
- @query_map[param] = []
97
- end
95
+ @query_map[param] = [] unless @query_map.key?(param)
98
96
  @query_map[param] = [@query_map[param], value].flatten
99
97
  end
100
98
  end
@@ -1,3 +1,3 @@
1
1
  module Bicho
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.12'.freeze
3
3
  end
@@ -1,5 +1,12 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
+ require 'minitest/reporters'
4
+ require 'minitest/mock'
5
+ Minitest::Reporters.use!(
6
+ Minitest::Reporters::ProgressReporter.new,
7
+ ENV,
8
+ Minitest.backtrace_filter
9
+ )
3
10
  require 'bicho'
4
11
 
5
12
  if ENV['DEBUG']
@@ -0,0 +1,30 @@
1
+ require_relative 'helper'
2
+ require 'digest'
3
+
4
+ # Test for bug attachments
5
+ class AttachmentsTest < Minitest::Test
6
+ def test_client_get_attachments
7
+ Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
8
+
9
+ attachments = Bicho.client.get_attachments(679745)
10
+ assert_kind_of(Array, attachments)
11
+ assert !attachments.empty?
12
+
13
+ attachments.each do |attachment|
14
+ assert_kind_of(Bicho::Attachment, attachment)
15
+
16
+ next unless attachment.id == 329690
17
+ assert_equal('text/plain', attachment.content_type)
18
+ assert_equal(8559, attachment.size)
19
+ assert_equal('user-accounts: use Password Login instead of Automatic Login',
20
+ attachment.summary)
21
+
22
+ assert_equal('80c4665205bcbd2b90ea920eff21f29988d8fc85f36c293a65fa3dad52d19354',
23
+ Digest::SHA256.hexdigest(attachment.data.read))
24
+ end
25
+ end
26
+
27
+ def teardown
28
+ Bicho.client = nil
29
+ end
30
+ end
@@ -1,13 +1,19 @@
1
- require File.join(File.dirname(__FILE__), 'helper')
2
-
3
- class History_test < Test::Unit::TestCase
1
+ require_relative 'helper'
4
2
 
3
+ # Test for bug history
4
+ class HistoryTest < Minitest::Test
5
5
  def test_basic_history
6
6
  Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
7
7
 
8
8
  bug = Bicho.client.get_bug(645150)
9
9
 
10
- assert bug.history.size > 0
10
+ history = bug.history
11
+
12
+ assert !history.empty?
13
+
14
+ history.each do |c|
15
+ assert c.timestamp.to_time.to_i > 0
16
+ end
11
17
  end
12
18
 
13
19
  def teardown
@@ -1,41 +1,43 @@
1
- require File.join(File.dirname(__FILE__), 'helper')
1
+ require_relative 'helper'
2
2
  require 'bicho/plugins/novell'
3
- require 'tmpdir'
3
+ require 'logger'
4
4
 
5
- # Test for the plugin supporting the
6
- # Novell/SUSE bugzilla authentication
7
- class NovellPluginTest < Test::Unit::TestCase
8
- def test_urls_are_correct
5
+ # Test for the plugin supporting the Novell/SUSE bugzilla authentication
6
+ class NovellPluginTest < Minitest::Test
7
+ def test_url_replacement
8
+ r, w = IO.pipe
9
+ log = Logger.new(w)
9
10
  %w(novell suse).each do |domain|
10
- client = Bicho::Client.new("https://bugzilla.#{domain}.com")
11
- assert_raises NoMethodError do
12
- client.url
11
+ creds = { user: 'test', password: 'test' }
12
+ Bicho::Plugins::Novell.stub :oscrc_credentials, creds do
13
+ plugin = Bicho::Plugins::Novell.new
14
+ url = URI.parse("http://bugzilla.#{domain}.com")
15
+ site_url = plugin.transform_site_url_hook(url, log)
16
+ api_url = plugin.transform_api_url_hook(url, log)
17
+ assert_equal(site_url.to_s, "http://bugzilla.#{domain}.com")
18
+ assert_equal(api_url.to_s, 'https://test:test@apibugzilla.novell.com')
19
+ assert_match(/Rewrote url/, r.gets)
13
20
  end
14
21
  end
15
22
  end
16
23
 
17
- def self.write_fake_oscrc(path)
18
- File.open(path, 'w') do |f|
19
- f.write(<<EOS)
24
+ def test_oscrc_parsing
25
+ oscrc = <<EOS
20
26
  [https://api.opensuse.org]
21
27
  user = foo
22
28
  pass = bar
23
29
  # fake osc file
24
30
  EOS
25
- end
26
- end
27
31
 
28
- def test_oscrc_parsing
29
32
  Dir.mktmpdir do |tmp|
30
- fake_oscrc = File.join(tmp, 'oscrc')
31
- NovellPluginTest.write_fake_oscrc(fake_oscrc)
32
- Bicho::Plugins::Novell.oscrc_path = fake_oscrc
33
- plugin = Bicho::Plugins::Novell.new
34
- credentials = Bicho::Plugins::Novell.oscrc_credentials
35
- assert_not_nil(credentials)
36
- assert(credentials.key?(:user))
37
- assert(credentials.key?(:password))
38
- Bicho::Plugins::Novell.oscrc_path = nil
33
+ fake_oscrc = File.join(tmp, '.oscrc')
34
+ File.write(fake_oscrc, oscrc)
35
+ Bicho::Plugins::Novell.stub :oscrc_path, fake_oscrc do
36
+ credentials = Bicho::Plugins::Novell.oscrc_credentials
37
+ refute_nil(credentials)
38
+ assert(credentials.key?(:user))
39
+ assert(credentials.key?(:password))
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -1,9 +1,10 @@
1
- require File.join(File.dirname(__FILE__), 'helper')
1
+ require_relative 'helper'
2
2
 
3
- class Query_test < Test::Unit::TestCase
3
+ # Test query DSL
4
+ class QueryTest < Minitest::Test
4
5
  def test_active_record_style
5
6
  # No client set yet
6
- assert_raise RuntimeError do
7
+ assert_raises RuntimeError do
7
8
  Bicho::Bug.where.assigned_to('foo@bar.com').each do |bug|
8
9
  puts bug
9
10
  end
@@ -11,7 +12,7 @@ class Query_test < Test::Unit::TestCase
11
12
 
12
13
  Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
13
14
 
14
- ret = Bicho::Bug.where.product('vala').status('resolved').component('Basic Types').each.to_a
15
+ ret = Bicho::Bug.where.product('vala').status('resolved').component('Basic Types').each.to_a
15
16
  assert ret.collect(&:id).include?(645_150)
16
17
  end
17
18
 
@@ -24,7 +25,7 @@ class Query_test < Test::Unit::TestCase
24
25
  ret = Bicho::Query.new.open
25
26
  assert_equal({ 'status' => [:new, :assigned, :needinfo, :reopened] }, ret.query_map)
26
27
  end
27
-
28
+
28
29
  def teardown
29
30
  Bicho.client = nil
30
31
  end
@@ -4,8 +4,7 @@ require 'tmpdir'
4
4
 
5
5
  # Test for the plugin implementing user
6
6
  # preferences
7
- class UserPluginTest < Test::Unit::TestCase
8
-
7
+ class UserPluginTest < Minitest::Test
9
8
  def self.write_fake_config(path)
10
9
  File.open(path, 'w') do |f|
11
10
  f.write(<<EOS)
@@ -1,21 +1,20 @@
1
- require File.join(File.dirname(__FILE__), 'helper')
1
+ require_relative 'helper'
2
2
 
3
- #
4
3
  # Test getting the version of the Bugzilla API
5
- #
6
- class Version_test < Test::Unit::TestCase
4
+ class VersionTest < Minitest::Test
7
5
  def test_version_gnome
8
6
  Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
9
7
 
10
- ret = Bicho::client.version
11
- assert ret =~ /3.4/ # https://bugzilla.gnome.org/ is at 3.4.13 as of Jan/2015
8
+ ret = Bicho.client.version
9
+ # https://bugzilla.gnome.org/ is at 4.4.12 as of Jun/2016
10
+ assert_match(/4.4/, ret)
12
11
  end
13
12
 
14
13
  def test_version_suse
15
14
  Bicho.client = Bicho::Client.new('https://bugzilla.suse.com')
16
15
 
17
- ret = Bicho::client.version
18
- assert ret =~ /4.4/ #https://bugzilla.suse.com is at 4.4.6 as of Jan/2015
16
+ ret = Bicho.client.version
17
+ # https://bugzilla.suse.com is at 4.4.6 as of Jan/2015
18
+ assert_match(/4.4/, ret)
19
19
  end
20
-
21
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bicho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duncan Mac-Vicar P.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -66,6 +66,62 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Library to access bugzilla
70
126
  email:
71
127
  - dmacvicar@suse.de
@@ -76,15 +132,18 @@ extra_rdoc_files: []
76
132
  files:
77
133
  - ".gitignore"
78
134
  - ".rubocop.yml"
135
+ - ".travis.yml"
79
136
  - Gemfile
80
137
  - MIT-LICENSE
81
- - README.rdoc
138
+ - README.md
82
139
  - Rakefile
83
140
  - bicho.gemspec
84
141
  - bin/bicho
85
142
  - lib/bicho.rb
143
+ - lib/bicho/attachment.rb
86
144
  - lib/bicho/bug.rb
87
145
  - lib/bicho/cli/command.rb
146
+ - lib/bicho/cli/commands/attachments.rb
88
147
  - lib/bicho/cli/commands/history.rb
89
148
  - lib/bicho/cli/commands/search.rb
90
149
  - lib/bicho/cli/commands/show.rb
@@ -100,6 +159,7 @@ files:
100
159
  - lib/bicho/query.rb
101
160
  - lib/bicho/version.rb
102
161
  - test/helper.rb
162
+ - test/test_attachments.rb
103
163
  - test/test_history.rb
104
164
  - test/test_novell_plugin.rb
105
165
  - test/test_query.rb
@@ -131,6 +191,7 @@ specification_version: 4
131
191
  summary: Library to access bugzilla
132
192
  test_files:
133
193
  - test/helper.rb
194
+ - test/test_attachments.rb
134
195
  - test/test_history.rb
135
196
  - test/test_novell_plugin.rb
136
197
  - test/test_query.rb