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.

52 lines
2.0 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.module_account = self.env.ref('base.module_account')
  14. self.main_company.write({'country_id': self.us_country.id})
  15. self.module_account.write({'state': 'uninstalled'})
  16. self.env_country = os.environ.get('COUNTRY')
  17. def tearDown(self):
  18. super(TestCompanyCountry, self).tearDown()
  19. os.environ['COUNTRY'] = self.env_country
  20. def test01_company_country_changed(self):
  21. self.wizard.load_company_country(country_code='MX')
  22. self.assertEqual(self.main_company.country_id, self.mx_country)
  23. def test02_country_environment_values(self):
  24. # Country Code unknown, should raise
  25. with self.assertRaises(ValidationError):
  26. self.wizard.load_company_country(country_code='BAD')
  27. # COUNTRY as empty string, should unset Country of main company
  28. os.environ['COUNTRY'] = ""
  29. self.wizard.load_company_country()
  30. self.assertEqual(self.main_company.country_id.id, False)
  31. # COUNTRY environment variable not set, should raise
  32. with self.assertRaises(ValidationError):
  33. l10n_to_install = self.env['ir.module.module'].search([
  34. ('state', '=', 'to install'),
  35. ('name', '=like', 'l10n_%')])
  36. l10n_to_install.write({'state': 'uninstalled'})
  37. del os.environ['COUNTRY']
  38. self.wizard.load_company_country()
  39. # Account is already installed, shouldn't raise
  40. self.module_account.write({'state': 'installed'})
  41. self.wizard.load_company_country()