No Description
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.

test_uniqid.py 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import unittest
  20. from unittest import mock
  21. from unittest.mock import patch
  22. import leapi_dyncode as dyncode
  23. from lodel.leapi.datahandlers.datas import UniqID as Testee
  24. from lodel.plugins.dummy_datasource.datasource import DummyDatasource
  25. class UniqIDTestCase(unittest.TestCase):
  26. def test_base_type_is_set_to_int(self):
  27. self.assertEqual(Testee.base_type, 'int')
  28. def test_help_property_str_is_set(self):
  29. self.assertEqual(type(Testee.help), str)
  30. def test_internal_set_as_automatic_by_default(self):
  31. self.assertEqual(Testee().internal, 'automatic')
  32. def test_construct_data_sets_new_uid_if_none(self):
  33. set_uid = None
  34. mocked_returned_uid = 987654321
  35. with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
  36. returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
  37. mock_method.assert_called_once_with(dyncode.Object)
  38. self.assertEqual(returned_uid, mocked_returned_uid)
  39. def test_construct_data_returns_already_set_uid(self):
  40. set_uid = 123456789
  41. mocked_returned_uid = 987654321
  42. with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
  43. returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
  44. self.assertEqual(returned_uid, set_uid)
  45. def test_construct_data_does_not_call_new_numeric_id_if_id_is_set(self):
  46. set_uid = 123456789
  47. mocked_returned_uid = 987654321
  48. with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
  49. returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
  50. mock_method.assert_not_called()