From 6ffca482b2efeb7208d80232e1c0f814f1787928 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 2 Jul 2015 10:17:11 +0200 Subject: [PATCH] Add new tests and fix the resulting bugs. --- partner_firstname/models.py | 4 +- partner_firstname/tests/__init__.py | 2 +- partner_firstname/tests/test_empty.py | 53 +++++++++++++++++++ ...test_partner_firstname.py => test_name.py} | 0 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 partner_firstname/tests/test_empty.py rename partner_firstname/tests/{test_partner_firstname.py => test_name.py} (100%) diff --git a/partner_firstname/models.py b/partner_firstname/models.py index 83aa50a88..96c0876e0 100644 --- a/partner_firstname/models.py +++ b/partner_firstname/models.py @@ -55,7 +55,7 @@ class ResPartner(models.Model): submodules can extend that method and get whitespace cleaning for free. """ # Remove unneeded whitespace - clean = u" ".join(self.name.split(None)) + clean = u" ".join(self.name.split(None)) if self.name else self.name # Clean name avoiding infinite recursion if self.name != clean: @@ -78,7 +78,7 @@ class ResPartner(models.Model): trimmed whitespace. """ # Company name goes to the lastname - if self.is_company: + if self.is_company or self.name is False: parts = [self.name, False] # Guess name splitting diff --git a/partner_firstname/tests/__init__.py b/partner_firstname/tests/__init__.py index 71518a9dc..4d47eee87 100644 --- a/partner_firstname/tests/__init__.py +++ b/partner_firstname/tests/__init__.py @@ -28,4 +28,4 @@ # ############################################################################## -from . import test_partner_firstname +from . import test_name, test_empty diff --git a/partner_firstname/tests/test_empty.py b/partner_firstname/tests/test_empty.py new file mode 100644 index 000000000..6b0c222f5 --- /dev/null +++ b/partner_firstname/tests/test_empty.py @@ -0,0 +1,53 @@ +# -*- encoding: utf-8 -*- + +# Odoo, Open Source Management Solution +# Copyright (C) 2014-2015 Grupo ESOC +# +# 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 . + +from openerp.tests.common import TransactionCase +from .. 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): + """Test ``res.users``.""" + model = "res.users" + context = {"default_login": "user@example.com"} diff --git a/partner_firstname/tests/test_partner_firstname.py b/partner_firstname/tests/test_name.py similarity index 100% rename from partner_firstname/tests/test_partner_firstname.py rename to partner_firstname/tests/test_name.py