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
66c09043
Commit
66c09043
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Raise 422 when creating item with invalid ICS id
parent
ef4fb50f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models.py
+2
-1
2 additions, 1 deletion
app/models.py
tests/functional/test_api.py
+7
-0
7 additions, 0 deletions
tests/functional/test_api.py
with
9 additions
and
1 deletion
app/models.py
+
2
−
1
View file @
66c09043
...
@@ -229,7 +229,8 @@ class Item(db.Model):
...
@@ -229,7 +229,8 @@ class Item(db.Model):
def
validate_ics_id
(
self
,
key
,
string
):
def
validate_ics_id
(
self
,
key
,
string
):
"""
Ensure the ICS id field matches the required format
"""
"""
Ensure the ICS id field matches the required format
"""
if
string
is
not
None
:
if
string
is
not
None
:
assert
ICS_ID_RE
.
fullmatch
(
string
)
is
not
None
if
ICS_ID_RE
.
fullmatch
(
string
)
is
None
:
raise
utils
.
InventoryError
(
'
ICS id shall match [A-Z]{3}[0-9]{3}
'
,
status_code
=
422
)
return
string
return
string
def
to_dict
(
self
):
def
to_dict
(
self
):
...
...
This diff is collapsed.
Click to expand it.
tests/functional/test_api.py
+
7
−
0
View file @
66c09043
...
@@ -214,6 +214,13 @@ def test_create_item(client, user_token):
...
@@ -214,6 +214,13 @@ def test_create_item(client, user_token):
check_items
(
response
,
(
data
,
data
,
data2
))
check_items
(
response
,
(
data
,
data
,
data2
))
def
test_create_item_invalid_ics_id
(
client
,
user_token
):
for
ics_id
in
(
'
foo
'
,
'
AAB1234
'
,
'
AZ02
'
,
'
WS007
'
,
'
AAA01
'
):
data
=
{
'
serial_number
'
:
'
123456
'
,
'
ics_id
'
:
ics_id
}
response
=
post
(
client
,
'
/api/items
'
,
data
=
data
,
token
=
user_token
)
check_response_message
(
response
,
'
ICS id shall match [A-Z]{3}[0-9]{3}
'
,
422
)
def
test_get_item_fail
(
client
,
session
,
readonly_token
):
def
test_get_item_fail
(
client
,
session
,
readonly_token
):
response
=
get
(
client
,
'
/api/items/50
'
,
token
=
readonly_token
)
response
=
get
(
client
,
'
/api/items/50
'
,
token
=
readonly_token
)
check_response_message
(
response
,
"
Item id
'
50
'
not found
"
,
404
)
check_response_message
(
response
,
"
Item id
'
50
'
not found
"
,
404
)
...
...
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