portal_module 0.0.2

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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +13 -0
  5. data/Guardfile +24 -0
  6. data/LICENSE +22 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +240 -0
  9. data/Rakefile +101 -0
  10. data/bin/portal_module +10 -0
  11. data/lib/portal_module/assertable.rb +37 -0
  12. data/lib/portal_module/cli.rb +35 -0
  13. data/lib/portal_module/client.rb +110 -0
  14. data/lib/portal_module/command/client_access.rb +41 -0
  15. data/lib/portal_module/command/config.rb +323 -0
  16. data/lib/portal_module/command/dts.rb +70 -0
  17. data/lib/portal_module/command/loan_entry.rb +66 -0
  18. data/lib/portal_module/command.rb +16 -0
  19. data/lib/portal_module/config_helper.rb +32 -0
  20. data/lib/portal_module/dts.rb +99 -0
  21. data/lib/portal_module/loan_entry.rb +101 -0
  22. data/lib/portal_module/page_factory.rb +27 -0
  23. data/lib/portal_module/pages/data_transformation_page.rb +84 -0
  24. data/lib/portal_module/pages/login_page.rb +73 -0
  25. data/lib/portal_module/pages/prequal_setup_page.rb +77 -0
  26. data/lib/portal_module/pages.rb +90 -0
  27. data/lib/portal_module/rake/dts_tasks.rb +166 -0
  28. data/lib/portal_module/rake/loan_entry_tasks.rb +166 -0
  29. data/lib/portal_module/rake.rb +16 -0
  30. data/lib/portal_module/version.rb +3 -0
  31. data/lib/portal_module.rb +251 -0
  32. data/portal_module.gemspec +33 -0
  33. data/spec/data/dts_import.xml +1 -0
  34. data/spec/data/le_import.xml +1 -0
  35. data/spec/lib/portal_module/cli_spec.rb +35 -0
  36. data/spec/lib/portal_module/client_spec.rb +126 -0
  37. data/spec/lib/portal_module/command/config_spec.rb +474 -0
  38. data/spec/lib/portal_module/command/dts_spec.rb +98 -0
  39. data/spec/lib/portal_module/command/loan_entry_spec.rb +98 -0
  40. data/spec/lib/portal_module/dts_spec.rb +145 -0
  41. data/spec/lib/portal_module/loan_entry_spec.rb +113 -0
  42. data/spec/lib/portal_module_spec.rb +175 -0
  43. data/spec/spec_helper.rb +52 -0
  44. data/spec/support/asserts.rb +10 -0
  45. data/spec/support/dirs.rb +53 -0
  46. data/spec/support/helpers.rb +44 -0
  47. data/spec/support/mocks.rb +106 -0
  48. metadata +247 -0
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'command dts' do
4
+
5
+ let(:page_factory) do
6
+ obj = MockPageFactory.new
7
+ end
8
+
9
+ let(:client) do
10
+ obj = mock_client(page_factory)
11
+ end
12
+
13
+ let(:dts_mock) do
14
+ obj = mock_dts(page_factory)
15
+ end
16
+
17
+ before do
18
+ PortalModule.configure do |config|
19
+ config.credentials[:dev] = ['user', 'pass']
20
+ config.download_dir = spec_tmp_dir('downloads')
21
+ config.orgs['Test Org'] = '1'
22
+ end
23
+ end
24
+
25
+ it "returns help info" do
26
+ output = capture_output do
27
+ run_with_args %w(help dts)
28
+ end
29
+
30
+ expect( output ).to include "dts help [COMMAND]"
31
+ expect( output ).to include "dts upload <org> <filepath>"
32
+ expect( output ).to include "dts download <org> <filepath>"
33
+ expect( output ).to include "e, [--environment=dev]"
34
+ end
35
+
36
+ context "upload" do
37
+ it "uploads a DTS configuration file to the portal" do
38
+ file_path = (spec_data_dir() + 'dts_upload.xml').to_s
39
+
40
+ expect(client)
41
+ .to receive(:user=)
42
+ .with('user')
43
+
44
+ expect(client)
45
+ .to receive(:password=)
46
+ .with('pass')
47
+
48
+ expect(client)
49
+ .to receive(:env=)
50
+ .with('dev')
51
+
52
+ expect(client)
53
+ .to receive(:dts)
54
+ .and_return(dts_mock)
55
+
56
+ expect(dts_mock)
57
+ .to receive(:upload)
58
+ .with('Test Org', file_path)
59
+
60
+ expect(client)
61
+ .to receive(:logout)
62
+
63
+ run_with_args ['dts', 'upload', '-e', 'dev', 'Test Org', file_path], client
64
+ end
65
+ end
66
+
67
+ context "download" do
68
+ it "downloads a DTS configuration file from the portal" do
69
+ file_path = (spec_tmp_dir('dts/downlod') + 'dts_download.xml').to_s
70
+
71
+ expect(client)
72
+ .to receive(:user=)
73
+ .with('user')
74
+
75
+ expect(client)
76
+ .to receive(:password=)
77
+ .with('pass')
78
+
79
+ expect(client)
80
+ .to receive(:env=)
81
+ .with('dev')
82
+
83
+ expect(client)
84
+ .to receive(:dts)
85
+ .and_return(dts_mock)
86
+
87
+ expect(dts_mock)
88
+ .to receive(:download)
89
+ .with('Test Org', file_path)
90
+
91
+ expect(client)
92
+ .to receive(:logout)
93
+
94
+ run_with_args ['dts', 'download', '-e', 'dev', 'Test Org', file_path], client
95
+ end
96
+ end
97
+ end
98
+
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'command loan_entry' do
4
+
5
+ let(:page_factory) do
6
+ obj = MockPageFactory.new
7
+ end
8
+
9
+ let(:client) do
10
+ obj = mock_client(page_factory)
11
+ end
12
+
13
+ let(:le_mock) do
14
+ obj = mock_loan_entry(page_factory)
15
+ end
16
+
17
+ before do
18
+ PortalModule.configure do |config|
19
+ config.credentials[:dev] = ['user', 'pass']
20
+ config.download_dir = spec_tmp_dir('downloads')
21
+ config.orgs['Test Org'] = '1'
22
+ end
23
+ end
24
+
25
+ it "returns help info" do
26
+ output = capture_output do
27
+ run_with_args %w(help loan_entry)
28
+ end
29
+
30
+ expect( output ).to include "loan_entry help [COMMAND]"
31
+ expect( output ).to include "loan_entry upload <org> <filepath>"
32
+ expect( output ).to include "loan_entry download <org> <filepath>"
33
+ expect( output ).to include "e, [--environment=dev]"
34
+ end
35
+
36
+ context "upload" do
37
+ it "uploads a Loan Entry configuration file to the portal" do
38
+ file_path = (spec_data_dir() + 'le_upload.xml').to_s
39
+
40
+ expect(client)
41
+ .to receive(:user=)
42
+ .with('user')
43
+
44
+ expect(client)
45
+ .to receive(:password=)
46
+ .with('pass')
47
+
48
+ expect(client)
49
+ .to receive(:env=)
50
+ .with('dev')
51
+
52
+ expect(client)
53
+ .to receive(:loan_entry)
54
+ .and_return(le_mock)
55
+
56
+ expect(le_mock)
57
+ .to receive(:upload)
58
+ .with('Test Org', file_path)
59
+
60
+ expect(client)
61
+ .to receive(:logout)
62
+
63
+ run_with_args ['loan_entry', 'upload', '-e', 'dev', 'Test Org', file_path], client
64
+ end
65
+ end
66
+
67
+ context "download" do
68
+ it "downloads a Loan Entry configuration file from the portal" do
69
+ file_path = (spec_tmp_dir('loan_entry/downlod') + 'le_download.xml').to_s
70
+
71
+ expect(client)
72
+ .to receive(:user=)
73
+ .with('user')
74
+
75
+ expect(client)
76
+ .to receive(:password=)
77
+ .with('pass')
78
+
79
+ expect(client)
80
+ .to receive(:env=)
81
+ .with('dev')
82
+
83
+ expect(client)
84
+ .to receive(:loan_entry)
85
+ .and_return(le_mock)
86
+
87
+ expect(le_mock)
88
+ .to receive(:download)
89
+ .with('Test Org', file_path)
90
+
91
+ expect(client)
92
+ .to receive(:logout)
93
+
94
+ run_with_args ['loan_entry', 'download', '-e', 'dev', 'Test Org', file_path], client
95
+ end
96
+ end
97
+ end
98
+
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe PortalModule::Dts do
4
+
5
+ ##
6
+ # Copy a dummy file to the 'downloads' directory to simulate that
7
+ # a download has occurred.
8
+ #
9
+
10
+ def generate_dl_file
11
+ FileUtils.cp spec_data_dir + 'dts_import.xml', spec_tmp_dir('downloads') + '2-LatestDTS.xml'
12
+ end
13
+
14
+ context "api" do
15
+
16
+ let(:page_factory) do
17
+ obj = MockPageFactory.new
18
+ end
19
+
20
+ let(:valid_org) do
21
+ PortalModule.configure do |c|
22
+ c.orgs['Test Org'] = 1
23
+ c.download_dir = spec_tmp_dir('downloads')
24
+ end
25
+ 'Test Org'
26
+ end
27
+
28
+ let(:invalid_org) { 'Invalid Org' }
29
+
30
+ context "#save" do
31
+ it "saves the current configuration" do
32
+ expect(page_factory.dts_page)
33
+ .to receive(:save)
34
+
35
+ dts = PortalModule::Dts.new(page_factory)
36
+ dts = dts.save()
37
+ end
38
+ end
39
+
40
+ context "#activate" do
41
+ it "activates the current configuration" do
42
+ expect(page_factory.dts_page)
43
+ .to receive(:activate)
44
+
45
+ dts = PortalModule::Dts.new(page_factory)
46
+ dts = dts.activate()
47
+ end
48
+ end
49
+
50
+ context "#download" do
51
+ context "dest path dir exists" do
52
+ it "downloads a configuration" do
53
+ dest_file = spec_tmp_dir('dts') + 'export.xml'
54
+
55
+ page_obj = page_factory.dts_page
56
+ expect(page_obj)
57
+ .to receive(:load_org)
58
+ .with(valid_org)
59
+ .and_return(page_obj)
60
+
61
+ expect(page_factory.dts_page)
62
+ .to receive(:download)
63
+ .and_return(generate_dl_file)
64
+
65
+ dts = PortalModule::Dts.new(page_factory)
66
+ dts.download(valid_org, dest_file)
67
+
68
+ expect(File.exist?(dest_file)).to eq true
69
+ end
70
+ end
71
+
72
+ context "dest path does not exist" do
73
+ it "raises exception" do
74
+ dest_path = 'not/a/real/dir/export.xml'
75
+
76
+ expect(page_factory.dts_page)
77
+ .not_to receive(:load_org)
78
+
79
+ expect(page_factory.dts_page)
80
+ .not_to receive(:download)
81
+
82
+ dts = PortalModule::Dts.new(page_factory)
83
+ expect { dts.download(valid_org, dest_path) }.to raise_exception /No such directory - #{dest_path}/
84
+ end
85
+ end
86
+ end
87
+
88
+ context "#upload" do
89
+ context "file exists" do
90
+ it "uploads the DTS definition" do
91
+ src_path = spec_data_dir + 'dts_import.xml'
92
+
93
+ page_obj = page_factory.dts_page
94
+ expect(page_obj)
95
+ .to receive(:load_org)
96
+ .with(valid_org)
97
+ .and_return(page_obj)
98
+
99
+ expect(page_factory.dts_page)
100
+ .to receive(:upload)
101
+ .with(src_path)
102
+
103
+ dts = PortalModule::Dts.new(page_factory)
104
+ dts.upload(valid_org, src_path)
105
+ end
106
+ end
107
+
108
+ context "file does not exist" do
109
+ it "raises exception" do
110
+ src_path = 'not/a/real/dir/import.xml'
111
+
112
+ expect(page_factory.dts_page)
113
+ .not_to receive(:load_org)
114
+
115
+ expect(page_factory.dts_page)
116
+ .not_to receive(:upload)
117
+
118
+ dts = PortalModule::Dts.new(page_factory)
119
+ expect { dts.upload(valid_org, src_path) }.to raise_exception /File not found: #{src_path}/
120
+ end
121
+ end
122
+ end
123
+
124
+ context "#set_org" do
125
+ context "org has been configured" do
126
+ it "changes the Org Unit" do
127
+ expect(page_factory.dts_page)
128
+ .to receive(:load_org)
129
+ .with(valid_org)
130
+
131
+ dts = PortalModule::Dts.new(page_factory)
132
+ dts.set_org(valid_org)
133
+ end
134
+ end
135
+
136
+ context "org has not been configured" do
137
+ it "raises exception" do
138
+ dts = PortalModule::Dts.new(page_factory)
139
+ expect { dts.set_org(invalid_org) }.to raise_exception /Org Unit has not been configured - #{invalid_org}/
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe PortalModule::LoanEntry do
4
+
5
+ ##
6
+ # Copy a dummy file to the 'downloads' directory to simulate that
7
+ # a download has occurred.
8
+ #
9
+
10
+ def generate_dl_file
11
+ FileUtils.cp spec_data_dir + 'le_import.xml', spec_tmp_dir('downloads') + '2-LatestPrequal.xml'
12
+ end
13
+
14
+ context "api" do
15
+
16
+ let(:page_factory) do
17
+ obj = MockPageFactory.new
18
+ end
19
+
20
+ let(:valid_org) do
21
+ PortalModule.configure do |c|
22
+ c.orgs['Test Org'] = 1
23
+ c.download_dir = spec_tmp_dir('downloads')
24
+ end
25
+ 'Test Org'
26
+ end
27
+
28
+ let(:invalid_org) { 'Invalid Org' }
29
+
30
+ context "#activate" do
31
+ it "activates the current configuration" do
32
+ expect(page_factory.loan_entry_page)
33
+ .to receive(:activate)
34
+
35
+ le = PortalModule::LoanEntry.new(page_factory)
36
+ le = le.activate()
37
+ end
38
+ end
39
+
40
+ context "#download" do
41
+ context "file directory exists" do
42
+ it "downloads a loan entry definition" do
43
+ dest_file = spec_tmp_dir('loan_entry') + 'export.xml'
44
+
45
+ page = page_factory.loan_entry_page
46
+ expect(page)
47
+ .to receive(:load_org)
48
+ .with(valid_org)
49
+ .and_return(page)
50
+
51
+ expect(page)
52
+ .to receive(:download)
53
+ .and_return(generate_dl_file)
54
+
55
+ le = PortalModule::LoanEntry.new(page_factory)
56
+ le.download(valid_org, dest_file)
57
+
58
+ expect(File.exist?(dest_file)).to eq true
59
+ end
60
+ end
61
+
62
+ context "file directory does not exist" do
63
+ it "raises exception" do
64
+ dest_path = spec_tmp_dir('loan_entry') + 'not/a/real/dir/export.xml'
65
+
66
+ page = page_factory.loan_entry_page
67
+ expect(page)
68
+ .not_to receive(:load_org)
69
+
70
+ expect(page)
71
+ .not_to receive(:download)
72
+
73
+ le = PortalModule::LoanEntry.new(page_factory)
74
+ expect { le.download(valid_org, dest_path) }.to raise_exception /No such directory - #{dest_path}/
75
+ end
76
+ end
77
+ end
78
+
79
+ context "#upload" do
80
+ context "file exists" do
81
+ it "uploads loan entry definitions" do
82
+ src_file = spec_data_dir + 'le_import.xml'
83
+
84
+ page = page_factory.loan_entry_page
85
+ expect(page)
86
+ .to receive(:load_org)
87
+ .with(valid_org)
88
+ .and_return(page)
89
+
90
+ expect(page)
91
+ .to receive(:upload)
92
+ .with(src_file)
93
+
94
+ le = PortalModule::LoanEntry.new(page_factory)
95
+ le.upload valid_org, src_file
96
+ end
97
+ end
98
+
99
+ context "file does not exist" do
100
+ it "raises exception" do
101
+ src_file = spec_data_dir + 'does_not_exist.xml'
102
+
103
+ expect(page_factory.loan_entry_page)
104
+ .not_to receive(:load_org)
105
+
106
+ le = PortalModule::LoanEntry.new(page_factory)
107
+ expect { le.upload(valid_org, src_file) }.to raise_exception /File not found: #{src_file}/
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+