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
3529dfde
Commit
3529dfde
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
add dynamic field and article get method
parent
fab20de4
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
+34
-3
34 additions, 3 deletions
pyotrs/lib.py
tests/test_ticket.py
+280
-15
280 additions, 15 deletions
tests/test_ticket.py
with
314 additions
and
18 deletions
pyotrs/lib.py
+
34
−
3
View file @
3529dfde
...
...
@@ -72,7 +72,6 @@ class HTTPError(PyOTRSError):
class
Article
(
object
):
"""
PyOTRS Article class
"""
def
__init__
(
self
,
dct
):
self
.
__dict__
=
dct
...
...
@@ -196,7 +195,6 @@ class Article(object):
class
Attachment
(
object
):
"""
PyOTRS Attachment class
"""
def
__init__
(
self
,
dct
):
self
.
__dict__
=
dct
...
...
@@ -349,7 +347,6 @@ class DynamicField(object):
class
Ticket
(
object
):
"""
PyOTRS Ticket class
"""
def
__init__
(
self
,
dct
):
for
key
,
value
in
dct
.
items
():
if
isinstance
(
value
,
dict
):
...
...
@@ -402,6 +399,40 @@ class Ticket(object):
"""
return
{
"
Ticket
"
:
self
.
__dict__
}
def
article_get
(
self
,
article_id
):
"""
article_get
Args:
article_id (str): Article ID as either int or str
Returns:
**Article** or **None**
"""
result
=
[
x
for
x
in
self
.
list_articles
if
x
.
ArticleID
==
"
{0}
"
.
format
(
article_id
)]
if
result
:
return
result
[
0
]
else
:
return
None
def
dynamic_field_get
(
self
,
df_name
):
"""
dynamic_field_get
Args:
df_name (str): Name of DynamicField to retrieve
Returns:
**DynamicField** or **None**
"""
result
=
[
x
for
x
in
self
.
list_dynamic_fields
if
x
.
name
==
df_name
]
if
result
:
return
result
[
0
]
else
:
return
None
@classmethod
def
create_basic
(
cls
,
Title
=
None
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_ticket.py
+
280
−
15
View file @
3529dfde
...
...
@@ -12,10 +12,13 @@ import unittest2 as unittest
import
datetime
from
pyotrs.lib
import
Ticket
# noqa
from
pyotrs.lib
import
DynamicField
# noqa
from
pyotrs.lib
import
Article
# noqa
from
pyotrs.lib
import
ArgumentMissingError
# noqa
class
TicketTests
(
unittest
.
TestCase
):
def
test_init
(
self
):
tic
=
Ticket
(
dct
=
{
'
Title
'
:
'
foo
'
})
self
.
assertIsInstance
(
tic
,
Ticket
)
...
...
@@ -55,33 +58,295 @@ class TicketTests(unittest.TestCase):
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
DynamicField
'
:
[
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assertEqual
(
tic
.
__repr__
(),
'
<Ticket>
'
)
self
.
assertEqual
(
tic
.
list_articles
[
0
].
__repr__
(),
"
<ArticleID: 30 (1 Attachment)>
"
)
def
test_dynamic_field_get_none
(
self
):
tic_dct
=
{
'
TypeID
'
:
'
1
'
,
'
Title
'
:
'
Baesic Ticket
'
,
'
Article
'
:
[{
'
Age
'
:
82383
,
'
AgeTimeUnix
'
:
82383
,
'
ArticleID
'
:
'
30
'
,
'
ArticleType
'
:
'
webrequest
'
,
'
ArticleTypeID
'
:
'
8
'
,
'
Attachment
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
'
Content
'
:
'
mFyC
'
,
'
ContentAlternative
'
:
''
,
'
ContentID
'
:
''
,
'
ContentType
'
:
'
text/plain
'
,
'
Disposition
'
:
'
attachment
'
,
'
Filename
'
:
'
foo.txt
'
,
'
Filesize
'
:
'
3 Bytes
'
,
'
FilesizeRaw
'
:
'
3
'
}
],
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assertIsNone
(
tic
.
dynamic_field_get
(
"
rgiosregoisrengi
"
))
def
test_dynamic_field_get_success
(
self
):
tic_dct
=
{
'
TypeID
'
:
'
1
'
,
'
Title
'
:
'
Baesic Ticket
'
,
'
Article
'
:
[{
'
Age
'
:
82383
,
'
AgeTimeUnix
'
:
82383
,
'
ArticleID
'
:
'
30
'
,
'
ArticleType
'
:
'
webrequest
'
,
'
ArticleTypeID
'
:
'
8
'
,
'
Attachment
'
:
[
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
'
Content
'
:
'
mFyC
'
,
'
ContentAlternative
'
:
''
,
'
ContentID
'
:
''
,
'
ContentType
'
:
'
text/plain
'
,
'
Disposition
'
:
'
attachment
'
,
'
Filename
'
:
'
foo.txt
'
,
'
Filesize
'
:
'
3 Bytes
'
,
'
FilesizeRaw
'
:
'
3
'
}
],
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assertIsInstance
(
tic
.
dynamic_field_get
(
"
firstname
"
),
DynamicField
)
self
.
assertEqual
(
tic
.
dynamic_field_get
(
"
firstname
"
).
value
,
'
Jane
'
)
def
test_article_get_none
(
self
):
tic_dct
=
{
'
TypeID
'
:
'
1
'
,
'
Title
'
:
'
Baesic Ticket
'
,
'
Article
'
:
[{
'
Age
'
:
82383
,
'
AgeTimeUnix
'
:
82383
,
'
ArticleID
'
:
'
30
'
,
'
ArticleType
'
:
'
webrequest
'
,
'
ArticleTypeID
'
:
'
8
'
,
'
Attachment
'
:
[
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
'
Content
'
:
'
mFyC
'
,
'
ContentAlternative
'
:
''
,
'
ContentID
'
:
''
,
'
ContentType
'
:
'
text/plain
'
,
'
Disposition
'
:
'
attachment
'
,
'
Filename
'
:
'
foo.txt
'
,
'
Filesize
'
:
'
3 Bytes
'
,
'
FilesizeRaw
'
:
'
3
'
}
],
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assertIsNone
(
tic
.
article_get
(
"
666
"
))
def
test_article_get_str_success
(
self
):
tic_dct
=
{
'
TypeID
'
:
'
1
'
,
'
Title
'
:
'
Baesic Ticket
'
,
'
Article
'
:
[{
'
Age
'
:
82383
,
'
AgeTimeUnix
'
:
82383
,
'
ArticleID
'
:
'
30
'
,
'
ArticleType
'
:
'
webrequest
'
,
'
ArticleTypeID
'
:
'
8
'
,
'
Attachment
'
:
[
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
'
Content
'
:
'
mFyC
'
,
'
ContentAlternative
'
:
''
,
'
ContentID
'
:
''
,
'
ContentType
'
:
'
text/plain
'
,
'
Disposition
'
:
'
attachment
'
,
'
Filename
'
:
'
foo.txt
'
,
'
Filesize
'
:
'
3 Bytes
'
,
'
FilesizeRaw
'
:
'
3
'
}
],
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}]
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assertIsInstance
(
tic
.
article_get
(
"
30
"
),
Article
)
self
.
assertEqual
(
tic
.
article_get
(
"
30
"
).
ArticleType
,
'
webrequest
'
)
def
test_article_get_int_success
(
self
):
tic_dct
=
{
'
TypeID
'
:
'
1
'
,
'
Title
'
:
'
Baesic Ticket
'
,
'
Article
'
:
[{
'
Age
'
:
82383
,
'
AgeTimeUnix
'
:
82383
,
'
ArticleID
'
:
'
30
'
,
'
ArticleType
'
:
'
webrequest
'
,
'
ArticleTypeID
'
:
'
8
'
,
'
Attachment
'
:
[
{
'
Content
'
:
'
mFyC
'
,
'
ContentAlternative
'
:
''
,
'
ContentID
'
:
''
,
'
ContentType
'
:
'
text/plain
'
,
'
Disposition
'
:
'
attachment
'
,
'
Filename
'
:
'
foo.txt
'
,
'
Filesize
'
:
'
3 Bytes
'
,
'
FilesizeRaw
'
:
'
3
'
}
],
'
Body
'
:
'
Hallo Bjørn,
\n
[kt]
\n\n
-- The End
'
,
'
Cc
'
:
''
,
'
CustomerID
'
:
None
,
'
CustomerUserID
'
:
None
,
'
EscalationResponseTime
'
:
'
0
'
,
'
EscalationSolutionTime
'
:
'
0
'
}],
'
DynamicField
'
:
[
{
'
Name
'
:
'
ProcessManagementActivityID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
ProcessManagementProcessID
'
,
'
Value
'
:
None
},
{
'
Name
'
:
'
firstname
'
,
'
Value
'
:
'
Jane
'
},
{
'
Name
'
:
'
lastname
'
,
'
Value
'
:
'
Doe
'
}
],
}
tic
=
Ticket
(
tic_dct
)
self
.
assertIsInstance
(
tic
,
Ticket
)
self
.
assert
Equal
(
tic
.
__repr__
(),
'
<Ticket>
'
)
self
.
assertEqual
(
tic
.
list_
article
s
[
0
].
__repr__
(),
"
<ArticleID: 30 (1 Attachment)>
"
)
self
.
assert
IsInstance
(
tic
.
article_get
(
30
),
Article
)
self
.
assertEqual
(
tic
.
article
_get
(
30
).
ArticleType
,
'
webrequest
'
)
def
test_create_basic_no_title
(
self
):
self
.
assertRaisesRegex
(
ArgumentMissingError
,
'
Title is required
'
,
Ticket
.
create_basic
)
...
...
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