|
| 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 | + experimental = { |
| 26 | + 'request_enqueuing': True, |
| 27 | + } |
| 28 | + settings = { |
| 29 | + 'distributed_tracing': True, |
| 30 | + 'experimental': experimental, |
| 31 | + } |
| 32 | + self.config._add('requests', settings) |
| 33 | + |
| 34 | + settings['distributed_tracing'] = False |
| 35 | + experimental['request_enqueuing'] = False |
| 36 | + ok_(self.config.requests['distributed_tracing'] is True) |
| 37 | + ok_(self.config.requests['experimental']['request_enqueuing'] is True) |
| 38 | + |
| 39 | + def test_missing_integration(self): |
| 40 | + # ensure a meaningful exception is raised when an integration |
| 41 | + # that is not available is retrieved in the configuration |
| 42 | + # object |
| 43 | + with assert_raises(ConfigException) as e: |
| 44 | + self.config.new_integration['some_key'] |
| 45 | + |
| 46 | + ok_(isinstance(e.exception, ConfigException)) |
| 47 | + |
| 48 | + def test_global_configuration(self): |
| 49 | + # ensure a global configuration is available in the `ddtrace` module |
| 50 | + ok_(isinstance(global_config, Config)) |
0 commit comments