cucumber-openerpscenario 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
data/cucumber-openerp.gemspec
CHANGED
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
###############################################################################
|
2
2
|
#
|
3
3
|
# OERPScenario, OpenERP Functional Tests
|
4
|
-
# Author Nicolas Bessi 2009
|
4
|
+
# Author Nicolas Bessi 2009
|
5
5
|
# Copyright Camptocamp SA
|
6
6
|
#
|
7
7
|
# This program is free software: you can redistribute it and/or modify
|
@@ -43,7 +43,7 @@ class ScenarioUtils
|
|
43
43
|
|
44
44
|
def get_config
|
45
45
|
my_config = ParseConfig.new(config_path)
|
46
|
-
|
46
|
+
# TODO When ruby 1.8 obsolete use dict syntax
|
47
47
|
{# ooor options
|
48
48
|
:port => my_config.get_value('port'),
|
49
49
|
:user => my_config.get_value('user'),
|
@@ -51,7 +51,7 @@ class ScenarioUtils
|
|
51
51
|
:pwd => my_config.get_value('password'),
|
52
52
|
:host => my_config.get_value('host'),
|
53
53
|
:log_level => Logger::ERROR,
|
54
|
-
|
54
|
+
:rpc_timeout => my_config.get_value('rpc_timeout').nil? ? nil : my_config.get_value('rpc_timeout').to_i,
|
55
55
|
# sequel options
|
56
56
|
:db_host => my_config.get_value('db_host'),
|
57
57
|
:db_port => my_config.get_value('db_port'),
|
@@ -59,4 +59,4 @@ class ScenarioUtils
|
|
59
59
|
:db_password => my_config.get_value('db_password')}
|
60
60
|
end
|
61
61
|
private :get_config
|
62
|
-
end
|
62
|
+
end
|
@@ -45,7 +45,7 @@ module OoorUtils
|
|
45
45
|
rescue Exception => e
|
46
46
|
$helperlogger.warn('can not load scenario helpers')
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
50
50
|
def create_ooor_connection(params={})
|
51
51
|
ooor.open_connection(config.merge(params))
|
@@ -92,6 +92,7 @@ class OoorProxy < BasicObject
|
|
92
92
|
:database => params[:dbname],
|
93
93
|
:username => params[:user],
|
94
94
|
:password => params[:pwd],
|
95
|
+
:rpc_timeout => params[:rpc_timeout],
|
95
96
|
:log_level => params[:log_level]})
|
96
97
|
end
|
97
98
|
private :init_ooor_connection
|
@@ -131,4 +132,4 @@ class OoorProxy < BasicObject
|
|
131
132
|
end
|
132
133
|
protected :method_missing
|
133
134
|
|
134
|
-
end
|
135
|
+
end
|
data/lib/cucumber/openerp/dsl.rb
CHANGED
@@ -24,12 +24,12 @@ def get_items(action, qty, model, args)
|
|
24
24
|
else
|
25
25
|
qty = ''
|
26
26
|
end
|
27
|
-
command_map = {'create' => 'new', 'need' => 'find_or_initialize_by_', '
|
27
|
+
command_map = {'create' => 'new', 'need' => 'find_or_initialize_by_', 'should have' => "find_#{qty}by_", 'find' => "find_#{qty}by_", 'find or create' => 'find_or_initialize_by_'}
|
28
28
|
comm_ext, arguments = prepare_args(args)
|
29
29
|
arguments.push({:fields=>['id']})
|
30
30
|
if command_map[action] == 'create'
|
31
31
|
if oclass.send(('find_by_'+comm_ext).to_sym, *arguments)
|
32
|
-
raise "Error object
|
32
|
+
raise "Error. This object already exists, if you want to update or use it, you have to use the sentence starting with \"I need...\" or \"I should have\""
|
33
33
|
end
|
34
34
|
end
|
35
35
|
res = oclass.send((command_map[action]+comm_ext).to_sym, *arguments) # I know in case or create we do 2 search but as there should be nul it cost almost nothing
|
@@ -56,35 +56,44 @@ def _manage_col_search(field_def, value)
|
|
56
56
|
return oid
|
57
57
|
end
|
58
58
|
|
59
|
+
def _item_value(relations, field_name, input_value, value_type)
|
60
|
+
return input_value if %w(char text).include?(value_type)
|
61
|
+
|
62
|
+
# we want to empty the data
|
63
|
+
return false if input_value.match(/^(false|0|no|f|n|nil)$/i)
|
64
|
+
|
65
|
+
# the field is a relation
|
66
|
+
if relations[field_name]
|
67
|
+
rel_item = _manage_col_search(relations[field_name], input_value)
|
68
|
+
return rel_item.id
|
69
|
+
end
|
70
|
+
|
71
|
+
# other data types
|
72
|
+
value = case value_type
|
73
|
+
when 'integer' then Integer(input_value)
|
74
|
+
when 'float' then Float(input_value)
|
75
|
+
when 'boolean' then true # false values are already trapped
|
76
|
+
when 'date', 'datetime' then
|
77
|
+
input_value.include?('%') ? Time.new.strftime(input_value) : input_value
|
78
|
+
else
|
79
|
+
input_value
|
80
|
+
end
|
81
|
+
value
|
82
|
+
end
|
83
|
+
|
59
84
|
def manage_item_table(item, table)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
85
|
+
relations = {}
|
86
|
+
relations.merge! item.class.many2one_associations
|
87
|
+
relations.merge! item.class.one2many_associations
|
88
|
+
relations.merge! item.class.many2many_associations
|
89
|
+
|
65
90
|
table.hashes.each do |dict|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
if v_type == 'integer'
|
73
|
-
value = Integer(value)
|
74
|
-
elsif v_type == 'float'
|
75
|
-
value = Float(value)
|
76
|
-
elsif v_type == 'boolean'
|
77
|
-
if [nil, 0, false, ''].include? value
|
78
|
-
value = false
|
79
|
-
end
|
80
|
-
elsif ['date', 'datetime'].include? v_type
|
81
|
-
if value.include? "%"
|
82
|
-
value = Time.new().strftime(value)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
eval "item.#{dict['name']} = value"
|
86
|
-
end
|
87
|
-
end
|
91
|
+
field_name = dict['name']
|
92
|
+
value = dict['value']
|
93
|
+
value_type = item.class.fields.fetch(field_name, {}).fetch('type', '')
|
94
|
+
|
95
|
+
item.send("#{field_name}=".to_sym, _item_value(relations, field_name, value, value_type))
|
96
|
+
end
|
88
97
|
end
|
89
98
|
|
90
99
|
Given /^I (create|need|should have|find|find or create) (a|all|last) "([^"]*)" with (.*)$/ do |action, qty, model, args|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cucumber-openerpscenario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nicolas Bessi - Camptocamp
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- bin/cucumber-openerp
|
84
84
|
- cucumber-openerp.gemspec
|
85
85
|
- cucumber-openerpscenario-0.1.6.gem
|
86
|
+
- cucumber-openerpscenario-0.1.7.gem
|
86
87
|
- lib/.DS_Store
|
87
88
|
- lib/cucumber/.DS_Store
|
88
89
|
- lib/cucumber/lib/.DS_Store
|