Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyOTRS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Coopdevs
Som Connexió
OTRS
PyOTRS
Commits
fe50adbc
Commit
fe50adbc
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
fix tests after type map change
parent
0423e0f5
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
pyotrs/lib.py
+1
-1
1 addition, 1 deletion
pyotrs/lib.py
tests/test_client.py
+48
-26
48 additions, 26 deletions
tests/test_client.py
with
49 additions
and
27 deletions
pyotrs/lib.py
+
1
−
1
View file @
fe50adbc
...
...
@@ -451,7 +451,7 @@ class Ticket(object):
"""
result
=
[
x
for
x
in
self
.
list_dynamic_fields
if
x
.
name
==
df_name
]
result
=
[
x
for
x
in
self
.
list_dynamic_fields
if
x
.
name
==
"
{0}
"
.
format
(
df_name
)
]
if
result
:
return
result
[
0
]
else
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_client.py
+
48
−
26
View file @
fe50adbc
...
...
@@ -101,18 +101,31 @@ class ClientTests(unittest.TestCase):
def
test_init_operation_map_override
(
self
):
operation_map_custom
=
{
'
SessionCreate
'
:
{
'
RequestMethod
'
:
'
POST
'
,
'
Route
'
:
'
/Session
'
},
'
TicketCreate
'
:
{
'
RequestMethod
'
:
'
POST
'
,
'
Route
'
:
'
/Ticket
'
},
'
TicketGet
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
},
'
TicketGetList
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/TicketList
'
},
'
TicketSearch
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/Ticket
'
},
'
TicketUpdate
'
:
{
'
RequestMethod
'
:
'
PATCH
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
}
'
SessionCreate
'
:
{
'
RequestMethod
'
:
'
POST
'
,
'
Route
'
:
'
/Session
'
,
'
Result
'
:
'
SessionID
'
},
'
TicketCreate
'
:
{
'
RequestMethod
'
:
'
POST
'
,
'
Route
'
:
'
/Ticket
'
,
'
Result
'
:
'
TicketID
'
},
'
TicketGet
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
,
'
Result
'
:
'
Ticket
'
},
'
TicketGetList
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/TicketList
'
,
'
Result
'
:
'
Ticket
'
},
'
TicketSearch
'
:
{
'
RequestMethod
'
:
'
GET
'
,
'
Route
'
:
'
/Ticket
'
,
'
Result
'
:
'
TicketID
'
},
'
TicketUpdate
'
:
{
'
RequestMethod
'
:
'
PATCH
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
,
'
Result
'
:
'
TicketID
'
}
}
client
=
Client
(
baseurl
=
"
http://fqdn/
"
,
webservicename
=
"
foo
"
,
operation_map
=
operation_map_custom
)
self
.
assertIsInstance
(
client
,
Client
)
"""
def test_init_type_map_override(self):
type_map_custom = {
'
SessionCreate
'
:
'
SessionID
'
,
...
...
@@ -126,6 +139,7 @@ class ClientTests(unittest.TestCase):
webservicename=
"
foo
"
,
type_map=type_map_custom)
self.assertIsInstance(client, Client)
"""
def
test_session_check_is_valid_no_session_id_error
(
self
):
"""
Test
"""
...
...
@@ -991,7 +1005,7 @@ class ClientTests(unittest.TestCase):
"""
Test _send_request no payload
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
self
.
assertRaisesRegex
(
ArgumentMissingError
,
'
payload
'
,
...
...
@@ -1001,24 +1015,24 @@ class ClientTests(unittest.TestCase):
"""
Test _send_request with invalid http method
"""
operation_mapping_invalid
=
{
'
SessionCreate
'
:
{
'
Result
Type
'
:
'
SessionID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Session
'
},
{
'
Result
'
:
'
SessionID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Session
'
},
'
TicketCreate
'
:
{
'
Result
Type
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket
'
},
{
'
Result
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket
'
},
'
TicketGet
'
:
{
'
Result
Type
'
:
'
Ticket
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
},
{
'
Result
'
:
'
Ticket
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
},
'
TicketGetList
'
:
{
'
Result
Type
'
:
'
Ticket
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/TicketList
'
},
{
'
Result
'
:
'
Ticket
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/TicketList
'
},
'
TicketSearch
'
:
{
'
Result
Type
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket
'
},
{
'
Result
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket
'
},
'
TicketUpdate
'
:
{
'
Result
Type
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
}
{
'
Result
'
:
'
TicketID
'
,
'
RequestMethod
'
:
'
FOOBAR
'
,
'
Route
'
:
'
/Ticket/:TicketID
'
}
}
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
,
operation_map
=
operation_mapping_invalid
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
self
.
assertRaisesRegex
(
ValueError
,
'
invalid http_method
'
,
...
...
@@ -1030,7 +1044,7 @@ class ClientTests(unittest.TestCase):
"""
Tests _send_request ok
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mock_requests_req
.
return_value
.
result
=
True
mock_requests_req
.
return_value
.
status_code
=
200
...
...
@@ -1046,7 +1060,7 @@ class ClientTests(unittest.TestCase):
"""
Tests _send_request fail http status code not 200
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mock_requests_req
.
return_value
.
result
=
False
mock_requests_req
.
return_value
.
status_code
=
500
...
...
@@ -1064,7 +1078,7 @@ class ClientTests(unittest.TestCase):
"""
Tests _send_request fail
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mock_requests_req
.
side_effect
=
Exception
(
"
Some Exception
"
)
...
...
@@ -1088,7 +1102,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with an invalid operation
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
DoTheMagicRainDance
"
# obj._result_type = obj.
type
_map[obj.operation]
# obj._result_type = obj.
operation
_map[obj.operation]
["Result"]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1103,7 +1117,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with SessionCreate
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
SessionCreate
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1117,7 +1131,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketGet
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketGetList
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
tkt
=
{
u
'
Ticket
'
:
[{
u
'
Age
'
:
24040576
,
u
'
CreateBy
'
:
u
'
1
'
,
...
...
@@ -1142,7 +1156,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketCreate
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketCreate
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1161,7 +1175,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketUpdate
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketCreate
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1176,7 +1190,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketSearch
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1190,7 +1204,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketSearch with empty result
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1204,7 +1218,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketSearch with a nonsence response
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
mocked_response
=
mock
.
Mock
(
spec
=
requests
.
Response
)
mocked_response
.
status_code
=
200
...
...
@@ -1221,7 +1235,7 @@ class ClientTests(unittest.TestCase):
"""
Test _validate_response with TicketGet when an error is received
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketGet
"
obj
.
_result_type
=
obj
.
type
_map
[
obj
.
operation
]
obj
.
_result_type
=
obj
.
operation
_map
[
obj
.
operation
]
[
"
Result
"
]
tkt
=
{
"
Error
"
:
{
"
ErrorMessage
"
:
"
TicketGet: Authorization failing!
"
,
"
ErrorCode
"
:
"
TicketGet.AuthFail
"
}}
...
...
@@ -1235,6 +1249,14 @@ class ClientTests(unittest.TestCase):
obj
.
_parse_and_validate_response
,
mocked_response
)
def
test_link_add_foo
(
self
):
"""
Test link_add foo
"""
obj
=
Client
(
baseurl
=
"
http://localhost
"
,
webservicename
=
"
foo
"
)
obj
.
operation
=
"
TicketGet
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
Result
"
]
self
.
assertTrue
(
True
)
def
main
():
unittest
.
main
()
...
...
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