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