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
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
ICS Control System Infrastructure
csentry
Commits
c29671e3
Commit
c29671e3
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Test TypeError in create_generic_model
parent
642a9b8c
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/api/main.py
+1
-1
1 addition, 1 deletion
app/api/main.py
tests/functional/test_api.py
+6
-0
6 additions, 0 deletions
tests/functional/test_api.py
with
7 additions
and
1 deletion
app/api/main.py
+
1
−
1
View file @
c29671e3
...
@@ -68,7 +68,7 @@ def create_generic_model(model, mandatory_fields=('name',)):
...
@@ -68,7 +68,7 @@ def create_generic_model(model, mandatory_fields=('name',)):
instance
=
model
(
**
data
)
instance
=
model
(
**
data
)
except
TypeError
as
e
:
except
TypeError
as
e
:
message
=
str
(
e
).
replace
(
'
__init__() got an
'
,
''
)
message
=
str
(
e
).
replace
(
'
__init__() got an
'
,
''
)
raise
utils
.
CSEntryError
(
message
)
raise
utils
.
CSEntryError
(
message
,
status_code
=
422
)
except
ValueError
as
e
:
except
ValueError
as
e
:
raise
utils
.
CSEntryError
(
str
(
e
),
status_code
=
422
)
raise
utils
.
CSEntryError
(
str
(
e
),
status_code
=
422
)
db
.
session
.
add
(
instance
)
db
.
session
.
add
(
instance
)
...
...
This diff is collapsed.
Click to expand it.
tests/functional/test_api.py
+
6
−
0
View file @
c29671e3
...
@@ -185,6 +185,12 @@ def test_create_generic_model(endpoint, client, user_token):
...
@@ -185,6 +185,12 @@ def test_create_generic_model(endpoint, client, user_token):
check_names
(
response
,
(
'
Foo
'
,
'
Bar
'
))
check_names
(
response
,
(
'
Foo
'
,
'
Bar
'
))
@pytest.mark.parametrize
(
'
endpoint
'
,
GENERIC_CREATE_ENDPOINTS
)
def
test_create_generic_model_invalid_param
(
endpoint
,
client
,
user_token
):
response
=
post
(
client
,
f
'
/api/
{
endpoint
}
'
,
data
=
{
'
name
'
:
'
foo
'
,
'
hello
'
:
'
world
'
},
token
=
user_token
)
check_response_message
(
response
,
"
unexpected keyword argument
'
hello
'"
,
422
)
def
test_create_item
(
client
,
user_token
):
def
test_create_item
(
client
,
user_token
):
# check that serial_number is mandatory
# check that serial_number is mandatory
response
=
post
(
client
,
'
/api/items
'
,
data
=
{},
token
=
user_token
)
response
=
post
(
client
,
'
/api/items
'
,
data
=
{},
token
=
user_token
)
...
...
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