From be00f74797e3ff67888ffd397d4cc3a1ceb05c19 Mon Sep 17 00:00:00 2001 From: Olivier LAURENT Date: Tue, 4 Mar 2014 11:20:38 +0100 Subject: [PATCH] [FIX] some tests failed if user's language is not english [CHG] improve some assertions --- partner_firstname/i18n/de.po | 16 ++-- partner_firstname/i18n/en.po | 6 +- partner_firstname/i18n/fr.po | 16 ++-- partner_firstname/i18n/nl.po | 16 ++-- partner_firstname/i18n/partner_firstname.pot | 6 +- .../tests/test_partner_firstname.py | 77 +++++++++++-------- 6 files changed, 83 insertions(+), 54 deletions(-) diff --git a/partner_firstname/i18n/de.po b/partner_firstname/i18n/de.po index 65fdef123..7b5eb2551 100644 --- a/partner_firstname/i18n/de.po +++ b/partner_firstname/i18n/de.po @@ -16,8 +16,12 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/partner.py:76 +#: code:addons/partner_firstname/partner.py:81 #: code:addons/partner_firstname/res_user.py:35 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:56 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:57 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:71 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:72 #, python-format msgid "%s (copy)" msgstr "%s (kopie)" @@ -27,16 +31,16 @@ msgstr "%s (kopie)" msgid "Users" msgstr "Benutzer" -#. module: partner_firstname -#: field:res.partner,lastname:0 -msgid "Lastname" -msgstr "Name" - #. module: partner_firstname #: field:res.partner,firstname:0 msgid "Firstname" msgstr "Vorname" +#. module: partner_firstname +#: field:res.partner,lastname:0 +msgid "Lastname" +msgstr "Name" + #. module: partner_firstname #: view:res.partner:0 msgid "Is a Company?" diff --git a/partner_firstname/i18n/en.po b/partner_firstname/i18n/en.po index 53f3034f8..7cccf0a33 100644 --- a/partner_firstname/i18n/en.po +++ b/partner_firstname/i18n/en.po @@ -16,8 +16,12 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/partner.py:76 +#: code:addons/partner_firstname/partner.py:81 #: code:addons/partner_firstname/res_user.py:35 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:56 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:57 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:71 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:72 #, python-format msgid "%s (copy)" msgstr "%s (copy)" diff --git a/partner_firstname/i18n/fr.po b/partner_firstname/i18n/fr.po index 682b35041..bcd457166 100644 --- a/partner_firstname/i18n/fr.po +++ b/partner_firstname/i18n/fr.po @@ -16,8 +16,12 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/partner.py:76 +#: code:addons/partner_firstname/partner.py:81 #: code:addons/partner_firstname/res_user.py:35 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:56 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:57 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:71 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:72 #, python-format msgid "%s (copy)" msgstr "%s (copie)" @@ -27,16 +31,16 @@ msgstr "%s (copie)" msgid "Users" msgstr "Utilisateur" -#. module: partner_firstname -#: field:res.partner,lastname:0 -msgid "Lastname" -msgstr "Nom" - #. module: partner_firstname #: field:res.partner,firstname:0 msgid "Firstname" msgstr "Prénom" +#. module: partner_firstname +#: field:res.partner,lastname:0 +msgid "Lastname" +msgstr "Nom de famille" + #. module: partner_firstname #: view:res.partner:0 msgid "Is a Company?" diff --git a/partner_firstname/i18n/nl.po b/partner_firstname/i18n/nl.po index a8eb29ef4..cd798ec82 100644 --- a/partner_firstname/i18n/nl.po +++ b/partner_firstname/i18n/nl.po @@ -16,8 +16,12 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/partner.py:76 +#: code:addons/partner_firstname/partner.py:81 #: code:addons/partner_firstname/res_user.py:35 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:56 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:57 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:71 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:72 #, python-format msgid "%s (copy)" msgstr "%s (kopie)" @@ -27,16 +31,16 @@ msgstr "%s (kopie)" msgid "Users" msgstr "Gebruikers" -#. module: partner_firstname -#: field:res.partner,lastname:0 -msgid "Lastname" -msgstr "Achternaam" - #. module: partner_firstname #: field:res.partner,firstname:0 msgid "Firstname" msgstr "Voornaam" +#. module: partner_firstname +#: field:res.partner,lastname:0 +msgid "Lastname" +msgstr "Achternaam" + #. module: partner_firstname #: view:res.partner:0 msgid "Is a Company?" diff --git a/partner_firstname/i18n/partner_firstname.pot b/partner_firstname/i18n/partner_firstname.pot index 52c9ec190..ab75c787a 100644 --- a/partner_firstname/i18n/partner_firstname.pot +++ b/partner_firstname/i18n/partner_firstname.pot @@ -16,8 +16,12 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/partner.py:76 +#: code:addons/partner_firstname/partner.py:81 #: code:addons/partner_firstname/res_user.py:35 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:56 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:57 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:71 +#: code:addons/partner_firstname/tests/test_partner_firstname.py:72 #, python-format msgid "%s (copy)" msgstr "" diff --git a/partner_firstname/tests/test_partner_firstname.py b/partner_firstname/tests/test_partner_firstname.py index 38e94ffc2..004b04f4c 100644 --- a/partner_firstname/tests/test_partner_firstname.py +++ b/partner_firstname/tests/test_partner_firstname.py @@ -29,11 +29,14 @@ ############################################################################## import openerp.tests.common as common +from openerp.tools.translate import _ + class test_partner_firstname(common.TransactionCase): def setUp(self): super(test_partner_firstname, self).setUp() + self.registry('ir.model').clear_caches() self.registry('ir.model.data').clear_caches() @@ -42,53 +45,59 @@ class test_partner_firstname(common.TransactionCase): self.fields_partner = {'lastname': 'lastname', 'firstname': 'firstname'} self.fields_user = {'name': 'lastname', 'login': 'v5Ue4Tql0Pm67KX05g25A'} + self.context = self.user_model.context_get(self.cr, self.uid) + def test_copy_partner(self): - cr, uid = self.cr, self.uid - res_id = self.partner_model.create(cr, uid, self.fields_partner, context={}) - res_id = self.partner_model.copy(cr, uid, res_id, default={}, context={}) - vals = self.partner_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0] - self.assertEqual(vals['name'] == "lastname (copy) firstname" and - vals['lastname'] == 'lastname (copy)' and - vals['firstname'] == 'firstname', True, 'Copy of the partner failed with wrong values') + cr, uid, context = self.cr, self.uid, self.context + res_id = self.partner_model.create(cr, uid, self.fields_partner, context=context) + res_id = self.partner_model.copy(cr, uid, res_id, default={}, context=context) + vals = self.partner_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0] + + self.assertEqual(vals['name'], _('%s (copy)') % 'lastname' + " firstname", 'Copy of the partner failed with wrong name') + self.assertEqual(vals['lastname'], _('%s (copy)') % 'lastname', 'Copy of the partner failed with wrong lastname') + self.assertEqual(vals['firstname'], 'firstname', 'Copy of the partner failed with wrong firstname') def test_copy_user(self): - cr, uid = self.cr, self.uid + cr, uid, context = self.cr, self.uid, self.context # create a user - res_id = self.user_model.create(cr, uid, self.fields_user, context={}) + res_id = self.user_model.create(cr, uid, self.fields_user, context=context) # get the related partner id and add it a firstname - flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0] - self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={}) + flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context=context)[0] + self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context=context) # copy the user and compare result - res_id = self.user_model.copy(cr, uid, res_id, default={}, context={}) - vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0] - self.assertEqual(vals['name'] == "lastname (copy) firstname" and - vals['lastname'] == 'lastname (copy)' and - vals['firstname'] == 'firstname', True, 'Copy of the user failed with wrong values') + res_id = self.user_model.copy(cr, uid, res_id, default={}, context=context) + vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0] + + self.assertEqual(vals['name'], _('%s (copy)') % 'lastname' + ' firstname', 'Copy of the user failed with wrong name') + self.assertEqual(vals['lastname'], _('%s (copy)') % 'lastname', 'Copy of the user failed with wrong lastname') + self.assertEqual(vals['firstname'], 'firstname', 'Copy of the user failed with wrong firstname') def test_update_user_lastname(self): - cr, uid = self.cr, self.uid + cr, uid, context = self.cr, self.uid, self.context # create a user - res_id = self.user_model.create(cr, uid, self.fields_user, context={}) + res_id = self.user_model.create(cr, uid, self.fields_user, context=context) # get the related partner id and add it a firstname - flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0] - self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={}) - self.user_model.write(cr, uid, res_id, {'name': 'change firstname'}, context={}) - vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0] - self.assertEqual(vals['name'] == "change firstname" and - vals['lastname'] == 'change' and - vals['firstname'] == 'firstname', True, 'Update of the user lastname failed with wrong values') + flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context=context)[0] + self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context=context) + self.user_model.write(cr, uid, res_id, {'name': 'change firstname'}, context=context) + vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0] + + self.assertEqual(vals['name'], 'change firstname', 'Update of the user lastname failed with wrong name') + self.assertEqual(vals['lastname'], 'change', 'Update of the user lastname failed with wrong lastname') + self.assertEqual(vals['firstname'], 'firstname', 'Update of the user lastname failed with wrong firstname') def test_update_user_firstname(self): - cr, uid = self.cr, self.uid + cr, uid, context = self.cr, self.uid, self.context # create a user - res_id = self.user_model.create(cr, uid, self.fields_user, context={}) + res_id = self.user_model.create(cr, uid, self.fields_user, context=context) # get the related partner id and add it a firstname - flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0] - self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={}) - self.user_model.write(cr, uid, res_id, {'name': 'lastname other'}, context={}) - vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0] - self.assertEqual(vals['name'] == "lastname other" and - vals['lastname'] == 'lastname other' and - vals['firstname'] == False, True, 'Update of the user firstname failed with wrong values') + flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context=context)[0] + self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context=context) + self.user_model.write(cr, uid, res_id, {'name': 'lastname other'}, context=context) + vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context=context)[0] + + self.assertEqual(vals['name'], 'lastname other', 'Update of the user firstname failed with wrong name') + self.assertEqual(vals['lastname'], 'lastname other', 'Update of the user firstname failed with wrong lastname') + self.assertFalse(vals['firstname'], 'Update of the user firstname failed with wrong firstname') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: