Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
bliss
Commits
9b160052
Commit
9b160052
authored
Jun 21, 2021
by
Valentin Valls
Browse files
Rewrite the test with pytest helpers
parent
d7bc2178
Pipeline
#49112
failed with stages
in 99 minutes and 45 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/config/test_settings.py
View file @
9b160052
...
...
@@ -585,22 +585,28 @@ def test_creation_time(session):
assert
"wine"
not
in
drinks
.
instances
drinks
.
switch
(
"wine"
)
# get current time
now
=
datetime
.
datetime
.
now
()
# convert string to datetime obj
creation_date
=
datetime
.
datetime
.
strptime
(
drinks
.
creation_date
,
"%Y-%m-%d %H:%M:%S"
)
assert
abs
(
now
-
creation_date
)
<
datetime
.
timedelta
(
seconds
=
1
)
last_accessed
=
datetime
.
datetime
.
strptime
(
drinks
.
last_accessed
,
"%Y-%m-%d %H:%M:%S"
)
assert
abs
(
now
-
last_accessed
)
<
datetime
.
timedelta
(
seconds
=
2
)
def
str2datetime
(
string
):
return
datetime
.
datetime
.
strptime
(
string
,
"%Y-%m-%d %H:%M:%S"
)
# epsilon time bellow which time comparison is considered to be the same
# This value is pretty big to make sure the CI machine is fast enough
epsilon
=
datetime
.
timedelta
(
seconds
=
2
).
total_seconds
()
# creation and last access was done now
now
=
datetime
.
datetime
.
now
()
creation_date
=
str2datetime
(
drinks
.
creation_date
)
assert
creation_date
.
timestamp
()
==
pytest
.
approx
(
now
.
timestamp
(),
abs
=
epsilon
)
last_accessed
=
str2datetime
(
drinks
.
last_accessed
)
assert
last_accessed
.
timestamp
()
==
pytest
.
approx
(
now
.
timestamp
(),
abs
=
epsilon
)
# a later access update the last access time
gevent
.
sleep
(
1
)
drinks
.
creation_date
# access it => will change 'last_accessed'
assert
drinks
.
last_accessed
!=
str
(
drinks
.
creation_date
)
now
=
datetime
.
datetime
.
now
()
last_accessed2
=
str2datetime
(
drinks
.
last_accessed
)
assert
last_accessed
!=
last_accessed2
,
"last_accessed was not updated"
assert
last_accessed2
.
timestamp
()
==
pytest
.
approx
(
now
.
timestamp
(),
abs
=
epsilon
)
def
test_from_dict_ok
(
session
):
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment