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
0df8b3b4
Commit
0df8b3b4
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
move Client._send_request tests to seperate file
parent
c6ea9b46
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_client_responses.py
+189
-0
189 additions, 0 deletions
tests/test_client_responses.py
with
189 additions
and
0 deletions
tests/test_client_responses.py
0 → 100644
+
189
−
0
View file @
0df8b3b4
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
# support both Python2 and 3
"""
test_client_responses.py
Test for PyOTRS using **responses**
"""
# make sure (early) that parent dir (main app) is in path
import
unittest2
as
unittest
import
responses
import
requests
from
pyotrs
import
Client
# noqa
class
SendRequestResponsesTests
(
unittest
.
TestCase
):
"""
These test check both _send_request and _build_url
"""
def
test__sr_session_create
(
self
):
"""
Test _send_request session_create - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
SessionCreate
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
POST
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Session
'
,
json
=
{
u
'
SessionID
'
:
u
'
tMtTFDg1PxCX51dWnjue4W5oQtNsFd0k
'
},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
UserLogin
"
:
"
u-foo
"
,
"
Password
"
:
"
p-bar
"
})
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_create
(
self
):
"""
Test _send_request ticket_create - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketCreate
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
POST
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Ticket
'
,
json
=
{
u
'
ArticleID
'
:
u
'
2
'
,
u
'
TicketID
'
:
u
'
2
'
,
u
'
TicketNumber
'
:
u
'
000001
'
},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
bar
"
:
"
ticket-create
"
})
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_get
(
self
):
"""
Test _send_request ticket_get - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketGet
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
GET
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Ticket/1
'
,
json
=
{
u
'
Ticket
'
:
[{
u
'
Age
'
:
24040576
,
u
'
ArchiveFlag
'
:
u
'
n
'
,
u
'
ChangeBy
'
:
u
'
1
'
,
u
'
Changed
'
:
u
'
2016-04-13 20:41:19
'
,
u
'
CreateBy
'
:
u
'
1
'
,
u
'
StateType
'
:
u
'
open
'
,
u
'
TicketID
'
:
u
'
1
'
,
u
'
TicketNumber
'
:
u
'
2015071510123456
'
,
u
'
Title
'
:
u
'
Welcome to OTRS!
'
,
u
'
Type
'
:
u
'
Unclassified
'
,
u
'
TypeID
'
:
1
,
u
'
UnlockTimeout
'
:
u
'
0
'
,
u
'
UntilTime
'
:
0
}]},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
bla
"
:
"
ticket-get
"
},
ticket_id
=
1
)
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_get_list
(
self
):
"""
Test _send_request ticket_get - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketGetList
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
GET
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/TicketList
'
,
json
=
{
u
'
Ticket
'
:
[{
u
'
Age
'
:
24040576
,
u
'
ArchiveFlag
'
:
u
'
n
'
,
u
'
ChangeBy
'
:
u
'
1
'
,
u
'
Changed
'
:
u
'
2016-04-13 20:41:19
'
,
u
'
CreateBy
'
:
u
'
1
'
,
u
'
StateType
'
:
u
'
open
'
,
u
'
TicketID
'
:
u
'
1
'
,
u
'
TicketNumber
'
:
u
'
2015071510123456
'
,
u
'
Title
'
:
u
'
Welcome to OTRS!
'
,
u
'
Type
'
:
u
'
Unclassified
'
,
u
'
TypeID
'
:
1
,
u
'
UnlockTimeout
'
:
u
'
0
'
,
u
'
UntilTime
'
:
0
}]},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
bla
"
:
"
ticket-get
"
})
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_search
(
self
):
"""
Test _send_request ticket_search - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketSearch
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
GET
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Ticket
'
,
json
=
{
u
'
TicketID
'
:
[
u
'
1
'
]},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
bla
"
:
"
ticket-search
"
})
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_update
(
self
):
"""
Test _send_request ticket_update - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketUpdate
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
PATCH
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Ticket/1
'
,
json
=
{
u
'
TicketID
'
:
u
'
9
'
,
u
'
TicketNumber
'
:
u
'
000008
'
},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
{
"
alb
"
:
"
ticket-update
"
},
ticket_id
=
1
)
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
test__sr_ticket_update_with_article
(
self
):
"""
Test _send_request ticket_update with article - mocked
"""
obj
=
Client
(
baseurl
=
"
http://fqdn
"
,
webservicename
=
"
GenericTicketConnectorREST
"
)
obj
.
operation
=
"
TicketUpdate
"
obj
.
_result_type
=
obj
.
operation_map
[
obj
.
operation
][
"
ResultType
"
]
art
=
{
'
Article
'
:
{
'
Subject
'
:
'
Dümmy Subject
'
,
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
TimeUnit
'
:
0
,
'
MimeType
'
:
'
text/plain
'
,
'
Charset
'
:
'
UTF8
'
}}
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
True
)
as
rsps
:
rsps
.
add
(
responses
.
PATCH
,
'
http://fqdn/otrs/nph-genericinterface.pl/Webservice/
'
'
GenericTicketConnectorREST/Ticket/2
'
,
json
=
{
u
'
ArticleID
'
:
u
'
2
'
,
u
'
TicketID
'
:
u
'
2
'
,
u
'
TicketNumber
'
:
u
'
000002
'
},
status
=
200
,
content_type
=
'
application/json
'
)
result
=
obj
.
_send_request
(
payload
=
art
,
ticket_id
=
2
)
self
.
assertIsInstance
(
result
,
requests
.
Response
)
def
main
():
unittest
.
main
()
if
__name__
==
'
__main__
'
:
main
()
# EOF
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