Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amer
erp5
Commits
63c7b495
Commit
63c7b495
authored
Jul 23, 2012
by
Yusei Tahara
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'for_testrunner_1'
parents
c803a430
98601acc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
4 deletions
+144
-4
product/ERP5/tests/testInventoryAPI.py
product/ERP5/tests/testInventoryAPI.py
+122
-0
product/ZSQLCatalog/SearchKey/DateTimeKey.py
product/ZSQLCatalog/SearchKey/DateTimeKey.py
+22
-4
No files found.
product/ERP5/tests/testInventoryAPI.py
View file @
63c7b495
...
@@ -45,6 +45,7 @@ from Products.ERP5Type.tests.utils import reindex
...
@@ -45,6 +45,7 @@ from Products.ERP5Type.tests.utils import reindex
from
Products.ERP5Type.tests.backportUnittest
import
expectedFailure
from
Products.ERP5Type.tests.backportUnittest
import
expectedFailure
from
Products.DCWorkflow.DCWorkflow
import
ValidationFailed
from
Products.DCWorkflow.DCWorkflow
import
ValidationFailed
from
Products.ERP5Type.Base
import
_aq_reset
from
Products.ERP5Type.Base
import
_aq_reset
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
InventoryAPITestCase
(
ERP5TypeTestCase
):
class
InventoryAPITestCase
(
ERP5TypeTestCase
):
"""Base class for Inventory API Tests {{{
"""Base class for Inventory API Tests {{{
...
@@ -132,6 +133,8 @@ class InventoryAPITestCase(ERP5TypeTestCase):
...
@@ -132,6 +133,8 @@ class InventoryAPITestCase(ERP5TypeTestCase):
self
.
folder
.
getId
()
]:
self
.
folder
.
getId
()
]:
folder
=
self
.
portal
[
module
]
folder
=
self
.
portal
[
module
]
folder
.
manage_delObjects
(
list
(
folder
.
objectIds
()))
folder
.
manage_delObjects
(
list
(
folder
.
objectIds
()))
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
list
(
self
.
portal
.
portal_skins
.
custom
.
objectIds
()))
self
.
tic
()
self
.
tic
()
def
login
(
self
,
quiet
=
0
,
run
=
1
):
def
login
(
self
,
quiet
=
0
,
run
=
1
):
...
@@ -2739,6 +2742,125 @@ class TestInventoryDocument(InventoryAPITestCase):
...
@@ -2739,6 +2742,125 @@ class TestInventoryDocument(InventoryAPITestCase):
optimisation__
=
False
,
optimisation__
=
False
,
mirror_uid
=
self
.
mirror_node
.
getUid
())])
mirror_uid
=
self
.
mirror_node
.
getUid
())])
def
test_MultipleSectionAndFullInventory
(
self
):
"""Make sure that getInventoryList works in the situation which
two sections use the same node and one section has full inventory for
the node.
"""
# In this test we do not need doucments made by afterSetUp.
self
.
portal
.
inventory_module
.
manage_delObjects
(
list
(
self
.
portal
.
inventory_module
.
objectIds
()))
self
.
folder
.
manage_delObjects
(
list
(
self
.
folder
.
objectIds
()))
self
.
commit
()
self
.
tic
()
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
'Inventory_getDefaultInventoryCalculationList'
,
''
,
'''return ({
'inventory_params':{
'section_uid':context.getDestinationSectionUid(),
'node_uid':context.getDestinationUid(),
'group_by_variation':1,
'group_by_resource':1},
'list_method':'getMovementList',
'first_level':({'key':'resource_relative_url',
'getter':'getResource',
'setter':('appendToCategoryList', 'resource')},
{'key':'variation_text',
'getter':'getVariationText',
'setter':'splitAndExtendToCategoryList'},
),
},)
'''
)
self
.
commit
()
getCurrentInventoryList
=
self
.
getSimulationTool
().
getCurrentInventoryList
# Add movements for section
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/18 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
1
)
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/21 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
2
)
# Add movemnets for other section
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/19 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
3
)
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/20 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
4
)
self
.
commit
()
self
.
tic
()
# Check inventory
result
=
{}
for
brain
in
getCurrentInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
group_by_resource
=
1
,
group_by_node
=
1
,
group_by_section
=
1
):
key
=
(
brain
.
section_uid
,
brain
.
node_uid
,
brain
.
resource_uid
)
if
not
key
in
result
:
result
[
key
]
=
0
result
[
key
]
=
result
[
key
]
+
brain
.
inventory
self
.
assertEqual
(
result
,
{(
self
.
section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
3
,
(
self
.
other_section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
7
})
# Add full inventory for section, not for other section
full_inventory1
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory1
.
edit
(
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/07/20 00:00:00 GMT+9'
))
line
=
full_inventory1
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
100
)
full_inventory1
.
deliver
()
self
.
commit
()
self
.
tic
()
# Check inventory again. This time, full inventory should change
# section's inventory. It should not change other section's inventory.
result
=
{}
for
brain
in
getCurrentInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
group_by_resource
=
1
,
group_by_node
=
1
,
group_by_section
=
1
):
key
=
(
brain
.
section_uid
,
brain
.
node_uid
,
brain
.
resource_uid
)
if
not
key
in
result
:
result
[
key
]
=
0
result
[
key
]
=
result
[
key
]
+
brain
.
inventory
self
.
assertEqual
(
result
,
{(
self
.
section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
102
,
(
self
.
other_section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
7
})
class
BaseTestUnitConversion
(
InventoryAPITestCase
):
class
BaseTestUnitConversion
(
InventoryAPITestCase
):
QUANTITY_UNIT_DICT
=
{}
QUANTITY_UNIT_DICT
=
{}
...
...
product/ZSQLCatalog/SearchKey/DateTimeKey.py
View file @
63c7b495
...
@@ -53,7 +53,7 @@ def _DateTime(*args, **kw):
...
@@ -53,7 +53,7 @@ def _DateTime(*args, **kw):
return
DateTime
(
*
args
,
**
kw
)
return
DateTime
(
*
args
,
**
kw
)
@
profiler_decorator
@
profiler_decorator
def
castDate
(
value
):
def
castDate
(
value
,
change_timezone
=
True
):
if
value
is
None
:
if
value
is
None
:
return
None
return
None
date_kw
=
{
'datefmt'
:
'international'
}
date_kw
=
{
'datefmt'
:
'international'
}
...
@@ -69,6 +69,17 @@ def castDate(value):
...
@@ -69,6 +69,17 @@ def castDate(value):
pass
pass
elif
isinstance
(
value
,
basestring
):
elif
isinstance
(
value
,
basestring
):
try
:
try
:
# This is needed because DateTime(2012) ignores timezone.
# >>> DateTime()
# DateTime('2012/01/30 19:06:34.216686 GMT+9')
# >>> DateTime('2012')
# DateTime('2012/01/01 00:00:00 GMT+0')
# Timezone changed from GMT+9 to GMT+0!
# Then document at "2012/01/01 00:00:00 GMT+9" cannot be found by
# query of '2012'.
# Because "2012/01/01 00:00:00 GMT+9" < "2012/01/01 00:00:00 GMT+0".
if
value
.
isdigit
():
raise
DateTimeError
value
=
_DateTime
(
value
,
**
date_kw
)
value
=
_DateTime
(
value
,
**
date_kw
)
except
DateTimeError
:
except
DateTimeError
:
delimiter_count
=
countDelimiters
(
value
)
delimiter_count
=
countDelimiters
(
value
)
...
@@ -83,7 +94,14 @@ def castDate(value):
...
@@ -83,7 +94,14 @@ def castDate(value):
raise
raise
else
:
else
:
raise
TypeError
,
'Unknown date type: %r'
%
(
value
)
raise
TypeError
,
'Unknown date type: %r'
%
(
value
)
return
value
.
toZone
(
'UTC'
)
if
change_timezone
:
return
value
.
toZone
(
'UTC'
)
else
:
# This is needed. Because if you call toZone('UTC'),
# 2012/12/01 can become 2012/11/30 and then month
# is changed! Month must not be changed. Otherwise
# getMonthLen returns wrong value.
return
value
# (strongly) inspired from DateTime.DateTime.py
# (strongly) inspired from DateTime.DateTime.py
delimiter_list
=
' -/.:,+'
delimiter_list
=
' -/.:,+'
...
@@ -114,7 +132,7 @@ def countDelimiters(value):
...
@@ -114,7 +132,7 @@ def countDelimiters(value):
@
profiler_decorator
@
profiler_decorator
def
getPeriodBoundaries
(
value
):
def
getPeriodBoundaries
(
value
):
first_date
=
castDate
(
value
)
first_date
=
castDate
(
value
,
change_timezone
=
False
)
if
isinstance
(
value
,
dict
):
if
isinstance
(
value
,
dict
):
value
=
value
[
'query'
]
value
=
value
[
'query'
]
# Try to guess how much was given in query.
# Try to guess how much was given in query.
...
@@ -127,7 +145,7 @@ def getPeriodBoundaries(value):
...
@@ -127,7 +145,7 @@ def getPeriodBoundaries(value):
delta
=
delta_list
[
delimiter_count
]
delta
=
delta_list
[
delimiter_count
]
if
callable
(
delta
):
if
callable
(
delta
):
delta
=
delta
(
first_date
)
delta
=
delta
(
first_date
)
return
first_date
,
first_date
+
delta
return
first_date
.
toZone
(
'UTC'
),
(
first_date
+
delta
).
toZone
(
'UTC'
)
@
profiler_decorator
@
profiler_decorator
def
wholePeriod
(
search_key
,
group
,
column
,
value_list
,
exclude
=
False
):
def
wholePeriod
(
search_key
,
group
,
column
,
value_list
,
exclude
=
False
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment