Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue 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
Anders Harrisson
csentry
Commits
230f3234
Commit
230f3234
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add /network/domains endpoint
parent
23448e02
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/api/network.py
+25
-0
25 additions, 0 deletions
app/api/network.py
tests/functional/test_api.py
+29
-0
29 additions, 0 deletions
tests/functional/test_api.py
with
54 additions
and
0 deletions
app/api/network.py
+
25
−
0
View file @
230f3234
...
@@ -164,3 +164,28 @@ def create_macs():
...
@@ -164,3 +164,28 @@ def create_macs():
"""
"""
return
create_generic_model
(
models
.
Mac
,
return
create_generic_model
(
models
.
Mac
,
mandatory_fields
=
(
'
address
'
,))
mandatory_fields
=
(
'
address
'
,))
@bp.route
(
'
/domains
'
)
@jwt_required
def
get_domains
():
"""
Return domains
.. :quickref: Network; Get domains
"""
return
get_generic_model
(
models
.
Domain
,
order_by
=
models
.
Domain
.
name
)
@bp.route
(
'
/domains
'
,
methods
=
[
'
POST
'
])
@jwt_required
@jwt_groups_accepted
(
'
admin
'
)
def
create_domain
():
"""
Create a new domain
.. :quickref: Network; Create new domain
:jsonparam name: domain name
"""
return
create_generic_model
(
models
.
Domain
,
mandatory_fields
=
(
'
name
'
,))
This diff is collapsed.
Click to expand it.
tests/functional/test_api.py
+
29
−
0
View file @
230f3234
...
@@ -27,6 +27,7 @@ ENDPOINT_MODEL = {
...
@@ -27,6 +27,7 @@ ENDPOINT_MODEL = {
'
network/interfaces
'
:
models
.
Interface
,
'
network/interfaces
'
:
models
.
Interface
,
'
network/hosts
'
:
models
.
Host
,
'
network/hosts
'
:
models
.
Host
,
'
network/macs
'
:
models
.
Mac
,
'
network/macs
'
:
models
.
Mac
,
'
network/domains
'
:
models
.
Domain
,
}
}
GENERIC_GET_ENDPOINTS
=
[
key
for
key
in
ENDPOINT_MODEL
.
keys
()
GENERIC_GET_ENDPOINTS
=
[
key
for
key
in
ENDPOINT_MODEL
.
keys
()
if
key
.
startswith
(
'
inventory
'
)
and
key
!=
'
inventory/items
'
]
if
key
.
startswith
(
'
inventory
'
)
and
key
!=
'
inventory/items
'
]
...
@@ -765,3 +766,31 @@ def test_get_user_profile(client, readonly_token):
...
@@ -765,3 +766,31 @@ def test_get_user_profile(client, readonly_token):
assert
user
[
'
username
'
]
==
'
user_ro
'
assert
user
[
'
username
'
]
==
'
user_ro
'
assert
user
[
'
display_name
'
]
==
'
User RO
'
assert
user
[
'
display_name
'
]
==
'
User RO
'
assert
user
[
'
email
'
]
==
'
user_ro@example.com
'
assert
user
[
'
email
'
]
==
'
user_ro@example.com
'
def
test_get_domains
(
client
,
domain_factory
,
readonly_token
):
# Create some domains
domain1
=
domain_factory
()
domain2
=
domain_factory
()
response
=
get
(
client
,
f
'
{
API_URL
}
/network/domains
'
,
token
=
readonly_token
)
assert
response
.
status_code
==
200
assert
len
(
response
.
json
)
==
2
check_input_is_subset_of_response
(
response
,
(
domain1
.
to_dict
(),
domain2
.
to_dict
()))
def
test_create_domain
(
client
,
admin_token
):
# check that name is mandatory
response
=
post
(
client
,
f
'
{
API_URL
}
/network/domains
'
,
data
=
{},
token
=
admin_token
)
check_response_message
(
response
,
"
Missing mandatory field
'
name
'"
,
422
)
data
=
{
'
name
'
:
'
tn.esss.lu.se
'
}
response
=
post
(
client
,
f
'
{
API_URL
}
/network/domains
'
,
data
=
data
,
token
=
admin_token
)
assert
response
.
status_code
==
201
assert
{
'
id
'
,
'
name
'
,
'
scopes
'
,
'
networks
'
,
'
created_at
'
,
'
updated_at
'
,
'
user
'
}
==
set
(
response
.
json
.
keys
())
assert
response
.
json
[
'
name
'
]
==
data
[
'
name
'
]
# Check that name shall be unique
response
=
post
(
client
,
f
'
{
API_URL
}
/network/domains
'
,
data
=
data
,
token
=
admin_token
)
check_response_message
(
response
,
'
(psycopg2.IntegrityError) duplicate key value violates unique constraint
'
,
422
)
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