Browse Source

Use unicode for code & tests.

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

6
partner_firstname/models.py

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

19
partner_firstname/tests/test_partner_firstname.py

@ -33,18 +33,19 @@ class PartnerFirstnameCase(TransactionCase):
def setUp(self):
super(PartnerFirstnameCase, self).setUp()
self.check_fields = True
self.expect(u"Núñez", u"Fernán")
self.create_original()
def create_original(self):
self.original = self.env["res.partner"].create({
"lastname": "lastname",
"firstname": "firstname"})
"lastname": self.lastname,
"firstname": self.firstname})
def expect(self, lastname, firstname, name=None):
"""Define what is expected in each field when ending."""
self.lastname = lastname
self.firstname = firstname
self.name = name or "%s %s" % (lastname, firstname)
self.name = name or u"%s %s" % (lastname, firstname)
def tearDown(self):
if self.check_fields:
@ -61,23 +62,23 @@ class PartnerFirstnameCase(TransactionCase):
def test_copy(self):
"""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()
def test_update_lastname(self):
"""Change lastname."""
self.expect("newlastname", "firstname")
self.expect(u"newlästname", self.firstname)
self.original.name = self.name
def test_update_firstname(self):
"""Change firstname."""
self.expect("lastname", "newfirstname")
self.expect(self.lastname, u"newfïrstname")
self.original.name = self.name
def test_whitespace_cleanup(self):
"""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
self.original.invalidate_cache()
@ -92,5 +93,5 @@ class PartnerFirstnameCase(TransactionCase):
class UserFirstnameCase(PartnerFirstnameCase):
def create_original(self):
self.original = self.env["res.users"].create({
"name": "lastname firstname",
"name": u"%s %s" % (self.lastname, self.firstname),
"login": "firstnametest@example.com"})
Loading…
Cancel
Save