/usr/lib/python3/dist-packages/trytond/modules/party/tests/test_party.py is in tryton-modules-party 4.6.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 | # 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 doctest
try:
import phonenumbers
except ImportError:
phonenumbers = None
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.tests.test_tryton import doctest_teardown
from trytond.tests.test_tryton import doctest_checker
from trytond.pool import Pool
from trytond.exceptions import UserError
from trytond.transaction import Transaction
class PartyTestCase(ModuleTestCase):
'Test Party module'
module = 'party'
@with_transaction()
def test_category(self):
'Create category'
pool = Pool()
Category = pool.get('party.category')
category1, = Category.create([{
'name': 'Category 1',
}])
self.assertTrue(category1.id)
@with_transaction()
def test_category_recursion(self):
'Test category recursion'
pool = Pool()
Category = pool.get('party.category')
category1, = Category.create([{
'name': 'Category 1',
}])
category2, = Category.create([{
'name': 'Category 2',
'parent': category1.id,
}])
self.assertTrue(category2.id)
self.assertRaises(Exception, Category.write, [category1], {
'parent': category2.id,
})
@with_transaction()
def test_party(self):
'Create party'
pool = Pool()
Party = pool.get('party.party')
party1, = Party.create([{
'name': 'Party 1',
}])
self.assertTrue(party1.id)
@with_transaction()
def test_party_code(self):
'Test party code constraint'
pool = Pool()
Party = pool.get('party.party')
party1, = Party.create([{
'name': 'Party 1',
}])
code = party1.code
party2, = Party.create([{
'name': 'Party 2',
}])
self.assertRaises(Exception, Party.write, [party2], {
'code': code,
})
@with_transaction()
def test_address(self):
'Create address'
pool = Pool()
Party = pool.get('party.party')
Address = pool.get('party.address')
party1, = Party.create([{
'name': 'Party 1',
}])
address, = Address.create([{
'party': party1.id,
'street': 'St sample, 15',
'city': 'City',
}])
self.assertTrue(address.id)
self.assertMultiLineEqual(address.full_address,
"St sample, 15\n"
"City")
with Transaction().set_context(address_with_party=True):
address = Address(address.id)
self.assertMultiLineEqual(address.full_address,
"Party 1\n"
"St sample, 15\n"
"City")
@with_transaction()
def test_full_address_country_subdivision(self):
'Test full address with country and subdivision'
pool = Pool()
Party = pool.get('party.party')
Country = pool.get('country.country')
Subdivision = pool.get('country.subdivision')
Address = pool.get('party.address')
party, = Party.create([{
'name': 'Party',
}])
country = Country(name='Country')
country.save()
subdivision = Subdivision(
name='Subdivision', country=country, code='SUB', type='area')
subdivision.save()
address, = Address.create([{
'party': party.id,
'subdivision': subdivision.id,
'country': country.id,
}])
self.assertMultiLineEqual(address.full_address,
"Subdivision\n"
"COUNTRY")
@with_transaction()
def test_party_label_report(self):
'Test party label report'
pool = Pool()
Party = pool.get('party.party')
Label = pool.get('party.label', type='report')
party1, = Party.create([{
'name': 'Party 1',
}])
oext, content, _, _ = Label.execute([party1.id], {})
self.assertEqual(oext, 'odt')
self.assertTrue(content)
@with_transaction()
def test_party_without_name(self):
'Create party without name'
pool = Pool()
Party = pool.get('party.party')
party2, = Party.create([{}])
self.assertTrue(party2.id)
code = party2.code
self.assertEqual(party2.rec_name, '[' + code + ']')
@unittest.skipIf(phonenumbers is None, 'requires phonenumbers')
@with_transaction()
def test_phone_number_format(self):
'Test phone number format'
pool = Pool()
Party = pool.get('party.party')
ContactMechanism = pool.get('party.contact_mechanism')
transaction = Transaction()
def create(mtype, mvalue):
party1, = Party.create([{
'name': 'Party 1',
}])
return ContactMechanism.create([{
'party': party1.id,
'type': mtype,
'value': mvalue,
}])[0]
# Test format on create
mechanism = create('phone', '+442083661177')
self.assertEqual(mechanism.value, '+44 20 8366 1177')
self.assertEqual(mechanism.value_compact, '+442083661177')
# Test format on write
mechanism.value = '+442083661178'
mechanism.save()
self.assertEqual(mechanism.value, '+44 20 8366 1178')
self.assertEqual(mechanism.value_compact, '+442083661178')
ContactMechanism.write([mechanism], {
'value': '+442083661179',
})
self.assertEqual(mechanism.value, '+44 20 8366 1179')
self.assertEqual(mechanism.value_compact, '+442083661179')
# Test rejection of a phone type mechanism to non-phone value
with self.assertRaises(UserError):
mechanism.value = 'notaphone@example.com'
mechanism.save()
transaction.rollback()
# Test rejection of invalid phone number creation
with self.assertRaises(UserError):
mechanism = create('phone', 'alsonotaphone@example.com')
transaction.rollback()
# Test acceptance of a non-phone value when type is non-phone
mechanism = create('email', 'name@example.com')
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(PartyTestCase))
suite.addTests(doctest.DocFileSuite(
'scenario_party_replace.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite
|