Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kat Hoessel
resttime
Commits
d46e7f03
Commit
d46e7f03
authored
Sep 14, 2020
by
katsel
Browse files
Put API calls and parsing into a function
parent
b0fb6ef9
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/resttime_tests.py
View file @
d46e7f03
from
nose.tools
import
*
import
flask
from
datetime
import
datetime
,
date
from
resttime
import
*
app
.
config
[
'TESTING'
]
=
True
web
=
app
.
test_client
()
def
read_api_time
(
endpoint
=
'/time'
):
with
web
.
get
(
endpoint
)
as
resp
:
# read from API
rline
=
resp
.
data
.
splitlines
()[
0
].
decode
(
'utf-8'
)
# convert to datetime object
rtime
=
datetime
.
strptime
(
rline
,
'%a %b %d %H:%M:%S %Y'
)
return
rtime
def
test_index
():
# check that we get a 404 on the / URL
resp
=
web
.
get
(
'/'
)
assert_equal
(
resp
.
status_code
,
404
)
# test that /time URL works (200 status and not empty)
resp
=
web
.
get
(
'/time'
)
expected
=
200
resp
=
web
.
get
(
'/time'
)
assert_equal
(
resp
.
status_code
,
expected
),
"Expected status %r is not %r"
%
(
expected
,
resp
.
status_code
)
assert
resp
.
data
,
"Response data is empty."
def
test_date
():
# check that the date is correct
with
web
.
get
(
'/time'
)
as
resp
:
restline
=
resp
.
data
.
splitlines
()[
0
].
decode
(
'utf-8'
)
resttime
=
datetime
.
strptime
(
restline
,
'%a %b %d %H:%M:%S %Y'
)
assert
resttime
.
date
()
==
date
.
today
(),
"Date does not match"
# check for correct date
resttime
=
read_api_time
()
assert
resttime
.
date
()
==
date
.
today
(),
"Date does not match"
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