Browse Source

Use new() to create onchange records. Reduce redundancy in tests.

pull/139/head
Jairo Llopis 10 years ago
parent
commit
ba74af5c9b
  1. 10
      partner_firstname/tests/base.py
  2. 36
      partner_firstname/tests/test_onchange.py

10
partner_firstname/tests/base.py

@ -76,3 +76,13 @@ class BaseCase(TransactionCase):
self.check_fields = False
with self.assertRaises(ex.EmptyNamesError):
self.original.firstname = self.original.lastname = False
class OnChangeCase(TransactionCase):
is_company = False
def new_partner(self):
"""Create an empty partner. Ensure it is (or not) a company."""
new = self.env["res.partner"].new()
new.is_company = self.is_company
return new

36
partner_firstname/tests/test_onchange.py

@ -1,23 +1,21 @@
# -*- coding: utf-8 -*-
"""These tests try to mimic the behavior of the UI form.
The form operates in onchange mode, and has only some limitations that must be
met.
The form operates in onchange mode, with its limitations.
"""
from openerp.tests.common import TransactionCase
from .base import OnChangeCase
class PartnerCompanyCase(TransactionCase):
class PartnerCompanyCase(OnChangeCase):
is_company = True
def test_create_from_form(self):
"""A user creates a company from the form."""
name = u"Sôme company"
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is a company
partner.is_company = True
partner = self.new_partner()
# User sets a name, which triggers onchanges
partner.name = name
@ -34,10 +32,7 @@ class PartnerCompanyCase(TransactionCase):
"""
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is a company
partner.is_company = True
partner = self.new_partner()
# User sets a name, which triggers onchanges
partner.name = u"Foó"
@ -51,16 +46,13 @@ class PartnerCompanyCase(TransactionCase):
self.assertEqual(partner.lastname, False)
class PartnerContactCase(TransactionCase):
class PartnerContactCase(OnChangeCase):
def test_create_from_form_only_firstname(self):
"""A user creates a contact with only the firstname from the form."""
firstname = u"Fïrst"
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is not a company
partner.is_company = False
partner = self.new_partner()
# Changes firstname, which triggers onchanges
partner.firstname = firstname
@ -76,10 +68,7 @@ class PartnerContactCase(TransactionCase):
lastname = u"Läst"
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is not a company
partner.is_company = False
partner = self.new_partner()
# Changes lastname, which triggers onchanges
partner.lastname = lastname
@ -96,10 +85,7 @@ class PartnerContactCase(TransactionCase):
lastname = u"Läst"
with self.env.do_in_onchange():
# User presses ``new``
partner = self.env["res.partner"].create({})
# User ensures it is not a company
partner.is_company = False
partner = self.new_partner()
# Changes firstname, which triggers onchanges
partner.firstname = firstname

Loading…
Cancel
Save