This file is indexed.

/usr/lib/python3/dist-packages/trytond/tests/test_protocols.py is in tryton-server 4.6.3-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

import unittest
import json
import datetime
from decimal import Decimal

from trytond.protocols.jsonrpc import JSONEncoder, JSONDecoder, JSONRequest
from trytond.protocols.xmlrpc import client, XMLRequest


class JSONTestCase(unittest.TestCase):
    'Test JSON'

    def test_json_request(self):
        req = JSONRequest.from_values(
            data=b'{"method": "method", "params": ["foo", "bar"]}',
            content_type='text/json',
            )
        self.assertEqual(req.parsed_data,
            {'method': 'method', 'params': ['foo', 'bar']})
        self.assertEqual(req.rpc_method, 'method')
        self.assertEqual(req.rpc_params, ['foo', 'bar'])

    def dumps_loads(self, value):
        self.assertEqual(json.loads(
                json.dumps(value, cls=JSONEncoder),
                object_hook=JSONDecoder()), value)

    def test_datetime(self):
        'Test datetime'
        self.dumps_loads(datetime.datetime.now())

    def test_date(self):
        'Test date'
        self.dumps_loads(datetime.date.today())

    def test_time(self):
        'Test time'
        self.dumps_loads(datetime.datetime.now().time())

    def test_bytes(self):
        'Test bytes'
        self.dumps_loads(bytes(b'foo'))
        self.dumps_loads(bytearray(b'foo'))

    def test_decimal(self):
        'Test Decimal'
        self.dumps_loads(Decimal('3.141592653589793'))


class XMLTestCase(unittest.TestCase):
    'Test XML'

    def test_xml_request(self):
        req = XMLRequest.from_values(
            data=b"<?xml version='1.0'?>\n<methodCall>\n<methodName>method</methodName>\n<params>\n<param>\n<value><string>foo</string></value>\n</param>\n<param>\n<value><string>bar</string></value>\n</param>\n</params>\n</methodCall>\n",
            content_type='text/xml')
        self.assertEqual(req.parsed_data, (('foo', 'bar'), 'method'))
        self.assertEqual(req.rpc_method, 'method')
        self.assertEqual(req.rpc_params, ('foo', 'bar'))

    def dumps_loads(self, value):
        s = client.dumps((value,))
        result, _ = client.loads(s)
        result, = result
        self.assertEqual(value, result)

    def test_decimal(self):
        'Test Decimal'
        self.dumps_loads(Decimal('3.141592653589793'))

    def test_bytes(self):
        'Test bytes'
        self.dumps_loads(bytes(b'foo'))
        self.dumps_loads(bytearray(b'foo'))

    def test_date(self):
        'Test date'
        self.dumps_loads(datetime.date.today())

    def test_time(self):
        'Test time'
        self.dumps_loads(datetime.datetime.now().time())

    def test_none(self):
        'Test None'
        self.dumps_loads(None)


def suite():
    suite_ = unittest.TestSuite()
    suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(JSONTestCase))
    suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(XMLTestCase))
    return suite_