This file is indexed.

/usr/lib/python3/dist-packages/trytond/tests/test_modelsingleton.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
 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
# -*- 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 unittest
from datetime import datetime
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.transaction import Transaction
from trytond.pool import Pool


class ModelSingletonTestCase(unittest.TestCase):
    'Test ModelSingleton'

    @classmethod
    def setUpClass(cls):
        activate_module('tests')

    @with_transaction()
    def test_read(self):
        'Test read method'
        pool = Pool()
        Singleton = pool.get('test.singleton')

        singleton, = Singleton.read([1], ['name'])
        self.assertTrue(singleton['name'] == 'test')
        self.assertTrue(singleton['id'] == 1)

        singleton, = Singleton.read([1], ['name'])
        self.assertTrue(singleton['name'] == 'test')
        self.assertTrue(singleton['id'] == 1)

        singleton, = Singleton.read([1], [
            'create_uid',
            'create_uid.rec_name',
            'create_date',
            'write_uid',
            'write_date',
            ])
        self.assertEqual(singleton['create_uid'], Transaction().user)
        self.assertEqual(singleton['create_uid.rec_name'], 'Administrator')
        self.assertTrue(isinstance(singleton['create_date'], datetime))
        self.assertEqual(singleton['write_uid'], None)
        self.assertEqual(singleton['write_date'], None)

    @with_transaction()
    def test_create(self):
        'Test create method'
        pool = Pool()
        Singleton = pool.get('test.singleton')

        singleton, = Singleton.create([{'name': 'bar'}])
        self.assertTrue(singleton)
        self.assertEqual(singleton.name, 'bar')

        singleton2, = Singleton.create([{'name': 'foo'}])
        self.assertEqual(singleton2, singleton)

        self.assertEqual(singleton.name, 'foo')

        singletons = Singleton.search([])
        self.assertEqual(singletons, [singleton])

    @with_transaction()
    def test_copy(self):
        'Test copy method'
        pool = Pool()
        Singleton = pool.get('test.singleton')

        singleton, = Singleton.search([])

        singleton2, = Singleton.copy([singleton])
        self.assertEqual(singleton2, singleton)

        singletons = Singleton.search([])
        self.assertEqual(len(singletons), 1)

        singleton3, = Singleton.copy([singleton], {'name': 'bar'})
        self.assertEqual(singleton3, singleton)

        singletons = Singleton.search([])
        self.assertEqual(len(singletons), 1)

    @with_transaction()
    def test_default_get(self):
        'Test default_get method'
        pool = Pool()
        Singleton = pool.get('test.singleton')

        default = Singleton.default_get(['name'])
        self.assertEqual(default, {'name': 'test'})

        default = Singleton.default_get(['create_uid'])
        self.assertEqual(len(default), 2)

        default = Singleton.default_get(['create_uid'],
                with_rec_name=False)
        self.assertEqual(len(default), 1)

        Singleton.create([{'name': 'bar'}])

        default = Singleton.default_get(['name'])
        self.assertEqual(default, {'name': 'bar'})

        default = Singleton.default_get(['create_uid'])
        self.assertEqual(len(default), 2)

        default = Singleton.default_get(['create_uid'],
                with_rec_name=False)
        self.assertEqual(len(default), 1)

    @with_transaction()
    def test_search(self):
        'Test search method'
        pool = Pool()
        Singleton = pool.get('test.singleton')

        singletons = Singleton.search([])
        self.assertEqual(list(map(int, singletons)), [1])

        singletons = Singleton.search([])
        self.assertEqual(list(map(int, singletons)), [1])

        count = Singleton.search([], count=True)
        self.assertEqual(count, 1)

        Singleton.create([{'name': 'foo'}])
        singleton, = Singleton.search([('name', '=', 'foo')])
        self.assertEqual(singleton.name, 'foo')
        singletons = Singleton.search([('name', '=', 'bar')])
        self.assertEqual(singletons, [])


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