Newer
Older
from __future__ import unicode_literals # support both Python2 and 3
#
# Name: test_article.py
# Description: Test for PyOTRS Article class
#
# Author: robert.habermann@dlh.de
# Date: 2016-04-17
# make sure (early) that parent dir (main app) is in path
import os.path
import sys
import unittest2 as unittest
# from mock import MagicMock, patch
current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(current_path, os.pardir))
from pyotrs import Article # noqa
# from pyotrs.lib import NoBaseURL, NoWebServiceName, NoCredentials
# from pyotrs.lib import SessionCreateError, SessionIDFileError, OTRSAPIError, OTRSHTTPError
class ArticleTests(unittest.TestCase):
def test_dummy(self):
self.assertRegex(art.__repr__(), '<Article.*')
def test_dummy_to_dct(self):
expected = {'Article': {'Subject': 'Dümmy Subject',
'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End',
'TimeUnit': 0,
'MimeType': 'text/plain',
'Charset': 'UTF8'}}
self.assertDictEqual(art.to_dct(), expected)
def test_dummy_force_notify(self):
expected = {'Article': {'Subject': 'Dümmy Subject',
'Body': 'Hallo Bjørn,\n[kt]\n\n -- The End',
'TimeUnit': 0,
'MimeType': 'text/plain',
'Charset': 'UTF8',
"ForceNotificationToUserID": [1, 2]}}
art = Article._dummy_force_notify()
def test_validation(self):
expected = {'Article': {'Subject': 'This Article only has Subject',
'Body': 'and Body and needs to be completed.'}}
expected_validated = {'Article': {'Subject': 'This Article only has Subject',
'Body': 'and Body and needs to be completed.',
'TimeUnit': 0,
'MimeType': 'text/plain',
'Charset': 'UTF8'}}
art = Article({'Subject': 'This Article only has Subject',
'Body': 'and Body and needs to be completed.'})
self.assertIsInstance(art, Article)
self.assertDictEqual(art.to_dct(), expected)
art.validate()
self.assertDictEqual(art.to_dct(), expected_validated)
def main():
unittest.main()
if __name__ == '__main__':
main()
# EOF