This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/tests/test_mptt.py is in tryton-server 3.0.2-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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#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 sys
import unittest
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \
        install_module
from trytond.transaction import Transaction


class MPTTTestCase(unittest.TestCase):
    '''
    Test Modified Preorder Tree Traversal.
    '''

    def setUp(self):
        install_module('tests')
        self.mptt = POOL.get('test.mptt')

    def CheckTree(self, parent_id=None, left=-1, right=sys.maxint):
        childs = self.mptt.search([
                ('parent', '=', parent_id),
                ], order=[('left', 'ASC')])
        for child in childs:
            assert child.left > left, \
                '%s: left %d <= parent left %d' % \
                (child, child.left, left)
            assert child.left < child.right, \
                '%s: left %d >= right %d' % \
                (child, child.left, child.right)
            assert child.right < right, \
                '%s: right %d >= parent right %d' % \
                (child, child.right, right)
            self.CheckTree(child.id, left=child.left,
                right=child.right)
        next_left = -1
        for child in childs:
            assert child.left > next_left, \
                '%s: left %d <= next left %d' % \
                (child, child.left, next_left)
            next_left = child.right
        childs.reverse()
        previous_right = sys.maxint
        for child in childs:
            assert child.right < previous_right, \
                '%s: right %d >= previous right %d' \
                % (child, child.right, previous_right)
            previous_right = child.left

    def ReParent(self, parent=None):
        records = self.mptt.search([
                ('parent', '=', parent),
                ])
        if not records:
            return
        for record in records:
            for record2 in records:
                if record != record2:
                    record.parent = record2
                    record.save()
                    record.parent = parent
                    record.save()
        for record in records:
            self.ReParent(record)

    def test0010create(self):
        '''
        Create tree.
        '''
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            new_records = [None, None, None]
            for j in range(3):
                parent_records = new_records
                new_records = []
                k = 0
                for parent_record in parent_records:
                    new_records += self.mptt.create([{
                                'name': 'Test %d %d %d' % (j, k, i),
                                'parent': (parent_record.id
                                    if parent_record else None),
                                } for i in range(3)])
                    k += 1
            self.CheckTree()

            transaction.cursor.commit()

    def test0030reparent(self):
        '''
        Re-parent.
        '''
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            self.ReParent()
            transaction.cursor.rollback()

    def test0040active(self):
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            for record in records:
                if record.id % 2:
                    record.active = False
                    record.save()
            self.CheckTree()
            self.ReParent()
            self.CheckTree()

            transaction.cursor.rollback()

        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            self.mptt.write(records[:len(records) // 2], {
                    'active': False
                    })
            self.CheckTree()

            transaction.cursor.rollback()

        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            self.mptt.write(records, {
                    'active': False
                    })
            self.ReParent()
            self.CheckTree()

            transaction.cursor.rollback()

    def test0050delete(self):
        '''
        Delete.
        '''
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            for record in records:
                if record.id % 2:
                    self.mptt.delete([record])
            self.CheckTree()

            transaction.cursor.rollback()

        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            self.mptt.delete(records[:len(records) // 2])
            self.CheckTree()

            transaction.cursor.rollback()

        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            records = self.mptt.search([])
            self.mptt.delete(records)
            self.CheckTree()

            transaction.cursor.rollback()


def suite():
    return unittest.TestLoader().loadTestsFromTestCase(MPTTTestCase)

if __name__ == '__main__':
    suite = suite()
    unittest.TextTestRunner(verbosity=2).run(suite)