Browse Source
Convert YAML tests to unit-tests, with several improvements
Convert YAML tests to unit-tests, with several improvements
Allow simultaneous use of country_field and partner_field in field definitionpull/88/head
Alexis de Lattre
8 years ago
12 changed files with 115 additions and 120 deletions
-
1base_phone/__openerp__.py
-
3base_phone/fields.py
-
7base_phone/models/res_partner.py
-
50base_phone/test/phonenum.yml
-
3base_phone/tests/__init__.py
-
55base_phone/tests/test_phone.py
-
19crm_phone/__init__.py
-
1crm_phone/__openerp__.py
-
6crm_phone/crm_phone.py
-
41crm_phone/test/phonenum.yml
-
3crm_phone/tests/__init__.py
-
46crm_phone/tests/test_crm_phone.py
@ -1,50 +0,0 @@ |
|||||
- |
|
||||
Write country = FR for the main company |
|
||||
- |
|
||||
!record {model: res.company, id: base.main_company}: |
|
||||
country_id: base.fr |
|
||||
- |
|
||||
Write french phone numbers in national format |
|
||||
- |
|
||||
!record {model: res.partner, id: partner1}: |
|
||||
name: Pierre Paillet |
|
||||
mobile: 06 42 77 42 66 |
|
||||
fax: (0) 1 45 42 12 42 |
|
||||
- |
|
||||
Write swiss phone numbers in international format |
|
||||
- |
|
||||
!record {model: res.partner, id: partner2}: |
|
||||
name: Joël Grand-Guillaume |
|
||||
parent_id: base.res_partner_12 |
|
||||
phone: +41 21 619 10 10 |
|
||||
mobile: +41 79 606 42 42 |
|
||||
- |
|
||||
Write invalid phone number |
|
||||
- |
|
||||
!record {model: res.partner, id: partner3}: |
|
||||
name: Jean Badphone |
|
||||
phone: 42 |
|
||||
- |
|
||||
Check that valid phone numbers have been converted to E.164 |
|
||||
- |
|
||||
!python {model: res.partner}: | |
|
||||
partner1 = self.browse(cr, uid, ref('partner1'), context=context) |
|
||||
assert partner1.mobile == '+33 6 42 77 42 66', 'Mobile number not written in E.164 format (partner1)' |
|
||||
assert partner1.fax == '+33 1 45 42 12 42', 'Fax number not written in E.164 format (partner1)' |
|
||||
partner2 = self.browse(cr, uid, ref('partner2'), context=context) |
|
||||
assert partner2.phone == '+41 21 619 10 10', 'Phone number not written in E.164 format (partner2)' |
|
||||
assert partner2.mobile == '+41 79 606 42 42', 'Mobile number not written in E.164 format (partner2)' |
|
||||
- |
|
||||
Check that invalid phone numbers are kept unchanged |
|
||||
- |
|
||||
!python {model: res.partner}: | |
|
||||
partner3 = self.browse(cr, uid, ref('partner3'), context=context) |
|
||||
assert partner3.phone == '42', 'Invalid phone numbers should not be changed' |
|
||||
- |
|
||||
Get name from phone number |
|
||||
- |
|
||||
!python {model: phone.common}: | |
|
||||
name = self.get_name_from_phone_number(cr, uid, '0642774266') |
|
||||
assert name == 'Pierre Paillet', 'Wrong result for get_name_from_phone_number' |
|
||||
name2 = self.get_name_from_phone_number(cr, uid, '0041216191010') |
|
||||
assert name2 == u'Joël Grand-Guillaume (Camptocamp)', 'Wrong result for get_name_from_phone_number (partner2)' |
|
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import test_phone |
@ -0,0 +1,55 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Akretion France (Alexis de Lattre <alexis.delattre@akretion.com>) |
||||
|
|
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestPhone(TransactionCase): |
||||
|
|
||||
|
def test_phone(self): |
||||
|
company = self.env.ref('base.main_company') |
||||
|
company.country_id = self.env.ref('base.fr').id |
||||
|
rpo = self.env['res.partner'] |
||||
|
# Create an existing partner without country |
||||
|
partner1 = rpo.create({ |
||||
|
'name': u'Pierre Paillet', |
||||
|
'phone': '04-72-08-87-32', |
||||
|
'mobile': '06.42.77.42.66', |
||||
|
'fax': '(0) 1 45 42 12 42', |
||||
|
}) |
||||
|
self.assertEquals(partner1.phone, '+33 4 72 08 87 32') |
||||
|
self.assertEquals(partner1.mobile, '+33 6 42 77 42 66') |
||||
|
self.assertEquals(partner1.fax, '+33 1 45 42 12 42') |
||||
|
# Create a partner with country |
||||
|
self.env.ref('base.res_partner_12').country_id =\ |
||||
|
self.env.ref('base.ch').id |
||||
|
partner2 = rpo.create({ |
||||
|
'name': u'Joël Grand-Guillaume', |
||||
|
'parent_id': self.env.ref('base.res_partner_12').id, |
||||
|
'use_parent_address': True, |
||||
|
'phone': '(0) 21 619 10 10', |
||||
|
'mobile': '(0) 79 606 42 42', |
||||
|
}) |
||||
|
self.assertEquals(partner2.country_id, self.env.ref('base.ch')) |
||||
|
self.assertEquals(partner2.phone, '+41 21 619 10 10') |
||||
|
self.assertEquals(partner2.mobile, '+41 79 606 42 42') |
||||
|
# Write on an existing partner |
||||
|
agrolait = self.env.ref('base.res_partner_2') |
||||
|
self.assertEquals(agrolait.country_id, self.env.ref('base.be')) |
||||
|
agrolait.write({'phone': '(0) 2 391 43 74'}) |
||||
|
self.assertEquals(agrolait.phone, '+32 2 391 43 74') |
||||
|
# Write on an existing partner with country at the same time |
||||
|
agrolait.write({ |
||||
|
'fax': '04 72 89 32 43', |
||||
|
'country_id': self.env.ref('base.fr').id, |
||||
|
}) |
||||
|
self.assertEquals(agrolait.fax, '+33 4 72 89 32 43') |
||||
|
# Write an invalid phone number |
||||
|
partner2.fax = '42' |
||||
|
self.assertEquals(partner2.fax, '42') |
||||
|
# Test get_name_from_phone_number |
||||
|
pco = self.env['phone.common'] |
||||
|
name = pco.get_name_from_phone_number('0642774266') |
||||
|
self.assertEquals(name, 'Pierre Paillet') |
||||
|
name2 = pco.get_name_from_phone_number('0041216191010') |
||||
|
self.assertEquals(name2, u'Joël Grand-Guillaume (Camptocamp)') |
@ -1,23 +1,4 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# CRM Phone module for Odoo/OpenERP |
|
||||
# Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr> |
|
||||
# |
|
||||
# This program is free software: you can redistribute it and/or modify |
|
||||
# it under the terms of the GNU Affero General Public License as |
|
||||
# published by the Free Software Foundation, either version 3 of the |
|
||||
# License, or (at your option) any later version. |
|
||||
# |
|
||||
# This program is distributed in the hope that it will be useful, |
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
# GNU Affero General Public License for more details. |
|
||||
# |
|
||||
# You should have received a copy of the GNU Affero General Public License |
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import crm_phone |
from . import crm_phone |
||||
from . import wizard |
from . import wizard |
@ -1,41 +0,0 @@ |
|||||
- |
|
||||
Write french phone numbers in national format |
|
||||
- |
|
||||
!record {model: crm.lead, id: lead1}: |
|
||||
name: Jacques Toufaux |
|
||||
mobile: 06 42 77 42 77 |
|
||||
fax: (0) 1 45 44 42 43 |
|
||||
country_id: base.fr |
|
||||
- |
|
||||
Write swiss phone numbers in national format |
|
||||
- |
|
||||
!record {model: crm.lead, id: lead2}: |
|
||||
name: Michel Content |
|
||||
country_id: base.ch |
|
||||
phone: 04 31 23 45 67 |
|
||||
- |
|
||||
Create a german lead |
|
||||
- |
|
||||
!record {model: crm.lead, id: lead3}: |
|
||||
name: Angela Strasse |
|
||||
country_id: base.de |
|
||||
- |
|
||||
Check that valid phone numbers have been converted to E.164 |
|
||||
- |
|
||||
!python {model: crm.lead}: | |
|
||||
lead1 = self.browse(cr, uid, ref('lead1'), context=context) |
|
||||
assert lead1.mobile == '+33 6 42 77 42 77', 'Mobile number not written in E.164 format (lead1)' |
|
||||
assert lead1.fax == '+33 1 45 44 42 43', 'Fax number not written in E.164 format (lead1)' |
|
||||
lead2 = self.browse(cr, uid, ref('lead2'), context=context) |
|
||||
assert lead2.phone == '+41 43 123 45 67', 'Phone number not written in E.164 format (lead2)' |
|
||||
self.write(cr, uid, ref('lead3'), {'phone': '08912345678'}) |
|
||||
lead3 = self.browse(cr, uid, ref('lead3'), context=context) |
|
||||
assert lead3.phone == '+49 89 12345678', 'Phone number not written in E.164 format (lead3)' |
|
||||
- |
|
||||
Get name from phone number |
|
||||
- |
|
||||
!python {model: phone.common}: | |
|
||||
name = self.get_name_from_phone_number(cr, uid, '0642774277') |
|
||||
assert name == 'Jacques Toufaux', 'Wrong result for get_name_from_phone_number (lead1)' |
|
||||
name2 = self.get_name_from_phone_number(cr, uid, '0041431234567') |
|
||||
assert name2 == 'Michel Content', 'Wrong result for get_name_from_phone_number (lead2)' |
|
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import test_crm_phone |
@ -0,0 +1,46 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Akretion France (Alexis de Lattre <alexis.delattre@akretion.com>) |
||||
|
|
||||
|
|
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestCRMPhone(TransactionCase): |
||||
|
|
||||
|
def test_crm_phone(self): |
||||
|
clo = self.env['crm.lead'] |
||||
|
lead1 = clo.create({ |
||||
|
'name': 'The super deal of the year !', |
||||
|
'partner_name': 'Ford', |
||||
|
'contact_name': 'Jacques Toufaux', |
||||
|
'mobile': '06.42.77.42.77', |
||||
|
'fax': '(0) 1 45 44 42 43', |
||||
|
'country_id': self.env.ref('base.fr').id, |
||||
|
}) |
||||
|
self.assertEquals(lead1.mobile, '+33 6 42 77 42 77') |
||||
|
self.assertEquals(lead1.fax, '+33 1 45 44 42 43') |
||||
|
lead2 = clo.create({ |
||||
|
'name': u'Automobile Odoo deployment', |
||||
|
'partner_name': u'Kia', |
||||
|
'contact_name': u'Mikaël Content', |
||||
|
'country_id': self.env.ref('base.ch').id, |
||||
|
'phone': '04 31 23 45 67', |
||||
|
}) |
||||
|
self.assertEquals(lead2.phone, '+41 43 123 45 67') |
||||
|
lead3 = clo.create({ |
||||
|
'name': 'Angela Strasse', |
||||
|
'country_id': self.env.ref('base.de').id, |
||||
|
}) |
||||
|
lead3.write({'phone': '08912345678'}) |
||||
|
self.assertEquals(lead3.phone, '+49 89 12345678') |
||||
|
lead4 = clo.create({ |
||||
|
'name': 'Large Odoo deployment', |
||||
|
'partner_id': self.env.ref('base.res_partner_2').id, |
||||
|
}) |
||||
|
lead4.write({'mobile': '(0) 2-391-43-75'}) |
||||
|
self.assertEquals(lead4.mobile, '+32 2 391 43 75') |
||||
|
pco = self.env['phone.common'] |
||||
|
name = pco.get_name_from_phone_number('0642774277') |
||||
|
self.assertEquals(name, 'Jacques Toufaux (Ford)') |
||||
|
name2 = pco.get_name_from_phone_number('0041431234567') |
||||
|
self.assertEquals(name2, u'Mikaël Content (Kia)') |
Write
Preview
Loading…
Cancel
Save
Reference in new issue