Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-polling-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
geant-swd
brian
brian-polling-manager
Commits
f60dcd17
Commit
f60dcd17
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added api tests
parent
756470ac
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
brian_polling_manager/api.py
+2
-2
2 additions, 2 deletions
brian_polling_manager/api.py
test/conftest.py
+8
-0
8 additions, 0 deletions
test/conftest.py
test/test_api.py
+38
-0
38 additions, 0 deletions
test/test_api.py
test/test_e2e.py
+7
-11
7 additions, 11 deletions
test/test_e2e.py
with
55 additions
and
13 deletions
brian_polling_manager/api.py
+
2
−
2
View file @
f60dcd17
...
@@ -23,7 +23,7 @@ import pkg_resources
...
@@ -23,7 +23,7 @@ import pkg_resources
from
flask
import
Blueprint
,
current_app
,
request
,
Response
,
jsonify
from
flask
import
Blueprint
,
current_app
,
request
,
Response
,
jsonify
from
brian_polling_manager
import
CONFIG_KEY
from
brian_polling_manager
import
CONFIG_KEY
from
brian_polling_manager
.main
import
refresh
from
brian_polling_manager
import
main
routes
=
Blueprint
(
"
api-routes
"
,
__name__
)
routes
=
Blueprint
(
"
api-routes
"
,
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -159,5 +159,5 @@ def update():
...
@@ -159,5 +159,5 @@ def update():
:return:
:return:
"""
"""
response
=
refresh
(
config
=
current_app
.
config
[
CONFIG_KEY
])
response
=
main
.
refresh
(
config
=
current_app
.
config
[
CONFIG_KEY
])
return
jsonify
(
response
)
return
jsonify
(
response
)
This diff is collapsed.
Click to expand it.
test/conftest.py
+
8
−
0
View file @
f60dcd17
...
@@ -55,6 +55,14 @@ def config():
...
@@ -55,6 +55,14 @@ def config():
}
}
@pytest.fixture
def
config_filename
(
config
):
with
tempfile
.
NamedTemporaryFile
(
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
config
))
f
.
flush
()
yield
f
.
name
@pytest.fixture
@pytest.fixture
def
mocked_sensu
():
def
mocked_sensu
():
...
...
This diff is collapsed.
Click to expand it.
test/test_api.py
0 → 100644
+
38
−
0
View file @
f60dcd17
import
json
import
os
import
jsonschema
import
pytest
import
responses
import
brian_polling_manager
from
brian_polling_manager.api
import
VERSION_SCHEMA
from
brian_polling_manager.main
import
REFRESH_RESULT_SCHEMA
@pytest.fixture
def
client
(
config_filename
,
mocked_sensu
,
mocked_inventory
):
os
.
environ
[
'
CONFIG_FILENAME
'
]
=
config_filename
with
brian_polling_manager
.
create_app
().
test_client
()
as
c
:
yield
c
def
test_version
(
client
):
rv
=
client
.
get
(
'
/api/version
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
VERSION_SCHEMA
)
@responses.activate
def
test_update
(
client
):
rv
=
client
.
get
(
'
/api/update
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
REFRESH_RESULT_SCHEMA
)
This diff is collapsed.
Click to expand it.
test/test_e2e.py
+
7
−
11
View file @
f60dcd17
...
@@ -8,15 +8,11 @@ from brian_polling_manager import main
...
@@ -8,15 +8,11 @@ from brian_polling_manager import main
@responses.activate
@responses.activate
def
test_run_flashtest
(
config
,
mocked_sensu
,
mocked_inventory
):
def
test_run_flashtest
(
config
_filename
,
mocked_sensu
,
mocked_inventory
):
with
tempfile
.
NamedTemporaryFile
(
mode
=
'
w
'
)
as
f
:
runner
=
CliRunner
()
f
.
write
(
json
.
dumps
(
config
))
result
=
runner
.
invoke
(
f
.
flush
()
main
.
cli
,
[
'
--config
'
,
config_filename
,
'
--force
'
]
runner
=
CliRunner
()
)
result
=
runner
.
invoke
(
assert
result
.
exit_code
==
0
main
.
cli
,
[
'
--config
'
,
f
.
name
,
'
--force
'
]
)
assert
result
.
exit_code
==
0
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