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
data/bin/portal_module ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # Exit cleanly from an early interrupt
5
+ Signal.trap("INT") { exit 1 }
6
+
7
+ require 'portal_module'
8
+
9
+ PortalModule::Runner.new(ARGV.dup).execute!
10
+
@@ -0,0 +1,37 @@
1
+ ##############################################################################
2
+ # File:: assertable.rb
3
+ # Purpose:: Useful assertions
4
+ #
5
+ # Author:: Jeff McAffee 03/28/2015
6
+ ##############################################################################
7
+
8
+
9
+ module Assertable
10
+
11
+ # ConfigurationError Asserts
12
+ #
13
+ def assert_org_is_configured org
14
+ unless PortalModule.configuration.orgs.key?(org)
15
+ raise ConfigurationError, "Org Unit has not been configured - #{org}"
16
+ end
17
+ end
18
+
19
+ def assert_dl_dir_is_configured
20
+ dd = PortalModule.configuration.download_dir
21
+ if (dd.nil? || dd.to_s.empty?)
22
+ raise ConfigurationError, "Download directory has not been configured"
23
+ end
24
+ end
25
+
26
+ # File System Asserts
27
+ def assert_dir_exists path
28
+ path = Pathname(path)
29
+ dir = path.dirname
30
+ raise IOError, "No such directory - #{path}" unless dir.exist?
31
+ end
32
+
33
+ def assert_file_exists path
34
+ path = Pathname(path)
35
+ raise IOError, "File not found: #{path}" unless path.exist? && !path.directory?
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ ##############################################################################
2
+ # File:: cli.rb
3
+ # Purpose:: Portal Module command line interface
4
+ #
5
+ # Author:: Jeff McAffee 2015-03-27
6
+ ##############################################################################
7
+
8
+ require 'thor'
9
+ require 'portal_module/command'
10
+
11
+
12
+ module PortalModule
13
+ class CLI < Thor
14
+
15
+ def self.start(*)
16
+ super
17
+ rescue Exception => e
18
+ raise e
19
+ end
20
+
21
+ def initialize(*args)
22
+ super
23
+ end
24
+
25
+ desc "config [COMMAND]", "modify configuration values"
26
+ subcommand "config", PortalModule::Command::Config
27
+
28
+ desc "dts [COMMAND]", "run a dts command"
29
+ subcommand "dts", PortalModule::Command::Dts
30
+
31
+ desc "loan_entry [COMMAND]", "run a Loan Entry command"
32
+ subcommand "loan_entry", PortalModule::Command::LoanEntry
33
+ end # CLI
34
+ end # PortalModule
35
+
@@ -0,0 +1,110 @@
1
+ ##############################################################################
2
+ # File:: client.rb
3
+ # Purpose:: PortalModule client object
4
+ #
5
+ # Author:: Jeff McAffee 2015-03-27
6
+ ##############################################################################
7
+
8
+ module PortalModule
9
+ class Client
10
+
11
+ attr_writer :page_factory
12
+
13
+ #
14
+ # Override credentials
15
+ #
16
+
17
+ attr_writer :user
18
+ attr_writer :password
19
+
20
+ def env=(environment)
21
+ PortalModule.configuration.current_env = environment
22
+ end
23
+
24
+ def env
25
+ PortalModule.configuration.current_env
26
+ end
27
+
28
+ def loan_entry
29
+ login
30
+ LoanEntry.new page_factory
31
+ end
32
+
33
+ def dts
34
+ login
35
+ Dts.new page_factory
36
+ end
37
+
38
+ def page_factory
39
+ @page_factory ||= PortalModule::PageFactory.new
40
+ end
41
+
42
+ ##
43
+ # Login to the portal
44
+ #
45
+ # If no credentials are provided, try to get credentials from the config object.
46
+ #
47
+
48
+ def login(user = nil, pass = nil)
49
+ if @logged_in
50
+ return true
51
+ end
52
+
53
+ user, pass = verify_credentials user, pass
54
+
55
+ logout
56
+ page_factory.login_page(true).login_as(user, pass)
57
+ @logged_in = true
58
+ end
59
+
60
+ ##
61
+ # Logout of the portal
62
+ #
63
+
64
+ def logout
65
+ page_factory.login_page(true).logout
66
+ @logged_in = false
67
+ end
68
+
69
+ ##
70
+ # Logout of the portal and quit the browser
71
+ #
72
+
73
+ def quit
74
+ logout
75
+ page_factory.login_page(false).browser.close
76
+ end
77
+
78
+ private
79
+
80
+ ##
81
+ # If credential args are empty, attempt to look them up,
82
+ # first in the client attributes, then in the config obj.
83
+
84
+ def verify_credentials user, pass
85
+ return [user, pass] if valid_user_and_pass? user, pass
86
+
87
+ # Pull values stored in this client.
88
+ user, pass = @user, @password
89
+ return [user, pass] if valid_user_and_pass? user, pass
90
+
91
+ # Pull values stored in the config.
92
+ user, pass = PortalModule.configuration.user_credentials
93
+ return [user, pass] if valid_user_and_pass? user, pass
94
+
95
+ fail AuthenticationRequired.new("Missing credentials for #{env}")
96
+ end
97
+
98
+ def valid_user_and_pass? user, pass
99
+ if user.nil? || user.empty?
100
+ return false
101
+ end
102
+
103
+ if pass.nil? || pass.empty?
104
+ return false
105
+ end
106
+
107
+ true
108
+ end
109
+ end # Client
110
+ end # PortalModule
@@ -0,0 +1,41 @@
1
+ ##############################################################################
2
+ # File:: client_access.rb
3
+ # Purpose:: Module providing client access helper methods for CLI classes.
4
+ #
5
+ # Author:: Jeff McAffee 2015-03-27
6
+ ##############################################################################
7
+
8
+ module PortalModule
9
+ module Command
10
+ module ClientAccess
11
+ private def credentials
12
+ config = PortalModule.configuration
13
+ user, pass = config.user_credentials
14
+ if user.nil? || pass.nil?
15
+ user = ask "username for #{config.current_env} environment:"
16
+ pass = ask "password:", echo: false
17
+ # Force a new line - hiding the echo on the password eats the new line.
18
+ say "\n"
19
+ end
20
+ [user, pass]
21
+ end
22
+
23
+ private def client
24
+ return @client unless @client.nil?
25
+
26
+ @client = PortalModule.client
27
+ @client.env = options[:environment] unless options[:environment].nil?
28
+
29
+ user, pass = credentials
30
+ if user.empty? || pass.empty?
31
+ say "missing credentials", :red
32
+ return
33
+ end
34
+
35
+ @client.user = user
36
+ @client.password = pass
37
+ @client
38
+ end
39
+ end # ClientAccess
40
+ end # Command
41
+ end # PortalModule
@@ -0,0 +1,323 @@
1
+ ##############################################################################
2
+ # File:: config.rb
3
+ # Purpose:: Config command
4
+ #
5
+ # Author:: Jeff McAffee 2015-03-27
6
+ ##############################################################################
7
+
8
+ module PortalModule
9
+ module Command
10
+ class Config < Thor
11
+
12
+ ###
13
+ # Add commands
14
+ #
15
+
16
+ class Add < Thor
17
+
18
+ desc "env <envname> <url>", "add a environment url"
19
+ def env(envname, url)
20
+ with_loaded_config do
21
+ unless PortalModule.configuration.base_urls.key? envname.to_sym
22
+ PortalModule.configuration.base_urls[envname.to_sym] = url
23
+ else
24
+ say "environment '#{envname}' already exists", :red
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "org <orgname> <orgid>", "add an Org Unit and ID"
30
+ def org(orgname, orgid)
31
+ with_loaded_config do
32
+ unless PortalModule.configuration.orgs.key? orgname
33
+ PortalModule.configuration.orgs[orgname] = orgid
34
+ else
35
+ say "org unit '#{orgname}' already exists", :red
36
+ end
37
+ end
38
+ end
39
+
40
+ desc "credentials <envname> <username> <pass>", "add login credentials for an environment"
41
+ def credentials(envname, username, pass)
42
+ with_loaded_config do
43
+ if PortalModule.configuration.base_urls.key? envname.to_sym
44
+ unless PortalModule.configuration.credentials.key? envname.to_sym
45
+ PortalModule.configuration.credentials[envname.to_sym] = [username, pass]
46
+ else
47
+ say "credentials already exist for environment '#{envname}'", :red
48
+ end
49
+ else
50
+ say "environment '#{envname}' doesn't exist", :red
51
+ say "create environment before adding credentials"
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def with_loaded_config &block
59
+ fail "expecting block" unless block_given?
60
+
61
+ unless PortalModule.load_configuration
62
+ say "Configuration file not found!", :red
63
+ say "Have you tried 'config init' first?"
64
+ return
65
+ end
66
+
67
+ yield
68
+
69
+ PortalModule.save_configuration
70
+ end
71
+ end
72
+
73
+ desc "add [CATEGORY]", "add a configuration value"
74
+ subcommand "add", Add
75
+
76
+ ###
77
+ # Show commands
78
+ #
79
+
80
+ class Show < Thor
81
+
82
+ desc "envs", "display configured environments"
83
+ def envs
84
+ with_loaded_config do
85
+ say "Environments:"
86
+
87
+ output = []
88
+ PortalModule.configuration.base_urls.each do |env, url|
89
+ output << [env, url]
90
+ end
91
+ print_table output, indent: 8
92
+ end
93
+ end
94
+
95
+ desc "orgs", "display configured Org Units"
96
+ def orgs
97
+ with_loaded_config do
98
+ say "Org Units:"
99
+
100
+ output = []
101
+ PortalModule.configuration.orgs.each do |org, id|
102
+ output << [org, id]
103
+ end
104
+ print_table output, indent: 8
105
+ end
106
+ end
107
+
108
+ desc "credentials <envname>", "display configured credentials for an environment"
109
+ long_desc <<-LD
110
+ Display configured credentials for an environment.
111
+
112
+ If an environment name is not provided, credentials for all
113
+ environments will be displayed.
114
+ LD
115
+ def credentials(envname=nil)
116
+ with_loaded_config do
117
+ say "credentials:"
118
+
119
+ output = []
120
+ PortalModule.configuration.credentials.each do |env, cred|
121
+ if envname.nil? || env == envname.to_sym
122
+ output << [env, cred.first, cred.last]
123
+ end
124
+ end
125
+ print_table output, indent: 8
126
+ end
127
+ end
128
+
129
+ private
130
+
131
+ def with_loaded_config &block
132
+ fail "expecting block" unless block_given?
133
+
134
+ unless PortalModule.load_configuration
135
+ say "Configuration file not found!", :red
136
+ say "Have you tried 'config init' first?"
137
+ return
138
+ end
139
+
140
+ yield
141
+ end
142
+ end
143
+
144
+ desc "show [CATEGORY]", "display configuration values for [CATEGORY]"
145
+ subcommand "show", Show
146
+
147
+ ###
148
+ # Del commands
149
+ #
150
+
151
+ class Del < Thor
152
+
153
+ desc "env <envname>", "delete an environment configuration"
154
+ def env(envname)
155
+ with_loaded_config do
156
+ if PortalModule.configuration.base_urls.key?(envname.to_sym)
157
+ PortalModule.configuration.base_urls.delete(envname.to_sym)
158
+ end
159
+ end
160
+
161
+ credentials(envname)
162
+ end
163
+
164
+ desc "org <orgname>", "delete an Org Unit"
165
+ def org(orgname)
166
+ with_loaded_config do
167
+ if PortalModule.configuration.orgs.key?(orgname)
168
+ PortalModule.configuration.orgs.delete(orgname)
169
+ end
170
+ end
171
+ end
172
+
173
+ desc "credentials <envname>", "delete credentials for an environment"
174
+ def credentials(envname)
175
+ with_loaded_config do
176
+ if PortalModule.configuration.credentials.key?(envname.to_sym)
177
+ PortalModule.configuration.credentials.delete(envname.to_sym)
178
+ end
179
+ end
180
+ end
181
+
182
+ private
183
+
184
+ def with_loaded_config &block
185
+ fail "expecting block" unless block_given?
186
+
187
+ unless PortalModule.load_configuration
188
+ say "Configuration file not found!", :red
189
+ say "Have you tried 'config init' first?"
190
+ return
191
+ end
192
+
193
+ yield
194
+
195
+ PortalModule.save_configuration
196
+ end
197
+ end
198
+
199
+ desc "del [CATEGORY]", "delete a configuration value for [CATEGORY]"
200
+ subcommand "del", Del
201
+
202
+ ###
203
+ # init command
204
+ #
205
+
206
+ desc "init <filedir>", "create a configuration file"
207
+ long_desc <<-LD
208
+ Initialize and write a configuration file to disk.
209
+
210
+ If <filedir> is provided, config file will be written to the
211
+ given directory.
212
+
213
+ If <filedir> is not given, the configuration file will be
214
+ written to the current working directory.
215
+
216
+ If you do not yet have a configuration file, this command
217
+ should be run before any other modifications so your config
218
+ changes are safely stored.
219
+ LD
220
+ option :quiet, :type => :boolean, :default => false, :aliases => :q
221
+ def init(filedir = nil)
222
+ outpath = PortalModule.save_configuration filedir
223
+ say("configuration written to #{outpath.to_s}", :green) unless options[:quiet]
224
+ end
225
+
226
+ ###
227
+ # timeout command
228
+ #
229
+
230
+ desc "timeout <seconds>", "show or set the browser timeout period"
231
+ long_desc <<-LD
232
+ Show or set the browser timeout period.
233
+ Default value is 360.
234
+
235
+ If <seconds> is not provided, display the current setting.
236
+
237
+ <seconds> must be an integer value.
238
+ LD
239
+ def timeout(seconds=nil)
240
+ if seconds.nil?
241
+ with_loaded_config do
242
+ say "browser timeout: #{PortalModule.configuration.browser_timeout}"
243
+ end
244
+ else
245
+ seconds = Integer(seconds)
246
+ with_loaded_config(true) do
247
+ PortalModule.configuration.browser_timeout = seconds
248
+ end
249
+ end
250
+ rescue ArgumentError => e
251
+ say 'argument error: seconds must be an integer', :red
252
+ end
253
+
254
+ ###
255
+ # defenv command
256
+ #
257
+
258
+ desc "defenv <envname>", "show or set the default environment"
259
+ long_desc <<-LD
260
+ Show or set the default environment.
261
+
262
+ If <envname> is not provided, display the current setting.
263
+
264
+ <envname> must be an existing environment.
265
+ LD
266
+ def defenv(envname=nil)
267
+ if envname.nil?
268
+ with_loaded_config do
269
+ say "default environment: #{PortalModule.configuration.default_environment}"
270
+ end
271
+ return
272
+ end
273
+
274
+ with_loaded_config(true) do
275
+ if PortalModule.configuration.base_urls.key? envname.to_sym
276
+ PortalModule.configuration.default_environment = envname.to_sym
277
+ else
278
+ say "argument error: environment '#{envname}' has not been configured", :red
279
+ end
280
+ end
281
+ end
282
+
283
+ ###
284
+ # download_dir command
285
+ #
286
+
287
+ desc "download_dir <dir>", "show or set the system download directory"
288
+ long_desc <<-LD
289
+ Show or set the system download directory.
290
+
291
+ If <dir> is not provided, display the current setting.
292
+ LD
293
+ def download_dir(dir=nil)
294
+ if dir.nil?
295
+ with_loaded_config do
296
+ say "download dir: #{PortalModule.configuration.download_dir}"
297
+ end
298
+ return
299
+ end
300
+
301
+ with_loaded_config(true) do
302
+ PortalModule.configuration.download_dir = dir
303
+ end
304
+ end
305
+
306
+ private
307
+
308
+ def with_loaded_config save = false
309
+ fail "expecting block" unless block_given?
310
+
311
+ unless PortalModule.load_configuration
312
+ say "Configuration file not found!", :red
313
+ say "Have you tried 'config init' first?"
314
+ return
315
+ end
316
+
317
+ yield
318
+
319
+ PortalModule.save_configuration if save
320
+ end
321
+ end # Config
322
+ end # Command
323
+ end # PortalModule