|
| 1 | +from unittest import TestCase |
| 2 | + |
| 3 | +from nose.tools import eq_, ok_, assert_raises |
| 4 | + |
| 5 | +from ddtrace import config as global_config |
| 6 | +from ddtrace.configuration import Config, ConfigException |
| 7 | + |
| 8 | + |
| 9 | +class ConfigTestCase(TestCase): |
| 10 | + """Test the `Configuration` class that stores integration settings""" |
| 11 | + def setUp(self): |
| 12 | + self.config = Config() |
| 13 | + |
| 14 | + def test_registration(self): |
| 15 | + # ensure an integration can register a new list of settings |
| 16 | + settings = { |
| 17 | + 'distributed_tracing': True, |
| 18 | + } |
| 19 | + self.config._add('requests', settings) |
| 20 | + ok_(self.config.requests['distributed_tracing'] is True) |
| 21 | + |
| 22 | + def test_settings_copy(self): |
| 23 | + # ensure that once an integration is registered, a copy |
| 24 | + # of the settings is stored to avoid side-effects |
| 25 | + settings = { |
| 26 | + 'distributed_tracing': True, |
| 27 | + } |
| 28 | + self.config._add('requests', settings) |
| 29 | + |
| 30 | + settings['distributed_tracing'] = False |
| 31 | + ok_(self.config.requests['distributed_tracing'] is True) |
| 32 | + |
| 33 | + def test_missing_integration(self): |
| 34 | + # ensure a meaningful exception is raised when an integration |
| 35 | + # that is not available is retrieved in the configuration |
| 36 | + # object |
| 37 | + with assert_raises(ConfigException) as e: |
| 38 | + self.config.new_integration['some_key'] |
| 39 | + |
| 40 | + ok_(isinstance(e.exception, ConfigException)) |
| 41 | + eq_(e.exception.message, 'Integration "new_integration" is not registered in this configuration') |
| 42 | + |
| 43 | + def test_global_configuration(self): |
| 44 | + # ensure a global configuration is available in the `ddtrace` module |
| 45 | + ok_(isinstance(global_config, Config)) |
0 commit comments