Browse Source

Tests work with `mail` module installed now.

Sometimes, the only way is to just skip them.
pull/139/head
Jairo Llopis 9 years ago
parent
commit
1e666a0db8
  1. 10
      partner_firstname/tests/base.py
  2. 17
      partner_firstname/tests/test_empty.py
  3. 19
      partner_firstname/tests/test_name.py

10
partner_firstname/tests/base.py

@ -29,7 +29,15 @@ from openerp.tests.common import TransactionCase
from .. import exceptions as ex
class BaseCase(TransactionCase):
class MailInstalled():
def mail_installed(self):
"""Check if ``mail`` module is installed.``"""
return (self.env["ir.module.module"]
.search([("name", "=", "mail")])
.state == "installed")
class BaseCase(TransactionCase, MailInstalled):
def setUp(self):
super(BaseCase, self).setUp()
self.check_fields = True

17
partner_firstname/tests/test_empty.py

@ -16,7 +16,13 @@
# 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/>.
"""Test situations where names are empty.
To have more accurate results, remove the ``mail`` module before testing.
"""
from openerp.tests.common import TransactionCase
from .base import MailInstalled
from .. import exceptions as ex
@ -47,7 +53,16 @@ class PersonCase(CompanyCase):
context = {"default_is_company": False}
class UserCase(CompanyCase):
class UserCase(CompanyCase, MailInstalled):
"""Test ``res.users``."""
model = "res.users"
context = {"default_login": "user@example.com"}
def tearDown(self):
# Cannot create users if ``mail`` is installed
if self.mail_installed():
# Skip tests
super(CompanyCase, self).tearDown()
else:
# Run tests
super(UserCase, self).tearDown()

19
partner_firstname/tests/test_name.py

@ -27,8 +27,7 @@
"""Test naming logic.
Please have in mind that some tests will fail if the ``mail`` module is
installed.
To have more accurate results, remove the ``mail`` module before testing.
"""
from .base import BaseCase
@ -60,6 +59,7 @@ class PartnerCompanyCase(BaseCase):
self.original.is_company = True
def test_copy(self):
"""Copy the partner and compare the result."""
super(PartnerCompanyCase, self).test_copy()
self.expect(self.name, False, self.name)
@ -72,6 +72,19 @@ class PartnerCompanyCase(BaseCase):
class UserCase(PartnerContactCase):
def create_original(self):
name = u"%s %s" % (self.lastname, self.firstname)
# Cannot create users if ``mail`` is installed
if self.mail_installed():
self.original = self.env.ref("base.user_demo")
self.original.name = name
else:
self.original = self.env["res.users"].create({
"name": u"%s %s" % (self.lastname, self.firstname),
"name": name,
"login": "firstnametest@example.com"})
def test_copy(self):
"""Copy the partner and compare the result."""
# Skip if ``mail`` is installed
if not self.mail_installed():
super(UserCase, self).test_copy()
Loading…
Cancel
Save