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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
6880eb79
Commit
6880eb79
authored
Jun 16, 2016
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: move Tracking API to a dedicated test module
parent
7376157c
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
244 additions
and
200 deletions
+244
-200
bt5/tmp_work/TestTemplateItem/portal_components/test.erp5.testInventoryAPI.py
...plateItem/portal_components/test.erp5.testInventoryAPI.py
+0
-200
product/ERP5/tests/testTrackingAPI.py
product/ERP5/tests/testTrackingAPI.py
+244
-0
No files found.
bt5/tmp_work/TestTemplateItem/portal_components/test.erp5.testInventoryAPI.py
View file @
6880eb79
...
...
@@ -3175,205 +3175,6 @@ class TestInventoryStat(InventoryAPITestCase):
makeMovement
(
quantity
=
5
)
self
.
assertEqual
(
getInventoryStat
(
node_uid
=
node_uid
)[
0
].
stock_uid
,
3
)
class
TestTrackingList
(
InventoryAPITestCase
):
"""Tests Item Tracking
"""
def
testNodeUid
(
self
):
getTrackingList
=
self
.
getSimulationTool
().
getTrackingList
start_date
=
DateTime
()
def
makeMovement
(
aggregate
=
None
):
self
.
_makeMovement
(
quantity
=
1
,
price
=
1
,
aggregate_value
=
aggregate
,
resource_value
=
self
.
resource
,
start_date
=
start_date
,
source_value
=
self
.
other_node
,
destination_value
=
self
.
node
)
item_uid
=
self
.
item
.
getUid
()
other_item_uid
=
self
.
other_item
.
getUid
()
node_uid
=
self
.
node
.
getUid
()
self
.
assertEqual
(
len
(
getTrackingList
(
node_uid
=
node_uid
,
at_date
=
start_date
)),
0
)
makeMovement
(
aggregate
=
self
.
item
)
result
=
getTrackingList
(
node_uid
=
node_uid
,
at_date
=
start_date
)
self
.
assertEqual
(
len
(
result
),
1
)
self
.
failIfDifferentSet
([
x
.
uid
for
x
in
result
],
[
item_uid
])
makeMovement
(
aggregate
=
self
.
other_item
)
result
=
getTrackingList
(
node_uid
=
node_uid
,
at_date
=
start_date
)
self
.
assertEqual
(
len
(
result
),
2
)
self
.
failIfDifferentSet
([
x
.
uid
for
x
in
result
],
[
item_uid
,
other_item_uid
])
def
testSeveralAggregateOnMovement
(
self
):
getTrackingList
=
self
.
getSimulationTool
().
getTrackingList
start_date
=
DateTime
()
def
makeMovement
(
aggregate_list
=
None
):
self
.
_makeMovement
(
quantity
=
1
,
price
=
1
,
aggregate_list
=
aggregate_list
,
resource_value
=
self
.
resource
,
start_date
=
start_date
,
source_value
=
self
.
other_node
,
destination_value
=
self
.
node
)
item_uid
=
self
.
item
.
getUid
()
other_item_uid
=
self
.
other_item
.
getUid
()
node_uid
=
self
.
node
.
getUid
()
self
.
assertEqual
(
len
(
getTrackingList
(
node_uid
=
node_uid
,
at_date
=
start_date
)),
0
)
makeMovement
(
aggregate_list
=
[
self
.
item
.
getRelativeUrl
(),
self
.
other_item
.
getRelativeUrl
()])
result
=
getTrackingList
(
node_uid
=
node_uid
,
at_date
=
start_date
)
self
.
assertEqual
(
len
(
result
),
2
)
self
.
failIfDifferentSet
([
x
.
uid
for
x
in
result
],
[
item_uid
,
other_item_uid
])
def
testDates
(
self
):
"""
Test different dates parameters of getTrackingList.
"""
getTrackingList
=
self
.
getSimulationTool
().
getTrackingList
now
=
DateTime
()
node_1
=
self
.
_makeOrganisation
(
title
=
'Node 1'
)
node_2
=
self
.
_makeOrganisation
(
title
=
'Node 2'
)
date_0
=
now
-
4
# Before first movement
date_1
=
now
-
3
# First movement
date_2
=
now
-
2
# Between both movements
date_3
=
now
-
1
# Second movement
date_4
=
now
# After last movement
self
.
_makeMovement
(
quantity
=
1
,
price
=
1
,
aggregate_value
=
self
.
item
,
resource_value
=
self
.
resource
,
start_date
=
date_1
,
source_value
=
None
,
destination_value
=
node_1
)
self
.
_makeMovement
(
quantity
=
1
,
price
=
1
,
aggregate_value
=
self
.
item
,
resource_value
=
self
.
resource
,
start_date
=
date_3
,
source_value
=
node_1
,
destination_value
=
node_2
)
node_1_uid
=
node_1
.
getUid
()
node_2_uid
=
node_2
.
getUid
()
date_location_dict
=
{
date_0
:
{
'at_date'
:
None
,
'to_date'
:
None
},
date_1
:
{
'at_date'
:
node_1_uid
,
'to_date'
:
None
},
date_2
:
{
'at_date'
:
node_1_uid
,
'to_date'
:
node_1_uid
},
date_3
:
{
'at_date'
:
node_2_uid
,
'to_date'
:
node_1_uid
},
date_4
:
{
'at_date'
:
node_2_uid
,
'to_date'
:
node_2_uid
}
}
node_uid_to_node_number
=
{
node_1_uid
:
1
,
node_2_uid
:
2
}
for
date
,
location_dict
in
date_location_dict
.
iteritems
():
for
param_id
,
location_uid
in
location_dict
.
iteritems
():
param_dict
=
{
param_id
:
date
}
uid_list
=
[
x
.
node_uid
for
x
in
getTrackingList
(
aggregate_uid
=
self
.
item
.
getUid
(),
**
param_dict
)]
if
location_uid
is
None
:
self
.
assertEqual
(
len
(
uid_list
),
0
)
else
:
self
.
assertEqual
(
len
(
uid_list
),
1
)
self
.
assertEqual
(
uid_list
[
0
],
location_uid
,
'%s=now - %i, aggregate should be at node %i but is at node %i'
%
\
(
param_id
,
now
-
date
,
node_uid_to_node_number
[
location_uid
],
node_uid_to_node_number
[
uid_list
[
0
]]))
def
testFutureTrackingList
(
self
):
movement
=
self
.
_makeMovement
(
quantity
=
1
,
aggregate_value
=
self
.
item
,)
getFutureTrackingList
=
self
.
portal
.
portal_simulation
.
getFutureTrackingList
node_uid
=
self
.
node
.
getUid
()
for
state
in
(
'planned'
,
'ordered'
,
'confirmed'
,
'ready'
,
'started'
,
'stopped'
,
'delivered'
):
movement
.
simulation_state
=
state
movement
.
reindexObject
()
self
.
tic
()
tracking_node_uid_list
=
[
brain
.
node_uid
for
brain
in
getFutureTrackingList
(
item
=
self
.
item
.
getRelativeUrl
())]
self
.
assertEqual
([
node_uid
],
tracking_node_uid_list
,
"%s != %s (state:%s)"
%
([
node_uid
],
tracking_node_uid_list
,
state
))
for
state
in
(
'draft'
,
'cancelled'
,
'deleted'
):
movement
.
simulation_state
=
state
movement
.
reindexObject
()
self
.
tic
()
tracking_node_uid_list
=
[
brain
.
node_uid
for
brain
in
getFutureTrackingList
(
item
=
self
.
item
.
getRelativeUrl
())]
self
.
assertEqual
([],
tracking_node_uid_list
,
"%s != %s (state:%s)"
%
([],
tracking_node_uid_list
,
state
))
def
_createScenarioToTestTrackingListMethod
(
self
,
state_a
=
"delivered"
,
state_b
=
"delivered"
,
state_c
=
"delivered"
):
"""
Scenario:
Item 1 => A -> B -> C
Item 2 => A -> B
"""
now
=
DateTime
()
item_a
=
self
.
getItemModule
().
newContent
(
title
=
"Item 1"
)
item_b
=
self
.
getItemModule
().
newContent
(
title
=
"Item 2"
)
node_a
=
self
.
_makeOrganisation
(
title
=
'Node A'
)
node_b
=
self
.
_makeOrganisation
(
title
=
'Node B'
)
node_c
=
self
.
_makeOrganisation
(
title
=
'Node C'
)
movement_a
=
self
.
_makeMovement
(
source_value
=
node_a
,
destination_value
=
node_b
,
resource
=
self
.
resource
,
quantity
=
1
,
aggregate_value
=
item_a
,
start_date
=
now
,
simulation_state
=
state_a
)
movement_b
=
self
.
_makeMovement
(
source_value
=
node_b
,
destination_value
=
node_c
,
resource
=
self
.
resource
,
quantity
=
1
,
aggregate_value
=
item_a
,
start_date
=
now
+
1
,
simulation_state
=
state_b
)
movement_c
=
self
.
_makeMovement
(
source_value
=
node_a
,
destination_value
=
node_b
,
resource
=
self
.
resource
,
quantity
=
1
,
aggregate_value
=
item_b
,
start_date
=
now
+
1
,
simulation_state
=
state_c
)
self
.
tic
()
return
{
"item_a"
:
item_a
,
"item_b"
:
item_b
,
"node_a"
:
node_a
,
"node_b"
:
node_b
,
"movement_a"
:
movement_a
,
"movement_b"
:
movement_b
,
"movement_c"
:
movement_c
}
def
testTrackingListWithOutputParameter
(
self
):
"""
Add test to check if getTrackingList with output=1, returns only Item 2
if you search for items in B
"""
data_dict
=
self
.
_createScenarioToTestTrackingListMethod
()
item_a
=
data_dict
[
'item_a'
]
item_b
=
data_dict
[
'item_b'
]
node_b
=
data_dict
[
'node_b'
]
getTrackingList
=
self
.
portal
.
portal_simulation
.
getTrackingList
path_list
=
[
i
.
path
for
i
in
getTrackingList
(
node_uid
=
node_b
.
getUid
())]
self
.
assertTrue
(
item_a
.
getPath
()
in
path_list
,
"Is expected %s in B"
%
item_a
.
getPath
())
self
.
assertTrue
(
item_b
.
getPath
()
in
path_list
,
"Is expected %s in B"
%
item_b
.
getPath
())
path_list
=
[
i
.
path
for
i
in
getTrackingList
(
node_uid
=
node_b
.
getUid
(),
output
=
1
)]
self
.
assertTrue
(
item_a
.
getPath
()
not
in
path_list
,
"%s should not be in B"
%
item_a
.
getTitle
())
self
.
assertTrue
(
item_b
.
getPath
()
in
path_list
,
"%s should be in B"
%
item_b
.
getTitle
())
def
testCurrentTrackingListWithOutputParameter
(
self
):
"""
Add test to check if getCurrentTrackingList with B -> C started and not delivered,
returns only Item 2 if you search for items in B
"""
data_dict
=
self
.
_createScenarioToTestTrackingListMethod
(
state_b
=
"started"
)
item_a
=
data_dict
[
'item_a'
]
item_b
=
data_dict
[
'item_b'
]
node_b
=
data_dict
[
'node_b'
]
getCurrentTrackingList
=
self
.
portal
.
portal_simulation
.
getCurrentTrackingList
path_list
=
[
i
.
path
for
i
in
getCurrentTrackingList
(
node_uid
=
node_b
.
getUid
(),
output
=
1
)]
self
.
assertTrue
(
item_a
.
getPath
()
not
in
path_list
,
"%s should not be in B"
%
item_a
.
getTitle
())
self
.
assertTrue
(
item_b
.
getPath
()
in
path_list
,
"%s should be in B"
%
item_a
.
getTitle
())
# TODO: missing tests for input=1
class
TestInventoryCacheTable
(
InventoryAPITestCase
):
""" Test impact of creating cache entries into inventory_cache table
...
...
@@ -4498,7 +4299,6 @@ def test_suite():
suite
.
addTest
(
unittest
.
makeSuite
(
TestMovementHistoryList
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestInventoryStat
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestNextNegativeInventoryDate
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestTrackingList
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestInventoryCacheTable
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestUnitConversion
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestUnitConversionDefinition
))
...
...
product/ERP5/tests/testTrackingAPI.py
0 → 100644
View file @
6880eb79
This diff is collapsed.
Click to expand it.
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