test_utils.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from collections import Mapping, MutableMapping
  2. from case import Mock
  3. from celery.app.utils import Settings, filter_hidden_settings, bugreport
  4. class test_Settings:
  5. def test_is_mapping(self):
  6. """Settings should be a collections.Mapping"""
  7. assert issubclass(Settings, Mapping)
  8. def test_is_mutable_mapping(self):
  9. """Settings should be a collections.MutableMapping"""
  10. assert issubclass(Settings, MutableMapping)
  11. def test_find(self):
  12. assert self.app.conf.find_option('always_eager')
  13. def test_get_by_parts(self):
  14. self.app.conf.task_do_this_and_that = 303
  15. assert self.app.conf.get_by_parts(
  16. 'task', 'do', 'this', 'and', 'that') == 303
  17. def test_find_value_for_key(self):
  18. assert self.app.conf.find_value_for_key(
  19. 'always_eager') is False
  20. def test_table(self):
  21. assert self.app.conf.table(with_defaults=True)
  22. assert self.app.conf.table(with_defaults=False)
  23. assert self.app.conf.table(censored=False)
  24. assert self.app.conf.table(censored=True)
  25. class test_filter_hidden_settings:
  26. def test_handles_non_string_keys(self):
  27. """filter_hidden_settings shouldn't raise an exception when handling
  28. mappings with non-string keys"""
  29. conf = {
  30. 'STRING_KEY': 'VALUE1',
  31. ('NON', 'STRING', 'KEY'): 'VALUE2',
  32. 'STRING_KEY2': {
  33. 'STRING_KEY3': 1,
  34. ('NON', 'STRING', 'KEY', '2'): 2
  35. },
  36. }
  37. filter_hidden_settings(conf)
  38. class test_bugreport:
  39. def test_no_conn_driver_info(self):
  40. self.app.connection = Mock()
  41. conn = self.app.connection.return_value = Mock()
  42. conn.transport = None
  43. bugreport(self.app)