You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

  1. # Copyright 2016 Vauxoo
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import os
  4. from odoo.exceptions import ValidationError
  5. from odoo.tests.common import TransactionCase
  6. class TestCompanyCountry(TransactionCase):
  7. def setUp(self):
  8. super(TestCompanyCountry, self).setUp()
  9. self.wizard = self.env['company.country.config.settings']
  10. self.us_country = self.env.ref('base.us')
  11. self.mx_country = self.env.ref('base.mx')
  12. self.main_company = self.env.ref('base.main_company')
  13. self.main_company.write({'country_id': self.us_country.id})
  14. self.env_country = os.environ.get('COUNTRY')
  15. def tearDown(self):
  16. super(TestCompanyCountry, self).tearDown()
  17. os.environ['COUNTRY'] = self.env_country
  18. def test01_company_country_changed(self):
  19. self.wizard.load_company_country(country_code='MX')
  20. self.assertEqual(self.main_company.country_id, self.mx_country)
  21. def test02_country_environment_values(self):
  22. # Country Code unknown, should raise
  23. with self.assertRaises(ValidationError):
  24. self.wizard.load_company_country(country_code='BAD')
  25. # COUNTRY as empty string, should unset Country of main company
  26. os.environ['COUNTRY'] = ""
  27. self.wizard.load_company_country()
  28. self.assertEqual(self.main_company.country_id.id, False)
  29. # COUNTRY environment variable not set, should raise
  30. with self.assertRaises(ValidationError):
  31. l10n_to_install = self.env['ir.module.module'].search([
  32. ('state', '=', 'to install'),
  33. ('name', '=like', 'l10n_%')])
  34. l10n_to_install.write({'state': 'uninstalled'})
  35. del os.environ['COUNTRY']
  36. self.wizard.load_company_country()