Browse Source

Use unicode for code & tests.

pull/104/head
Jairo Llopis 10 years ago
parent
commit
9a72a9efd0
  1. 4
      partner_firstname/models.py
  2. 19
      partner_firstname/tests/test_partner_firstname.py

4
partner_firstname/models.py

@ -38,7 +38,7 @@ class ResPartner(models.Model):
@api.depends("firstname", "lastname") @api.depends("firstname", "lastname")
def _name_compute(self): def _name_compute(self):
"""Write the 'name' field according to splitted data.""" """Write the 'name' field according to splitted data."""
self.name = " ".join((p for p in (self.lastname,
self.name = u" ".join((p for p in (self.lastname,
self.firstname) if p)) self.firstname) if p))
@api.one @api.one
@ -49,7 +49,7 @@ class ResPartner(models.Model):
- Otherwise, make a guess. - Otherwise, make a guess.
""" """
# Remove unneeded whitespace # Remove unneeded whitespace
clean = " ".join(self.name.split(None))
clean = u" ".join(self.name.split(None))
# Clean name avoiding infinite recursion # Clean name avoiding infinite recursion
if self.name != clean: if self.name != clean:

19
partner_firstname/tests/test_partner_firstname.py

@ -33,18 +33,19 @@ class PartnerFirstnameCase(TransactionCase):
def setUp(self): def setUp(self):
super(PartnerFirstnameCase, self).setUp() super(PartnerFirstnameCase, self).setUp()
self.check_fields = True self.check_fields = True
self.expect(u"Núñez", u"Fernán")
self.create_original() self.create_original()
def create_original(self): def create_original(self):
self.original = self.env["res.partner"].create({ self.original = self.env["res.partner"].create({
"lastname": "lastname",
"firstname": "firstname"})
"lastname": self.lastname,
"firstname": self.firstname})
def expect(self, lastname, firstname, name=None): def expect(self, lastname, firstname, name=None):
"""Define what is expected in each field when ending.""" """Define what is expected in each field when ending."""
self.lastname = lastname self.lastname = lastname
self.firstname = firstname self.firstname = firstname
self.name = name or "%s %s" % (lastname, firstname)
self.name = name or u"%s %s" % (lastname, firstname)
def tearDown(self): def tearDown(self):
if self.check_fields: if self.check_fields:
@ -61,23 +62,23 @@ class PartnerFirstnameCase(TransactionCase):
def test_copy(self): def test_copy(self):
"""Copy the partner and compare the result.""" """Copy the partner and compare the result."""
self.expect("lastname", "firstname (copy)")
self.expect(self.lastname, u"%s (copy)" % self.firstname)
self.changed = self.original.with_context(lang="en_US").copy() self.changed = self.original.with_context(lang="en_US").copy()
def test_update_lastname(self): def test_update_lastname(self):
"""Change lastname.""" """Change lastname."""
self.expect("newlastname", "firstname")
self.expect(u"newlästname", self.firstname)
self.original.name = self.name self.original.name = self.name
def test_update_firstname(self): def test_update_firstname(self):
"""Change firstname.""" """Change firstname."""
self.expect("lastname", "newfirstname")
self.expect(self.lastname, u"newfïrstname")
self.original.name = self.name self.original.name = self.name
def test_whitespace_cleanup(self): def test_whitespace_cleanup(self):
"""Check that whitespace in name gets cleared.""" """Check that whitespace in name gets cleared."""
self.expect("newlastname", "newfirstname")
self.original.name = " newlastname newfirstname "
self.expect(u"newlästname", u"newfïrstname")
self.original.name = " newlästname newfïrstname "
# Need this to refresh the ``name`` field # Need this to refresh the ``name`` field
self.original.invalidate_cache() self.original.invalidate_cache()
@ -92,5 +93,5 @@ class PartnerFirstnameCase(TransactionCase):
class UserFirstnameCase(PartnerFirstnameCase): class UserFirstnameCase(PartnerFirstnameCase):
def create_original(self): def create_original(self):
self.original = self.env["res.users"].create({ self.original = self.env["res.users"].create({
"name": "lastname firstname",
"name": u"%s %s" % (self.lastname, self.firstname),
"login": "firstnametest@example.com"}) "login": "firstnametest@example.com"})
Loading…
Cancel
Save