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
9059aa21
Commit
9059aa21
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
fix #4 by adding a customizable field
parent
1f5af24b
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
+16
-6
16 additions, 6 deletions
pyotrs/lib.py
tests/test_article.py
+23
-0
23 additions, 0 deletions
tests/test_article.py
with
39 additions
and
6 deletions
pyotrs/lib.py
+
16
−
6
View file @
9059aa21
...
...
@@ -117,16 +117,26 @@ class Article(object):
else
:
return
[]
def
validate
(
self
):
def
validate
(
self
,
validation_map
=
None
):
"""
validate data against a mapping dict - if a key is not present
then set it with a default value according to dict
Args:
validation_map (dict): A mapping for all Article fields that have to be set
During validation every required field that is not set will be set to
a default value specified in this dict
.. note::
There is also a blacklist (fields to be removed) but this is currently
hardcoded to *list_dynamic_fields* and *list_attachments*
"""
validation_map
=
{
"
Body
"
:
"
API created Article Body
"
,
"
Charset
"
:
"
UTF8
"
,
"
MimeType
"
:
"
text/plain
"
,
"
Subject
"
:
"
API created Article
"
,
"
TimeUnit
"
:
0
}
if
not
validation_map
:
validation_map
=
{
"
Body
"
:
"
API created Article Body
"
,
"
Charset
"
:
"
UTF8
"
,
"
MimeType
"
:
"
text/plain
"
,
"
Subject
"
:
"
API created Article
"
,
"
TimeUnit
"
:
0
}
dct
=
self
.
__dict__
...
...
This diff is collapsed.
Click to expand it.
tests/test_article.py
+
23
−
0
View file @
9059aa21
...
...
@@ -306,6 +306,29 @@ class ArticleTests(unittest.TestCase):
art
.
validate
()
self
.
assertDictEqual
(
art
.
to_dct
(),
expected_validated
)
def
test_validation_custom
(
self
):
"""
Article validation; blacklisted fields should be removed, others should be added
"""
custom_validation
=
{
"
Body
"
:
"
API created Article Body
"
,
"
Charset
"
:
"
UTF8
"
,
"
SpecialField
"
:
"
SpecialValue
"
,
"
MimeType
"
:
"
text/plain
"
,
"
Subject
"
:
"
API created Article
"
,
"
TimeUnit
"
:
0
}
expected_validated
=
{
'
Article
'
:
{
'
Subject
'
:
'
This Article only has Subject
'
,
'
Body
'
:
'
and Body and needs to be completed.
'
,
'
TimeUnit
'
:
0
,
'
MimeType
'
:
'
text/plain
'
,
'
Charset
'
:
'
UTF8
'
,
'
SpecialField
'
:
'
SpecialValue
'
}}
art
=
Article
({
'
Subject
'
:
'
This Article only has Subject
'
,
'
Body
'
:
'
and Body and needs to be completed.
'
})
art
.
validate
(
validation_map
=
custom_validation
)
self
.
assertDictEqual
(
art
.
to_dct
(),
expected_validated
)
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