hammer_cli_foreman_webhooks 0.0.2 → 0.0.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.
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+
3
+ require 'hammer_cli/testing/output_matchers'
4
+ require 'hammer_cli/testing/command_assertions'
5
+ require 'hammer_cli/testing/data_helpers'
6
+ require 'hammer_cli_foreman/testing/api_expectations'
7
+
8
+ include HammerCLI::Testing::OutputMatchers
9
+ include HammerCLI::Testing::CommandAssertions
10
+ include HammerCLI::Testing::DataHelpers
11
+ include HammerCLIForeman::Testing::APIExpectations
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'webhook template' do
4
+ describe 'import' do
5
+ let(:template) do
6
+ {
7
+ 'id' => 1,
8
+ 'template' => 'Template content'
9
+ }
10
+ end
11
+ let(:cmd) { %w(webhook-template import) }
12
+ let(:tempfile) { Tempfile.new('template') }
13
+
14
+ it 'requires --name and --file' do
15
+ params = ['--name=test']
16
+ api_expects_no_call
17
+ expected_result = usage_error_result(
18
+ cmd,
19
+ 'Options --name, --file are required.',
20
+ 'Could not import the webhook template')
21
+ result = run_cmd(cmd + params)
22
+ assert_cmd(expected_result, result)
23
+ end
24
+
25
+ it 'import template' do
26
+ params = ['--name=test', "--file=#{tempfile.path}"]
27
+ tempfile.write('Template content')
28
+ tempfile.rewind
29
+ api_expects(:webhook_templates, :import, 'Import webhook template').with_params(
30
+ 'webhook_template' => {
31
+ 'name' => 'test',
32
+ 'template' => 'Template content'
33
+ }).returns(template)
34
+
35
+ result = run_cmd(cmd + params)
36
+ assert_cmd(success_result("Imported webhook template successfully.\n"), result)
37
+ end
38
+ end
39
+
40
+ describe 'export' do
41
+ let(:cmd) { %w(webhook-template export) }
42
+ let(:tempfile) { Tempfile.new('template', '/tmp') }
43
+ let(:params) { ['--id=1', '--path=/tmp'] }
44
+ let(:template_response) do
45
+ response = mock('TemplateResponse')
46
+ response.stubs(:code).returns(200)
47
+ response.stubs(:body).returns('Template content')
48
+ response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
49
+ response
50
+ end
51
+
52
+ it 'download template' do
53
+ api_expects(:webhook_templates, :export, 'Export webhook template').with_params(
54
+ 'id' => '1').returns(template_response)
55
+
56
+ output = OutputMatcher.new("The webhook template has been saved to #{tempfile.path}")
57
+ expected_result = success_result(output)
58
+ result = run_cmd(cmd + params)
59
+ assert_cmd(expected_result, result)
60
+ assert_equal('Template content', tempfile.read)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,18 @@
1
+ ENV['TEST_API_VERSION'] = ENV['TEST_API_VERSION'] || '3.3'
2
+ FOREMAN_WEBHOOKS_VERSION = Gem::Version.new(ENV['TEST_API_VERSION']).to_s
3
+
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+ require 'minitest-spec-context'
7
+ require 'mocha/minitest'
8
+ require 'hammer_cli'
9
+
10
+ HammerCLI.context[:api_connection].create('foreman') do
11
+ HammerCLI::Apipie::ApiConnection.new(
12
+ apidoc_cache_dir: 'test/data/' + FOREMAN_WEBHOOKS_VERSION,
13
+ apidoc_cache_name: 'foreman_api',
14
+ dry_run: true
15
+ )
16
+ end
17
+
18
+ require 'hammer_cli_foreman_webhooks'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_foreman_webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleh Fedorenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-23 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hammer_cli_foreman
@@ -46,6 +46,10 @@ files:
46
46
  - lib/hammer_cli_foreman_webhooks/version.rb
47
47
  - lib/hammer_cli_foreman_webhooks/webhook.rb
48
48
  - lib/hammer_cli_foreman_webhooks/webhook_template.rb
49
+ - test/data/3.3/foreman_api.json
50
+ - test/functional/test_helper.rb
51
+ - test/functional/webhook_template_test.rb
52
+ - test/test_helper.rb
49
53
  homepage: https://github.com/theforeman/hammer-cli-foreman-webhooks
50
54
  licenses:
51
55
  - GPL-3.0
@@ -69,4 +73,8 @@ rubygems_version: 3.1.2
69
73
  signing_key:
70
74
  specification_version: 4
71
75
  summary: Foreman Webhooks plugin for Hammer CLI
72
- test_files: []
76
+ test_files:
77
+ - test/data/3.3/foreman_api.json
78
+ - test/functional/test_helper.rb
79
+ - test/functional/webhook_template_test.rb
80
+ - test/test_helper.rb