Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
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
dashboardv3
inventory-provider
Commits
2f2d44b5
Commit
2f2d44b5
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added tests of new test routes
parent
8d0dcb76
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_data_routes.py
+117
-4
117 additions, 4 deletions
test/test_data_routes.py
with
117 additions
and
4 deletions
test/test_data_routes.py
+
117
−
4
View file @
2f2d44b5
...
...
@@ -189,6 +189,17 @@ class MockedRedis(object):
def
set
(
self
,
key
,
value
):
MockedRedis
.
db
[
key
]
=
value
def
hget
(
self
,
key
,
field
):
value
=
MockedRedis
.
db
[
key
]
return
json
.
dumps
(
value
[
field
]).
encode
(
'
utf-8
'
)
def
hgetall
(
self
,
key
):
result
=
{}
for
k
,
v
in
MockedRedis
.
db
[
key
].
items
():
result
[
k
.
encode
(
'
utf-8
'
)]
\
=
json
.
dumps
(
v
).
encode
(
'
utf-8
'
)
return
result
def
keys
(
self
,
*
args
,
**
kwargs
):
return
list
([
k
.
encode
(
"
utf-8
"
)
for
k
in
MockedRedis
.
db
.
keys
()])
...
...
@@ -203,19 +214,121 @@ def client_with_mocked_data(mocker, client):
return
client
def
test_routers_list
(
client_with_mocked_data
):
def
_routers
(
client
):
routers_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
}
}
rv
=
client
_with_mocked_data
.
post
(
rv
=
client
.
post
(
"
data/routers
"
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
response
=
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
))
jsonschema
.
validate
(
response
,
routers_list_schema
)
assert
response
# shouldn't be empty
return
response
def
test_routers_list
(
client_with_mocked_data
):
assert
_routers
(
client_with_mocked_data
)
def
test_router_interfaces
(
client_with_mocked_data
):
interfaces_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
}
}
for
router
in
_routers
(
client_with_mocked_data
):
rv
=
client_with_mocked_data
.
post
(
"
/data/interfaces/
"
+
router
,
headers
=
DEFAULT_REQUEST_HEADERS
)
response
=
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
))
jsonschema
.
validate
(
response
,
interfaces_list_schema
)
assert
response
# at least shouldn't be empty
def
test_router_bgp_route
(
client_with_mocked_data
):
bgp_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
description
"
:
{
"
type
"
:
"
string
"
},
"
as
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
peer
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^\d+$
'
},
"
local
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^\d+$
'
},
},
"
required
"
:
[
"
peer
"
,
"
local
"
],
"
additionalProperties
"
:
False
},
},
"
required
"
:
[
"
description
"
,
"
as
"
],
"
additionalProperties
"
:
False
}
}
routers_with_bpg_configs
=
[
"
mx1.mil2.it.geant.net
"
,
"
mx1.vie.at.geant.net
"
,
"
mx1.fra.de.geant.net
"
,
"
mx1.ams.nl.geant.net
"
,
"
mx1.pra.cz.geant.net
"
,
"
mx1.dub.ie.geant.net
"
,
"
mx1.mad.es.geant.net
"
,
"
mx1.gen.ch.geant.net
"
,
"
mx1.mar.fr.geant.net
"
,
"
mx1.lon.uk.geant.net
"
]
for
router
in
_routers
(
client_with_mocked_data
):
if
router
not
in
routers_with_bpg_configs
:
continue
rv
=
client_with_mocked_data
.
post
(
"
/data/bgp/
"
+
router
,
headers
=
DEFAULT_REQUEST_HEADERS
)
response
=
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
))
jsonschema
.
validate
(
response
,
bgp_list_schema
)
assert
response
# at least shouldn't be empty
def
test_router_debug_data_route
(
client_with_mocked_data
):
debug_data_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
,
"
items
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
vrr
"
:
{
"
type
"
:
"
object
"
},
"
bgp
"
:
{
"
type
"
:
"
array
"
},
"
interfaces
"
:
{
"
type
"
:
"
array
"
}
},
"
required
"
:
[
"
vrr
"
,
"
bgp
"
,
"
interfaces
"
],
"
additionalProperties
"
:
False
}
}
for
router
in
_routers
(
client_with_mocked_data
):
rv
=
client_with_mocked_data
.
post
(
"
/data/debug-dump/
"
+
router
,
headers
=
DEFAULT_REQUEST_HEADERS
)
response
=
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
))
jsonschema
.
validate
(
response
,
debug_data_schema
)
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