This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/modules/currency/tests/test_currency.py is in tryton-modules-currency 3.8.0-1.

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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# 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
from decimal import Decimal
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction


class CurrencyTestCase(ModuleTestCase):
    'Test Currency module'
    module = 'currency'

    def setUp(self):
        super(CurrencyTestCase, self).setUp()
        self.rate = POOL.get('currency.currency.rate')
        self.currency = POOL.get('currency.currency')
        self.date = POOL.get('ir.date')

    def get_currency(self, code):
        return self.currency.search([
            ('code', '=', code),
            ], limit=1)[0]

    def test0010currencies(self):
        'Create currencies'

        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu1, cu2 = self.currency.create([{
                        'name': 'cu1',
                        'symbol': 'cu1',
                        'code': 'cu1'
                        }, {
                        'name': 'cu2',
                        'symbol': 'cu2',
                        'code': 'cu2'
                        }])
            self.assert_(cu1)
            self.assert_(cu2)

            transaction.cursor.commit()

    def test0020mon_grouping(self):
        'Check grouping'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            cu1 = self.get_currency('cu1')

            self.assertRaises(Exception, self.currency.write, [cu1],
                {'mon_grouping': ''})

            self.assertRaises(Exception, self.currency.write, [cu1],
                {'mon_grouping': '[a]'})

            self.assertRaises(Exception, self.currency.write, [cu1],
                {'mon_grouping': '[1,"a"]'})

            self.assertRaises(Exception, self.currency.write, [cu1],
                {'mon_grouping': '[1,"1"]'})

    def test0030rate(self):
        'Create rates'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            rate1, rate2 = self.rate.create([{
                        'rate': Decimal("1.3"),
                        'currency': cu1.id,
                        }, {
                        'rate': Decimal("1"),
                        'currency': cu2.id,
                        }])
            self.assert_(rate1)
            self.assert_(rate2)

            self.assertEqual(cu1.rate, Decimal("1.3"))

            transaction.cursor.commit()

    def test0040rate_unicity(self):
        'Rate unicity'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            today = self.date.today()

            cu, = self.currency.create([{
                        'name': 'cu',
                        'symbol': 'cu',
                        'code': 'cu'
                        }])

            self.rate.create([{
                        'rate': Decimal("1.3"),
                        'currency': cu.id,
                        'date': today,
                        }])

            self.assertRaises(Exception, self.rate.create, {
                    'rate': Decimal("1.3"),
                    'currency': cu.id,
                    'date': today,
                    })

            transaction.cursor.rollback()

    def test0050compute_simple(self):
        'Simple conversion'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            amount = Decimal("10")
            expected = Decimal("13")
            converted_amount = self.currency.compute(
                cu2, amount, cu1, True)
            self.assertEqual(converted_amount, expected)

            transaction.cursor.commit()

    def test0060compute_nonfinite(self):
        'Conversion with rounding on non-finite decimal representation'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            amount = Decimal("10")
            expected = Decimal("7.69")
            converted_amount = self.currency.compute(
                cu1, amount, cu2, True)
            self.assertEqual(converted_amount, expected)

    def test0070compute_nonfinite_worounding(self):
        'Same without rounding'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            amount = Decimal("10")
            expected = Decimal('7.692307692307692307692307692')
            converted_amount = self.currency.compute(
                cu1, amount, cu2, False)
            self.assertEqual(converted_amount, expected)

    def test0080compute_same(self):
        'Conversion to the same currency'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            cu1 = self.get_currency('cu1')

            amount = Decimal("10")
            converted_amount = self.currency.compute(
                cu1, amount, cu1, True)
            self.assertEqual(converted_amount, amount)

    def test0090compute_zeroamount(self):
        'Conversion with zero amount'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            expected = Decimal("0")
            converted_amount = self.currency.compute(
                cu1, Decimal("0"), cu2, True)
            self.assertEqual(converted_amount, expected)

    def test0100compute_zerorate(self):
        'Conversion with zero rate'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu1 = self.get_currency('cu1')
            cu2 = self.get_currency('cu2')

            rates = self.rate.search([
                    ('currency', '=', cu1.id),
                    ], 0, 1, None)
            self.rate.write(rates, {
                    'rate': Decimal("0"),
                    })
            amount = Decimal("10")
            self.assertRaises(Exception, self.currency.compute,
                cu1, amount, cu2, True)
            self.assertRaises(Exception, self.currency.compute,
                cu2, amount, cu1, True)

            transaction.cursor.rollback()

    def test0110compute_missingrate(self):
        'Conversion with missing rate'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu1 = self.get_currency('cu1')
            cu3, = self.currency.create([{
                        'name': 'cu3',
                        'symbol': 'cu3',
                        'code': 'cu3'
                        }])

            amount = Decimal("10")
            self.assertRaises(Exception, self.currency.compute,
                cu3, amount, cu1, True)
            self.assertRaises(Exception, self.currency.compute,
                cu1, amount, cu3, True)

            transaction.cursor.rollback()

    def test0120compute_bothmissingrate(self):
        'Conversion with both missing rate'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            cu3, cu4 = self.currency.create([{
                        'name': 'cu3',
                        'symbol': 'cu3',
                        'code': 'cu3'
                        }, {
                        'name': 'cu4',
                        'symbol': 'cu4',
                        'code': 'cu4'
                        }])

            amount = Decimal("10")
            self.assertRaises(Exception, self.currency.compute,
                cu3, amount, cu4, True)

            transaction.cursor.rollback()

    def test0130delete_cascade(self):
        'Test deletion of currency deletes rates'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            codes = ['cu%s' % (i + 1) for i in range(2)]
            currencies = [self.get_currency(i) for i in codes]
            self.currency.delete(currencies)

            rates = self.rate.search([(
                        'currency', 'in', map(int, currencies),
                        )], 0, None, None)
            self.assertFalse(rates)

            transaction.cursor.rollback()


def suite():
    suite = trytond.tests.test_tryton.suite()
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
            CurrencyTestCase))
    return suite