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.

73 lines
3.0 KiB

  1. # #############################################################################
  2. #
  3. # OpenERP, Open Source Management Solution
  4. # This module copyright (C) 2010 - 2014 Savoir-faire Linux
  5. # (<http://www.savoirfairelinux.com>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from odoo.tests import common
  22. import zipfile
  23. import io
  24. class TestPrototypeModuleExport(common.TransactionCase):
  25. def setUp(self):
  26. super(TestPrototypeModuleExport, self).setUp()
  27. self.main_model = self.env["module_prototyper.module.export"]
  28. self.prototype_model = self.env["module_prototyper"]
  29. self.module_category_model = self.env["ir.module.category"]
  30. self.prototype = self.prototype_model.create(
  31. {
  32. "name": "t_name",
  33. "category_id": self.module_category_model.browse(1).id,
  34. "human_name": "t_human_name",
  35. "summary": "t_summary",
  36. "description": "t_description",
  37. "author": "t_author",
  38. "maintainer": "t_maintainer",
  39. "website": "t_website",
  40. }
  41. )
  42. self.exporter = self.main_model.create({"name": "t_name"})
  43. def test_action_export_assert_for_wrong_active_model(self):
  44. """Test if the assertion raises."""
  45. exporter = self.main_model.with_context(
  46. active_model="t_active_model"
  47. ).create({})
  48. self.assertRaises(
  49. AssertionError, exporter.action_export, [exporter.id]
  50. )
  51. def test_action_export_update_wizard(self):
  52. """Test if the wizard is updated during the process."""
  53. exporter = self.main_model.with_context(
  54. active_model=self.prototype_model._name,
  55. active_id=self.prototype.id,
  56. ).create({})
  57. exporter.action_export(exporter.id)
  58. self.assertEqual(exporter.state, "get")
  59. self.assertEqual(exporter.name, "%s.zip" % (self.prototype.name,))
  60. def test_zip_files_returns_tuple(self):
  61. """Test the method return of the method that generate the zip file."""
  62. ret = self.main_model.zip_files(self.exporter, [self.prototype])
  63. self.assertIsInstance(ret, tuple)
  64. self.assertIsInstance(ret.zip_file, zipfile.ZipFile)
  65. self.assertIsInstance(ret.BytesIO, io.BytesIO)