urd_odoo_addons/partner_firstname/tests/test_empty.py

68 lines
2.2 KiB
Python
Raw Normal View History

2018-04-18 17:23:07 +02:00
# -*- coding: utf-8 -*-
# Odoo, Open Source Management Solution
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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 ..models import exceptions as ex
class CompanyCase(TransactionCase):
"""Test ``res.partner`` when it is a company."""
model = "res.partner"
context = {"default_is_company": True}
def tearDown(self):
try:
data = {"name": self.name}
with self.assertRaises(ex.EmptyNamesError):
self.env[self.model].with_context(**self.context).create(data)
finally:
super(CompanyCase, self).tearDown()
def test_name_empty_string(self):
"""Test what happens when the name is an empty string."""
self.name = ""
def test_name_false(self):
"""Test what happens when the name is ``False``."""
self.name = False
class PersonCase(CompanyCase):
"""Test ``res.partner`` when it is a person."""
context = {"default_is_company": False}
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()