prestashop-automation-tool 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pat +108 -0
- data/bin/pat-runner-invoice.rb +110 -0
- data/lib/prestashop-automation-tool.rb +9 -4
- data/lib/prestashop-automation-tool/helper.rb +20 -0
- data/lib/templates/sample_test.rb +7 -0
- metadata +7 -3
- data/bin/pat.rb +0 -38
data/bin/pat
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'prestashop-automation-tool'
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
def withConfig &block
|
8
|
+
if File.exists? 'pat.conf.json'
|
9
|
+
yield JSON.parse(File.read('pat.conf.json'), :symbolize_names => true)
|
10
|
+
else
|
11
|
+
abort "Could not find the config file #{pat.conf.json}, did you run 'pat.rb init'?"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.on('-ad', '--accept-defaults', 'Accept default values automatically.') do
|
18
|
+
options[:accept_defaults] = true
|
19
|
+
end
|
20
|
+
opts.on('--no-restore', 'Do not save/restore intial state when running tests.') do
|
21
|
+
options[:no_restore] = true
|
22
|
+
end
|
23
|
+
end.parse!
|
24
|
+
if ARGV.count == 0
|
25
|
+
puts "Missing action argument!"
|
26
|
+
exit 1
|
27
|
+
elsif ARGV[0] == 'init'
|
28
|
+
conf = PrestaShopAutomationTool::ConfigurationParser.new '.'
|
29
|
+
conf.parse
|
30
|
+
conf.ask_user_for_missing_info options
|
31
|
+
conf.autocomplete_config
|
32
|
+
File.write 'pat.conf.json', JSON.pretty_generate({
|
33
|
+
shop: conf.config
|
34
|
+
})
|
35
|
+
unless File.exists? 'tests-enabled'
|
36
|
+
Dir.mkdir 'tests-enabled'
|
37
|
+
end
|
38
|
+
unless File.exists? 'tests-available'
|
39
|
+
`git clone #{conf.config[:tests_repository]} tests-available`
|
40
|
+
end
|
41
|
+
elsif ARGV[0] == 'purge'
|
42
|
+
`rm -Rf pat.conf.json tests-enabled tests-available`
|
43
|
+
elsif ARGV[0] == 'install'
|
44
|
+
withConfig do |conf|
|
45
|
+
ps = PrestaShopAutomation::PrestaShop.new(conf[:shop])
|
46
|
+
ps.drop_database
|
47
|
+
ps.install options
|
48
|
+
end
|
49
|
+
elsif ARGV[0] == 'create'
|
50
|
+
if ARGV[1]
|
51
|
+
template = File.join PrestaShopAutomationTool.gem_root, 'lib', 'templates', 'sample_test.rb'
|
52
|
+
`cp #{template} tests-enabled/#{ARGV[1]}.rb`
|
53
|
+
else
|
54
|
+
puts 'Please provide the name of the test to create!'
|
55
|
+
end
|
56
|
+
elsif ARGV[0] == 'dump'
|
57
|
+
withConfig do |conf|
|
58
|
+
ps = PrestaShopAutomation::PrestaShop.new(conf[:shop])
|
59
|
+
ps.dump_database 'dump.sql'
|
60
|
+
end
|
61
|
+
elsif ARGV[0] == 'restore'
|
62
|
+
withConfig do |conf|
|
63
|
+
ps = PrestaShopAutomation::PrestaShop.new(conf[:shop])
|
64
|
+
ps.load_database 'dump.sql'
|
65
|
+
end
|
66
|
+
elsif ARGV[0] == 'test'
|
67
|
+
|
68
|
+
list = ARGV[1..-1]
|
69
|
+
|
70
|
+
if list.nil? or list.empty?
|
71
|
+
list = Dir.glob('tests-enabled/**/*')
|
72
|
+
end
|
73
|
+
|
74
|
+
list.sort!
|
75
|
+
|
76
|
+
list.each do |file|
|
77
|
+
ok = if file =~ /\.rb$/
|
78
|
+
puts "Running #{file}..."
|
79
|
+
system({'NO_RESTORE' => options[:no_restore]}, 'rspec', file)
|
80
|
+
elsif file =~ /\.json$/
|
81
|
+
puts "Running #{file}..."
|
82
|
+
data = JSON.parse File.read(file)
|
83
|
+
runner = "pat-runner-#{data['spec']['runner']}.rb"
|
84
|
+
system({'PAT_SOURCE' => file, 'NO_RESTORE' => (options[:no_restore] ? '1' : '0')}, runner)
|
85
|
+
else
|
86
|
+
:not_runnable
|
87
|
+
end
|
88
|
+
|
89
|
+
if ok != :not_runnable
|
90
|
+
puts "Ran #{file}: #{ok ? "success!" : "FAILED"}"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
elsif ARGV[0] == 'enable'
|
95
|
+
if ARGV[1]
|
96
|
+
`cp tests-available/#{ARGV[1]}.* tests-enabled/`
|
97
|
+
else
|
98
|
+
puts "Please also provide prefix!"
|
99
|
+
end
|
100
|
+
elsif ARGV[0] == 'disable'
|
101
|
+
if ARGV[1]
|
102
|
+
`mv tests-enabled/#{ARGV[1]}.* tests-available/`
|
103
|
+
else
|
104
|
+
puts "Please also provide prefix!"
|
105
|
+
end
|
106
|
+
else
|
107
|
+
puts "Unknown command '#{ARGV[0]}'!"
|
108
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/autorun'
|
5
|
+
require 'prestashop-automation-tool/helper'
|
6
|
+
|
7
|
+
def test_invoice ps, scenario, options={}
|
8
|
+
|
9
|
+
taxes = {}
|
10
|
+
groups = {}
|
11
|
+
|
12
|
+
ps.login_to_back_office
|
13
|
+
ps.set_friendly_urls false
|
14
|
+
ps.set_order_process_type scenario['meta']['order_process'].to_sym
|
15
|
+
|
16
|
+
if scenario["discounts"]
|
17
|
+
scenario["discounts"].each_pair do |name, amount|
|
18
|
+
ps.create_cart_rule :name=> name, :amount => amount
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if scenario["gift_wrapping"]
|
23
|
+
ps.set_gift_wrapping_option true,
|
24
|
+
:price => scenario["gift_wrapping"]["price"],
|
25
|
+
:tax_group_id => scenario["gift_wrapping"]["vat"] ? ps.create_tax_group_from_rate(scenario["gift_wrapping"]["vat"], taxes, groups) : nil,
|
26
|
+
:recycling_option => false
|
27
|
+
else
|
28
|
+
ps.set_gift_wrapping_option false
|
29
|
+
end
|
30
|
+
|
31
|
+
ps.set_rounding_rule scenario['meta']['rounding_rule']
|
32
|
+
ps.set_rounding_method scenario['meta']['rounding_method']
|
33
|
+
|
34
|
+
if scenario['meta']['ecotax']
|
35
|
+
ps.set_ecotax_option true, ps.create_tax_group_from_rate(scenario['meta']['ecotax'], taxes, groups)
|
36
|
+
else
|
37
|
+
ps.set_ecotax_option false
|
38
|
+
end
|
39
|
+
|
40
|
+
carrier_name = ps.create_carrier({
|
41
|
+
:name => scenario['carrier']['name'],
|
42
|
+
:with_handling_fees => scenario['carrier']['with_handling_fees'],
|
43
|
+
:free_shipping => scenario['carrier']['shipping_fees'] == 0,
|
44
|
+
:ranges => [{:from_included => 0, :to_excluded => 1000, :prices => {0 => scenario['carrier']['shipping_fees']}}],
|
45
|
+
:tax_group_id => scenario['carrier']['vat'] ? ps.create_tax_group_from_rate(scenario['carrier']['vat'], taxes, groups) : nil
|
46
|
+
})
|
47
|
+
|
48
|
+
products = []
|
49
|
+
scenario['products'].each_pair do |name, data|
|
50
|
+
id = ps.create_product({
|
51
|
+
:name => name,
|
52
|
+
:price => data['price'],
|
53
|
+
:tax_group_id => ps.create_tax_group_from_rate(data['vat'], taxes, groups),
|
54
|
+
:ecotax => data['ecotax'],
|
55
|
+
:specific_price => data['specific_price']
|
56
|
+
})
|
57
|
+
products << {id: id, quantity: data['quantity']}
|
58
|
+
|
59
|
+
if data["discount"]
|
60
|
+
ps.create_cart_rule({
|
61
|
+
:product_id => id,
|
62
|
+
:amount => data["discount"],
|
63
|
+
:free_shipping => false,
|
64
|
+
:name => "#{name} with (#{data['discount']}) discount"
|
65
|
+
})
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
ps.login_to_front_office
|
70
|
+
ps.add_products_to_cart products
|
71
|
+
|
72
|
+
order_id = if scenario['meta']['order_process'] == 'five_steps'
|
73
|
+
ps.order_current_cart_5_steps :carrier => carrier_name, :gift_wrapping => scenario["gift_wrapping"]
|
74
|
+
else
|
75
|
+
ps.order_current_cart_opc :carrier => carrier_name, :gift_wrapping => scenario["gift_wrapping"]
|
76
|
+
end
|
77
|
+
|
78
|
+
ps.goto_back_office
|
79
|
+
invoice = ps.validate_order :id => order_id, :dump_pdf_to => options[:dump_pdf_to], :get_invoice_json => true
|
80
|
+
|
81
|
+
if scenario['expect']['invoice']
|
82
|
+
if expected_total = scenario['expect']['invoice']['total']
|
83
|
+
actual_total = invoice['order']
|
84
|
+
mapping = {
|
85
|
+
'to_pay_tax_included' => 'total_paid_tax_incl',
|
86
|
+
'to_pay_tax_excluded' => 'total_paid_tax_excl',
|
87
|
+
'products_tax_included' => 'total_products_wt',
|
88
|
+
'products_tax_excluded' => 'total_products',
|
89
|
+
'shipping_tax_included' => 'total_shipping_tax_incl',
|
90
|
+
'shipping_tax_excluded' => 'total_shipping_tax_excl',
|
91
|
+
'discounts_tax_included' => 'total_discounts_tax_incl',
|
92
|
+
'discounts_tax_excluded' => 'total_discounts_tax_excl',
|
93
|
+
'wrapping_tax_included' => 'total_wrapping_tax_incl',
|
94
|
+
'wrapping_tax_excluded' => 'total_wrapping_tax_excl'
|
95
|
+
}
|
96
|
+
#puts invoice
|
97
|
+
expected_total.each_pair do |key, value_expected|
|
98
|
+
expect(actual_total[mapping[key]].to_f).to eq value_expected.to_f
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
scenario = JSON.parse File.read(ENV['PAT_SOURCE'])
|
105
|
+
|
106
|
+
describe 'Invoice test' do
|
107
|
+
it 'should work' do
|
108
|
+
test_invoice @shop, scenario, :dump_pdf_to => ENV['PAT_SOURCE'].sub(/\.json$/, '.pdf')
|
109
|
+
end
|
110
|
+
end
|
@@ -3,6 +3,11 @@ require 'apache-vhosts-parser'
|
|
3
3
|
require 'prestashop-automation'
|
4
4
|
|
5
5
|
module PrestaShopAutomationTool
|
6
|
+
|
7
|
+
def self.gem_root
|
8
|
+
File.expand_path '../..', __FILE__
|
9
|
+
end
|
10
|
+
|
6
11
|
class ConfigurationParser
|
7
12
|
|
8
13
|
attr_reader :config
|
@@ -31,7 +36,8 @@ module PrestaShopAutomationTool
|
|
31
36
|
admin_email: 'pub@prestashop.com',
|
32
37
|
admin_password: '123456789',
|
33
38
|
default_customer_email: 'pub@prestashop.com',
|
34
|
-
default_customer_password: '123456789'
|
39
|
+
default_customer_password: '123456789',
|
40
|
+
tests_repository: 'https://github.com/djfm/prestashop-automation-tool-tests'
|
35
41
|
}
|
36
42
|
|
37
43
|
@config = {}
|
@@ -91,12 +97,11 @@ module PrestaShopAutomationTool
|
|
91
97
|
@config[:database_host] = m[1]
|
92
98
|
@config[:database_port] = m[2]
|
93
99
|
end
|
94
|
-
|
95
100
|
if @admin_folder
|
96
|
-
@config[:back_office_url] = URI.join(@config[:front_office_url], @admin_folder).to_s
|
101
|
+
@config[:back_office_url] = URI.join(@config[:front_office_url], @admin_folder + '/').to_s
|
97
102
|
end
|
98
103
|
if @installer_folder
|
99
|
-
@config[:installer_url] = URI.join(@config[:front_office_url], @installer_folder).to_s
|
104
|
+
@config[:installer_url] = URI.join(@config[:front_office_url], @installer_folder + '/').to_s
|
100
105
|
end
|
101
106
|
end
|
102
107
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'prestashop-automation'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
dump = nil
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before :all do
|
8
|
+
conf = JSON.parse(File.read('pat.conf.json'), :symbolize_names => true)
|
9
|
+
@shop = PrestaShopAutomation::PrestaShop.new conf[:shop]
|
10
|
+
unless ENV['NO_RESTORE'] == '1'
|
11
|
+
dump = @shop.save
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config.after :all do
|
16
|
+
unless ENV['NO_RESTORE'] == '1'
|
17
|
+
@shop.restore dump
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prestashop-automation-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -46,12 +46,16 @@ dependencies:
|
|
46
46
|
description: Automate prestashop.
|
47
47
|
email: fm.de.jouvencel@gmail.com
|
48
48
|
executables:
|
49
|
-
- pat
|
49
|
+
- pat
|
50
|
+
- pat-runner-invoice.rb
|
50
51
|
extensions: []
|
51
52
|
extra_rdoc_files: []
|
52
53
|
files:
|
54
|
+
- lib/prestashop-automation-tool/helper.rb
|
53
55
|
- lib/prestashop-automation-tool.rb
|
54
|
-
-
|
56
|
+
- lib/templates/sample_test.rb
|
57
|
+
- bin/pat
|
58
|
+
- bin/pat-runner-invoice.rb
|
55
59
|
homepage: https://github.com/djfm/prestashop-automation-tool
|
56
60
|
licenses:
|
57
61
|
- OSL
|
data/bin/pat.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
require 'prestashop-automation-tool'
|
3
|
-
|
4
|
-
require 'optparse'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
def withConfig &block
|
8
|
-
if File.exists? 'pat.conf.json'
|
9
|
-
yield JSON.parse(File.read('pat.conf.json'), :symbolize_names => true)
|
10
|
-
else
|
11
|
-
abort "Could not find the config file #{pat.conf.json}, did you run 'pat.rb init'?"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
options = {}
|
16
|
-
OptionParser.new do |opts|
|
17
|
-
opts.on('-ad', '--accept-defaults', 'Accept default values automatically') do
|
18
|
-
options[:accept_defaults] = true
|
19
|
-
end
|
20
|
-
end.parse!
|
21
|
-
if ARGV.count != 1
|
22
|
-
puts "Missing action argument!"
|
23
|
-
exit 1
|
24
|
-
elsif ARGV[0] == 'init'
|
25
|
-
conf = PrestaShopAutomationTool::ConfigurationParser.new '.'
|
26
|
-
conf.parse
|
27
|
-
conf.ask_user_for_missing_info options
|
28
|
-
conf.autocomplete_config
|
29
|
-
File.write 'pat.conf.json', JSON.pretty_generate({
|
30
|
-
shop: conf.config
|
31
|
-
})
|
32
|
-
elsif ARGV[0] == 'install'
|
33
|
-
withConfig do |conf|
|
34
|
-
ps = PrestaShopAutomation::PrestaShop.new(conf[:shop])
|
35
|
-
ps.drop_database
|
36
|
-
ps.install options
|
37
|
-
end
|
38
|
-
end
|