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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +240 -0
- data/Rakefile +101 -0
- data/bin/portal_module +10 -0
- data/lib/portal_module/assertable.rb +37 -0
- data/lib/portal_module/cli.rb +35 -0
- data/lib/portal_module/client.rb +110 -0
- data/lib/portal_module/command/client_access.rb +41 -0
- data/lib/portal_module/command/config.rb +323 -0
- data/lib/portal_module/command/dts.rb +70 -0
- data/lib/portal_module/command/loan_entry.rb +66 -0
- data/lib/portal_module/command.rb +16 -0
- data/lib/portal_module/config_helper.rb +32 -0
- data/lib/portal_module/dts.rb +99 -0
- data/lib/portal_module/loan_entry.rb +101 -0
- data/lib/portal_module/page_factory.rb +27 -0
- data/lib/portal_module/pages/data_transformation_page.rb +84 -0
- data/lib/portal_module/pages/login_page.rb +73 -0
- data/lib/portal_module/pages/prequal_setup_page.rb +77 -0
- data/lib/portal_module/pages.rb +90 -0
- data/lib/portal_module/rake/dts_tasks.rb +166 -0
- data/lib/portal_module/rake/loan_entry_tasks.rb +166 -0
- data/lib/portal_module/rake.rb +16 -0
- data/lib/portal_module/version.rb +3 -0
- data/lib/portal_module.rb +251 -0
- data/portal_module.gemspec +33 -0
- data/spec/data/dts_import.xml +1 -0
- data/spec/data/le_import.xml +1 -0
- data/spec/lib/portal_module/cli_spec.rb +35 -0
- data/spec/lib/portal_module/client_spec.rb +126 -0
- data/spec/lib/portal_module/command/config_spec.rb +474 -0
- data/spec/lib/portal_module/command/dts_spec.rb +98 -0
- data/spec/lib/portal_module/command/loan_entry_spec.rb +98 -0
- data/spec/lib/portal_module/dts_spec.rb +145 -0
- data/spec/lib/portal_module/loan_entry_spec.rb +113 -0
- data/spec/lib/portal_module_spec.rb +175 -0
- data/spec/spec_helper.rb +52 -0
- data/spec/support/asserts.rb +10 -0
- data/spec/support/dirs.rb +53 -0
- data/spec/support/helpers.rb +44 -0
- data/spec/support/mocks.rb +106 -0
- metadata +247 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: rake.rb
|
3
|
+
# Purpose:: Pull in all rake task classes
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 2015-03-29
|
6
|
+
#
|
7
|
+
##############################################################################
|
8
|
+
|
9
|
+
require 'portal_module'
|
10
|
+
|
11
|
+
module PortalModule::Rake
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative 'rake/dts_tasks'
|
15
|
+
require_relative 'rake/loan_entry_tasks'
|
16
|
+
|
@@ -0,0 +1,251 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require "portal_module/version"
|
5
|
+
require 'portal_module/config_helper'
|
6
|
+
require "portal_module/cli"
|
7
|
+
require 'portal_module/page_factory'
|
8
|
+
require 'portal_module/pages'
|
9
|
+
require 'portal_module/loan_entry'
|
10
|
+
require 'portal_module/dts'
|
11
|
+
require 'portal_module/client'
|
12
|
+
|
13
|
+
if ENV['DEBUG'].nil?
|
14
|
+
$debug = false
|
15
|
+
else
|
16
|
+
$debug = true
|
17
|
+
end
|
18
|
+
|
19
|
+
class AuthenticationRequired < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
class ConfigurationError < StandardError; end
|
23
|
+
|
24
|
+
module PortalModule
|
25
|
+
CONFIG_FILE_NAME = '.portal_module'
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_accessor :configuration
|
29
|
+
attr_accessor :client
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Setup portal_module configuration
|
34
|
+
#
|
35
|
+
# Attempts to find and load a configuration file the first time
|
36
|
+
# it's requested. If a config file cannot be found on in the current
|
37
|
+
# directory tree (moving towards trunk, not the leaves), a default
|
38
|
+
# configuration object is created.
|
39
|
+
#
|
40
|
+
# If a block is provided, the configuration object is yielded to the block
|
41
|
+
# after the configuration is loaded/created.
|
42
|
+
#
|
43
|
+
|
44
|
+
def self.configure
|
45
|
+
if self.configuration.nil?
|
46
|
+
unless self.load_configuration
|
47
|
+
self.configuration = Configuration.new
|
48
|
+
end
|
49
|
+
end
|
50
|
+
yield(configuration) if block_given?
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Walk up the directory tree from current working dir (pwd) till a file
|
55
|
+
# named .portal_module is found
|
56
|
+
#
|
57
|
+
# Returns file path if found, nil if not.
|
58
|
+
#
|
59
|
+
|
60
|
+
def self.find_config_path
|
61
|
+
path = Pathname(Pathname.pwd).ascend{|d| h=d+CONFIG_FILE_NAME; break h if h.file?}
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Write configuration to disk
|
66
|
+
#
|
67
|
+
# Writes to current working dir (pwd) if path is nil
|
68
|
+
#
|
69
|
+
# Returns path of emitted file
|
70
|
+
#
|
71
|
+
|
72
|
+
def self.save_configuration(path = nil)
|
73
|
+
# If no path provided, see if we can find one in the dir tree.
|
74
|
+
if path.nil?
|
75
|
+
path = find_config_path
|
76
|
+
end
|
77
|
+
|
78
|
+
# Still no path? Use the current working dir.
|
79
|
+
if path.nil?
|
80
|
+
path = Pathname.pwd
|
81
|
+
end
|
82
|
+
|
83
|
+
unless path.to_s.end_with?('/' + CONFIG_FILE_NAME)
|
84
|
+
path = Pathname(path) + CONFIG_FILE_NAME
|
85
|
+
end
|
86
|
+
|
87
|
+
path = Pathname(path).expand_path
|
88
|
+
File.write(path, YAML.dump(configuration))
|
89
|
+
|
90
|
+
path
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Load the configuration from disk
|
95
|
+
#
|
96
|
+
# Returns true if config file found and loaded, false otherwise.
|
97
|
+
#
|
98
|
+
|
99
|
+
def self.load_configuration(path = nil)
|
100
|
+
# If no path provided, see if we can find one in the dir tree.
|
101
|
+
if path.nil?
|
102
|
+
path = find_config_path
|
103
|
+
end
|
104
|
+
|
105
|
+
return false if path.nil?
|
106
|
+
return false unless Pathname(path).exist?
|
107
|
+
|
108
|
+
File.open(path, 'r') do |f|
|
109
|
+
self.configuration = YAML.load(f)
|
110
|
+
puts "configuration loaded from #{path}" if $debug
|
111
|
+
end
|
112
|
+
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
class Configuration
|
117
|
+
attr_accessor :default_environment
|
118
|
+
attr_accessor :credentials
|
119
|
+
attr_accessor :base_urls
|
120
|
+
attr_accessor :page_urls
|
121
|
+
|
122
|
+
# Browser timeout in seconds. Default: 360 (6 mins).
|
123
|
+
attr_accessor :browser_timeout
|
124
|
+
|
125
|
+
attr_accessor :orgs
|
126
|
+
attr_reader :download_dir
|
127
|
+
attr_accessor :download_timeout
|
128
|
+
|
129
|
+
|
130
|
+
def initialize
|
131
|
+
reset
|
132
|
+
end
|
133
|
+
|
134
|
+
def reset
|
135
|
+
@default_environment = :dev
|
136
|
+
@current_env = nil
|
137
|
+
|
138
|
+
@credentials = {}
|
139
|
+
#@credentials = { dev: [ ENV['DEV_USER'], ENV['DEV_PASSWORD'] ],
|
140
|
+
# }
|
141
|
+
|
142
|
+
@base_urls = {}
|
143
|
+
#@base_urls = { dev: "http://example.com/Portal",
|
144
|
+
# }
|
145
|
+
|
146
|
+
@page_urls = { 'DataTransformationPage' => "/Admin/DataTransformation.aspx",
|
147
|
+
'PrequalSetupPage' => "/Admin/PrequalSetup.aspx",
|
148
|
+
}
|
149
|
+
|
150
|
+
@browser_timeout = 360
|
151
|
+
|
152
|
+
@orgs = {}
|
153
|
+
|
154
|
+
@download_dir = ''
|
155
|
+
@download_timeout = 360
|
156
|
+
end
|
157
|
+
|
158
|
+
##
|
159
|
+
# Set the current environment.
|
160
|
+
#
|
161
|
+
|
162
|
+
def current_env=(env)
|
163
|
+
env = env.to_sym
|
164
|
+
|
165
|
+
fail "Cannot set current_env to un-configured environment: #{env}" unless @base_urls.key? env
|
166
|
+
|
167
|
+
# This value is NOT included when dumping to YAML.
|
168
|
+
# See Configurtion#encode_with
|
169
|
+
@current_env = env.to_sym
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Return the current environment.
|
174
|
+
# Will return the default environment if current environment is not set.
|
175
|
+
#
|
176
|
+
|
177
|
+
def current_env
|
178
|
+
return @default_environment if @current_env.nil?
|
179
|
+
@current_env
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Set the download directory for the system
|
184
|
+
#
|
185
|
+
|
186
|
+
def download_dir=(dir)
|
187
|
+
@download_dir = String(dir)
|
188
|
+
end
|
189
|
+
|
190
|
+
def base_url
|
191
|
+
@base_urls[current_env]
|
192
|
+
end
|
193
|
+
|
194
|
+
def url page_class
|
195
|
+
suffix = @page_urls[page_class.to_s.split('::').last]
|
196
|
+
raise "Unkown page [#{page_class.to_s}]" if suffix.nil?
|
197
|
+
base_url + suffix
|
198
|
+
end
|
199
|
+
|
200
|
+
def user_credentials
|
201
|
+
@credentials[current_env]
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# Control which instance vars are emitted when dumped to YAML.
|
206
|
+
#
|
207
|
+
|
208
|
+
def encode_with(coder)
|
209
|
+
vars = instance_variables.map { |x| x.to_s }
|
210
|
+
vars = vars - ["@current_env"]
|
211
|
+
|
212
|
+
vars.each do |var|
|
213
|
+
var_val = eval(var)
|
214
|
+
coder[var.gsub('@', '')] = var_val
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end # Configuration
|
218
|
+
|
219
|
+
|
220
|
+
class Runner
|
221
|
+
def initialize(argv, client = PortalModule::Client.new, exit_code = true)
|
222
|
+
@argv = argv
|
223
|
+
PortalModule.client = client
|
224
|
+
@exit_code = exit_code
|
225
|
+
end
|
226
|
+
|
227
|
+
def execute!
|
228
|
+
exit_code = begin
|
229
|
+
|
230
|
+
# Run the Thor app
|
231
|
+
PortalModule::CLI.start(@argv)
|
232
|
+
|
233
|
+
# Thor::Base#start does not have a return value,
|
234
|
+
# assume success if no exception is thrown.
|
235
|
+
0
|
236
|
+
rescue StandardError => e
|
237
|
+
b = e.backtrace
|
238
|
+
b.unshift("#{b.shift}: #{e.message} (#{e.class})")
|
239
|
+
puts(b.map { |s| "\tfrom #{s}"}.join("\n"))
|
240
|
+
1
|
241
|
+
end
|
242
|
+
|
243
|
+
# Return the exit code
|
244
|
+
exit(exit_code) if @exit_code
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Call configure to force creation of the configuration object.
|
250
|
+
PortalModule.configure
|
251
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'portal_module/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "portal_module"
|
8
|
+
spec.version = PortalModule::VERSION
|
9
|
+
spec.authors = ["Jeff McAffee"]
|
10
|
+
spec.email = ["jeff@ktechsystems.com"]
|
11
|
+
spec.summary = %q{Portal Module CLI}
|
12
|
+
spec.description = %q{Command line interface for Portal Module}
|
13
|
+
spec.homepage = "https://github.com/jmcaffee/portal_module"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "cucumber", "~> 1.3.9"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
#spec.add_development_dependency "pry-byebug", "~> 1.3.3"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "nokogiri"
|
30
|
+
spec.add_runtime_dependency "page-object"
|
31
|
+
spec.add_runtime_dependency "thor"
|
32
|
+
spec.add_runtime_dependency "ktutils"
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dummy data
|
@@ -0,0 +1 @@
|
|
1
|
+
Dummy data
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).ascend{|d| h=d+'spec_helper.rb'; break h if h.file?}
|
3
|
+
|
4
|
+
require 'portal_module/cli'
|
5
|
+
|
6
|
+
describe 'portal_module executable' do
|
7
|
+
|
8
|
+
let(:cli) { PortalModule::CLI }
|
9
|
+
|
10
|
+
it "returns help info" do
|
11
|
+
output = capture_output do
|
12
|
+
cli.start %w(help)
|
13
|
+
end
|
14
|
+
|
15
|
+
expect( output ).to include "help [COMMAND]"
|
16
|
+
expect( output ).to include "config [COMMAND]"
|
17
|
+
expect( output ).to include "dts [COMMAND]"
|
18
|
+
expect( output ).to include "loan_entry [COMMAND]"
|
19
|
+
end
|
20
|
+
|
21
|
+
=begin
|
22
|
+
it "returns non-zero exit status when passed unrecognized options" do
|
23
|
+
pending
|
24
|
+
#portal_module '--invalid_argument', :exitstatus => true
|
25
|
+
portal_module '--invalid_argument'
|
26
|
+
expect(exitstatus).to_not be_zero
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns non-zero exit status when passed unrecognized task" do
|
30
|
+
pending
|
31
|
+
portal_module 'unrecognized-task'#, :exitstatus => true
|
32
|
+
expect(exitstatus).to_not be_zero
|
33
|
+
end
|
34
|
+
=end
|
35
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PortalModule::Client do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
PortalModule.configure do |config|
|
7
|
+
config.reset
|
8
|
+
config.credentials[:dev] = ['devuser', 'devpass']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:client) do
|
13
|
+
obj = PortalModule::Client.new
|
14
|
+
obj.page_factory = mock_page_factory
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:login_page) { client.page_factory.login_page }
|
19
|
+
|
20
|
+
context "#env=" do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
PortalModule.configure do |config|
|
24
|
+
config.reset
|
25
|
+
config.credentials[:sit] = ['user', 'pass']
|
26
|
+
config.base_urls[:sit] = 'http://example.com/Portal'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets environment to use" do
|
31
|
+
expect{ client.env = 'sit' }.to_not raise_exception
|
32
|
+
expect( client.env ).to eq :sit
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raises exception if environment is not configured" do
|
36
|
+
expect{ client.env = :test }.to raise_exception
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#env" do
|
41
|
+
it "returns default environment if not set" do
|
42
|
+
expect( client.env ).to eq PortalModule.configuration.default_environment
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#dts" do
|
47
|
+
it "logs into the current env and returns a pre-configured Dts object" do
|
48
|
+
|
49
|
+
expect(login_page)
|
50
|
+
.to receive(:login_as)
|
51
|
+
.with('testuser', 'testpass')
|
52
|
+
|
53
|
+
client.user = 'testuser'
|
54
|
+
client.password = 'testpass'
|
55
|
+
|
56
|
+
expect( client.dts ).to_not be nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#loan_entry" do
|
61
|
+
it "logs into the current env and returns a pre-configured LoanEntry object" do
|
62
|
+
|
63
|
+
expect(login_page)
|
64
|
+
.to receive(:login_as)
|
65
|
+
.with('testuser', 'testpass')
|
66
|
+
|
67
|
+
client.user = 'testuser'
|
68
|
+
client.password = 'testpass'
|
69
|
+
|
70
|
+
expect( client.loan_entry ).to_not be nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "#login" do
|
75
|
+
context "credentials not passed" do
|
76
|
+
|
77
|
+
before(:each) do
|
78
|
+
PortalModule.configure do |config|
|
79
|
+
config.reset
|
80
|
+
config.credentials[:dev] = ['devuser', 'devpass']
|
81
|
+
config.base_urls[:dev] = 'http://example.com/Portal'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:client) do
|
86
|
+
obj = PortalModule::Client.new
|
87
|
+
obj.page_factory = mock_page_factory
|
88
|
+
obj
|
89
|
+
end
|
90
|
+
|
91
|
+
it "uses credentials from configuration data" do
|
92
|
+
expect(login_page)
|
93
|
+
.to receive(:login_as)
|
94
|
+
.with('devuser', 'devpass')
|
95
|
+
|
96
|
+
client.env = :dev
|
97
|
+
client.login
|
98
|
+
end
|
99
|
+
|
100
|
+
it "credentials set on client override configuration data credentials" do
|
101
|
+
expect(login_page)
|
102
|
+
.to receive(:login_as)
|
103
|
+
.with('clientuser', 'clientpass')
|
104
|
+
|
105
|
+
client.env = :dev
|
106
|
+
client.user = 'clientuser'
|
107
|
+
client.password = 'clientpass'
|
108
|
+
client.login
|
109
|
+
end
|
110
|
+
|
111
|
+
it "raises AuthenticationRequired when no credentials are available" do
|
112
|
+
PortalModule.configure do |config|
|
113
|
+
config.credentials.delete :dev
|
114
|
+
end
|
115
|
+
|
116
|
+
client.env = :dev
|
117
|
+
client.user = nil
|
118
|
+
client.password = nil
|
119
|
+
|
120
|
+
expect{ client.login }.to raise_exception AuthenticationRequired
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|