test_utils.py 1.8 KB

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