Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
it-bott-integrasjoner
cim-client
Commits
b43b02f9
Commit
b43b02f9
authored
May 05, 2021
by
Trond Aasan
Browse files
CIM-58 Raise TypeError if person isn't an instance of PersonBase
parent
a59c9319
Pipeline
#79442
passed with stages
in 2 minutes and 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cim_client/client.py
View file @
b43b02f9
...
...
@@ -38,6 +38,9 @@ def _serialise_upsert_person(
A phone field is reset when the corresponding key is omitted.
Neither "" nor null are allowed values.
"""
if
not
isinstance
(
person
,
PersonBase
):
raise
TypeError
(
"Expected person to be an instance of PersonBase"
)
empty_phone_fields
=
{
f
for
f
in
{
...
...
tests/test_client.py
View file @
b43b02f9
...
...
@@ -158,6 +158,22 @@ def test_upsert_persons_many(client, john_doe, jane_doe, requests_mock):
assert
response
.
status_code
==
200
def
test_upsert_persons_one_wrong_type_raises_type_error
(
client
,
john_doe
,
requests_mock
):
with
pytest
.
raises
(
TypeError
):
client
.
upsert_persons
(
"Sesam, sesam"
)
# type: ignore
def
test_upsert_persons_many_wrong_type_raises_type_error
(
client
,
john_doe
,
requests_mock
):
data
=
[
Person
.
from_dict
(
john_doe
),
12
]
with
pytest
.
raises
(
TypeError
):
client
.
upsert_persons
(
data
)
# type: ignore
def
test_upsert_persons_failure_400
(
client
,
john_doe
,
requests_mock
):
"""Ensure 400 raises an error"""
requests_mock
.
post
(
client
.
endpoints
.
upsert_persons
(),
status_code
=
400
)
...
...
@@ -234,3 +250,9 @@ def test__serialise_upsert_person():
assert
"secret_number"
not
in
keys
assert
"private_mobile"
not
in
keys
assert
"private_phone"
not
in
keys
def
test__serialise_upsert_person_wrong_type_raises_type_error
():
p
=
"Hey babiluba"
with
pytest
.
raises
(
TypeError
):
_serialise_upsert_person
(
p
)
# type: ignore
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment