コード例 #1
0
ファイル: parser.py プロジェクト: sonyaya/python-rtkit
    def test_parse_kw_syntax_err(self):
        body = '''RT/3.8.10 409 Syntax Error

# queue: You may not create requests in that queue.
'''
        parsed = RTParser.parse(body, RTParser.decode_comment)
        self.assertEqual(parsed, [[('queue', 'You may not create requests in that queue.')]])
コード例 #2
0
ファイル: parser.py プロジェクト: webknjaz/python-rtkit
    def test_parse_kw_syntax_err(self):
        body = '''RT/3.8.10 409 Syntax Error

# queue: You may not create requests in that queue.
'''
        parsed = RTParser.parse(body, RTParser.decode_comment)
        self.assertEqual(parsed, [[('queue', 'You may not create requests in that queue.')]])
コード例 #3
0
 def __init__(self, request, response):
     self.headers = response.headers
     self.body = response.read()
     self.status_int = response.code
     self.status = '{0} {1}'.format(response.code, response.msg)
     self.logger = logging.getLogger('rtkit')
     self.logger.info(request.get_method())
     self.logger.info(request.get_full_url())
     self.logger.debug('HTTP_STATUS: {0}'.format(self.status))
     r = RTParser.HEADER.match(self.body)
     if r:
         self.status = r.group('s')
         self.status_int = int(r.group('i'))
     else:
         self.logger.error('"{0}" is not valid'.format(self.body))
         self.status = self.body
         self.status_int = 500
     self.logger.debug('%r' % self.body)
     try:
         decoder = RTParser.decode
         if self.status_int == 409:
             decoder = RTParser.decode_comment
         self.parsed = RTParser.parse(self.body, decoder)
     except errors.RTResourceError as e:
         self.parsed = []
         self.status_int = e.status_int
         self.status = '{0} {1}'.format(e.status_int, e.msg)
     self.logger.debug('RESOURCE_STATUS: {0}'.format(self.status))
     self.logger.info(self.parsed)
コード例 #4
0
ファイル: parser.py プロジェクト: webknjaz/python-rtkit
    def test_vertical_tab(self):
        body = '''RT/3.8.7 200 Ok
Field: first line
       second\vline
       third line
'''
        parsed = RTParser.parse(body, RTParser.decode)
        self.assertEqual(parsed, [[('Field', 'first line\nsecond\x0bline\nthird line')]])
コード例 #5
0
    def test_vertical_tab(self):
        body = '''RT/3.8.7 200 Ok
Field: first line
       second\vline
       third line
'''
        parsed = RTParser.parse(body, RTParser.decode)
        self.assertEqual(
            parsed, [[('Field', 'first line\nsecond\x0bline\nthird line')]])
コード例 #6
0
ファイル: mock.py プロジェクト: Tojaj/python-rtkit
def create_tkt():
    form = dict(
        RTParser.parse(request.form.get('content', ''), RTParser.decode)[0])
    if form['Queue'] == '2':
        body = 'RT/3.8.10 200 Ok\n\n# Could not create ticket.\n# Could not create ticket. Queue not set\n\n'
    elif form['Queue'] == '3':
        body = "RT/3.8.10 200 Ok\n\n# Could not create ticket.\n# No permission to create tickets in the queue '___Admin'\n\n"
    else:
        body = 'RT/3.8.10 200 Ok\n\n# Ticket 1 created.\n\n'
    response = make_response(body, 200)
    return response
コード例 #7
0
ファイル: parser.py プロジェクト: webknjaz/python-rtkit
    def test_parse_syntax_err(self):
        body = '''RT/3.6.6 409 Syntax Error

# Syntax error.

Queue: Vulnerabilities
CF-Priority: Low -Needs to be completed in > 30
>> CF-Is This Maintenance?: Not_maintenance
CF-Device or Area: My Device
Owner: jgreen
Text: I'm a thing
CF-Vulnerability Risk: Low
CF-Time Estimated: Days
CF-CVSS Score: 2.6
Subject: Test Vulnerability for Script Dev
'''
        parsed = RTParser.parse(body, RTParser.decode_comment)
        self.assertEqual(parsed, [[('CF-Is This Maintenance?', 'Not_maintenance')]])
コード例 #8
0
ファイル: parser.py プロジェクト: sonyaya/python-rtkit
    def test_parse_syntax_err(self):
        body = '''RT/3.6.6 409 Syntax Error

# Syntax error.

Queue: Vulnerabilities
CF-Priority: Low -Needs to be completed in > 30
>> CF-Is This Maintenance?: Not_maintenance
CF-Device or Area: My Device
Owner: jgreen
Text: I'm a thing
CF-Vulnerability Risk: Low
CF-Time Estimated: Days
CF-CVSS Score: 2.6
Subject: Test Vulnerability for Script Dev
'''
        parsed = RTParser.parse(body, RTParser.decode_comment)
        self.assertEqual(parsed, [[('CF-Is This Maintenance?', 'Not_maintenance')]])
コード例 #9
0
ファイル: mock.py プロジェクト: Tojaj/python-rtkit
def readupdate_tkt(tid):
    if request.method == 'GET':
        if tid == '2':
            body = 'RT/3.8.10 200 Ok\n\n# Ticket 2 does not exist.\n\n\n'
        elif tid == '3':
            body = 'RT/3.8.10 401 Credentials required\n'
        else:
            body = '''RT/3.8.10 200 Ok

id: ticket/1
Queue: General
Owner: Nobody
Creator: pyrtkit
Subject: pyrt-create4
Status: open
Priority: 5
InitialPriority: 0
FinalPriority: 0
Requestors:
Cc:
AdminCc:
Created: Sun Jul 03 10:48:57 2011
Starts: Not set
Started: Not set
Due: Not set
Resolved: Not set
Told: Wed Jul 06 12:58:00 2011
LastUpdated: Thu Jul 07 14:42:32 2011
TimeEstimated: 0
TimeWorked: 25 minutes
TimeLeft: 0


'''
    else:
        form = dict(
            RTParser.parse(request.form.get('content', ''),
                           RTParser.decode)[0])
        if form['Queue'] == '3':
            body = 'RT/3.8.10 409 Syntax Error\n\n# queue: You may not create requests in that queue.\n\n'
        else:
            body = ''
    response = make_response(body, 200)
    return response
コード例 #10
0
ファイル: resource.py プロジェクト: chasemp/python-rtkit
    def __init__(self, request, response):
        self.headers = response.headers
        """Headers as dict"""

        logging.debug('r>>>>>>>', response.read())
        self.body = response.read()
        logging.debug('b>>>>>>>', self.body)
        """Request Body"""

        self.status_int = response.code
        """Status Code"""

        self.status = '{0} {1}'.format(response.code, response.msg)
        """Status String"""

        self.logger = logging.getLogger('rtkit')
        """Logger"""

        self.logger.info(request.get_method())
        self.logger.info(request.get_full_url())
        self.logger.debug('HTTP_STATUS: {0}'.format(self.status))
        r = RTParser.HEADER.match(self.body)
        if r:
            self.status = r.group('s')
            self.status_int = int(r.group('i'))
        else:
            self.logger.error('"{0}" is not valid'.format(self.body))
            self.status = self.body
            self.status_int = 500
        self.logger.debug('%r' % self.body)

        self.parsed = None
        """A List of Tuples of  data"""
        try:
            decoder = RTParser.decode
            if self.status_int == 409:
                decoder = RTParser.decode_comment
            self.parsed = RTParser.parse(self.body, decoder)
        except errors.RTResourceError as e:
            self.parsed = []
            self.status_int = e.status_int
            self.status = '{0} {1}'.format(e.status_int, e.msg)
        self.logger.debug('RESOURCE_STATUS: {0}'.format(self.status))
        self.logger.info(self.parsed)
コード例 #11
0
ファイル: resource.py プロジェクト: chasemp/python-rtkit
    def __init__(self, request, response):
        self.headers = response.headers
        """Headers as dict"""

        logging.debug('r>>>>>>>', response.read())
        self.body = response.read()
        logging.debug('b>>>>>>>', self.body)
        """Request Body"""

        self.status_int = response.code
        """Status Code"""

        self.status = '{0} {1}'.format(response.code, response.msg)
        """Status String"""

        self.logger = logging.getLogger('rtkit')
        """Logger"""

        self.logger.info(request.get_method())
        self.logger.info(request.get_full_url())
        self.logger.debug('HTTP_STATUS: {0}'.format(self.status))
        r = RTParser.HEADER.match(self.body)
        if r:
            self.status = r.group('s')
            self.status_int = int(r.group('i'))
        else:
            self.logger.error('"{0}" is not valid'.format(self.body))
            self.status = self.body
            self.status_int = 500
        self.logger.debug('%r' % self.body)

        self.parsed = None
        """A List of Tuples of  data"""
        try:
            decoder = RTParser.decode
            if self.status_int == 409:
                decoder = RTParser.decode_comment
            self.parsed = RTParser.parse(self.body, decoder)
        except errors.RTResourceError as e:
            self.parsed = []
            self.status_int = e.status_int
            self.status = '{0} {1}'.format(e.status_int, e.msg)
        self.logger.debug('RESOURCE_STATUS: {0}'.format(self.status))
        self.logger.info(self.parsed)