Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
ca7983a4
Commit
ca7983a4
authored
9 years ago
by
Raphael Collet
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] account_budget: in test, use `float_compare` to compare amounts
parent
81233285
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
addons/account_budget/tests/test_theoreticalamount.py
+17
-11
17 additions, 11 deletions
addons/account_budget/tests/test_theoreticalamount.py
with
17 additions
and
11 deletions
addons/account_budget/tests/test_theoreticalamount.py
+
17
−
11
View file @
ca7983a4
...
...
@@ -3,7 +3,7 @@ from datetime import datetime
from
mock
import
patch
from
openerp.tests.common
import
TransactionCase
from
openerp.tools
import
DEFAULT_SERVER_DATETIME_FORMAT
from
openerp.tools
import
DEFAULT_SERVER_DATETIME_FORMAT
,
float_compare
# ---------------------------------------------------------
...
...
@@ -32,65 +32,71 @@ class TestTheoreticalAmount(TransactionCase):
self
.
patcher
=
patch
(
'
openerp.addons.account_budget.account_budget.datetime
'
,
wraps
=
datetime
)
self
.
mock_datetime
=
self
.
patcher
.
start
()
def
assertFloatEqual
(
self
,
value1
,
value2
,
*
args
,
**
kwargs
):
"""
Compare two values of the field theoritical_amount
"""
digits
=
type
(
self
.
line
).
theoritical_amount
.
digits
result
=
float_compare
(
value1
,
value2
,
precision_digits
=
digits
[
1
])
return
self
.
assertFalse
(
result
,
*
args
,
**
kwargs
)
def
test_01
(
self
):
"""
Start
"""
date
=
datetime
.
strptime
(
'
2014-01-01 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
0
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
0
)
def
test_02
(
self
):
"""
After 24 hours
"""
date
=
datetime
.
strptime
(
'
2014-01-02 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
1
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
1
)
def
test_03
(
self
):
"""
After 36 hours
"""
date
=
datetime
.
strptime
(
'
2014-01-02 12:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
1.5
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
1.5
)
def
test_04
(
self
):
"""
After 48 hours
"""
date
=
datetime
.
strptime
(
'
2014-01-03 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
2
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
2
)
def
test_05
(
self
):
"""
After 10 days
"""
date
=
datetime
.
strptime
(
'
2014-01-11 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
10
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
10
)
def
test_06
(
self
):
"""
After 50 days
"""
date
=
datetime
.
strptime
(
'
2014-02-20 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
50
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
50
)
def
test_07
(
self
):
"""
After 182 days, exactly half of the budget line
"""
date
=
datetime
.
strptime
(
'
2014-07-02 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
182
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
182
)
def
test_08
(
self
):
"""
After 308 days at noon
"""
date
=
datetime
.
strptime
(
'
2014-11-05 12:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
# remember, remember
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
308.5
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
308.5
)
def
test_09
(
self
):
"""
One day before
"""
date
=
datetime
.
strptime
(
'
2014-12-30 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
363
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
363
)
def
test_10
(
self
):
"""
At last
"""
date
=
datetime
.
strptime
(
'
2014-12-31 00:00:00
'
,
DEFAULT_SERVER_DATETIME_FORMAT
)
self
.
mock_datetime
.
now
.
return_value
=
date
self
.
assertEqual
(
self
.
line
.
theoritical_amount
,
-
364
)
self
.
assert
Float
Equal
(
self
.
line
.
theoritical_amount
,
-
364
)
def
tearDown
(
self
):
self
.
patcher
.
stop
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment