def test_reread(): conf1 = ("checks:\n" " - name: Name\n" " url: URL\n") conf2 = conf1 + " period: 60\n" with patch_creds(""): with patch_conf(conf1): conf = ReloadableSettings('::') # Config didn't change: assert not conf.reread() with patch_conf(conf2): # Config changed: assert conf.reread() assert conf.checks == [{'name': 'Name', 'url': 'URL', 'period': 60}]
def test_unnamed_check(): conf = "checks: [{period: 1}]" with patch_conf(conf): conf = ReloadableSettings('::') assert conf.checks == [{ 'name': 'Unnamed check 1', 'period': 1, }]
def test_unnamed_check(): conf = "checks: [{period: 1}]" with patch_conf(conf): conf = ReloadableSettings('::') assert conf.checks == [{ 'name': 'Unnamed check 1', 'schedule': [TimelineRule(interval=1, unit='seconds', at=None)] }]
def test_reread(): conf1 = ("checks:\n" " - name: Name\n" " url: URL\n") conf2 = conf1 + " period: 60\n" with patch_creds(""): with patch_conf(conf1): conf = ReloadableSettings('::') # Config didn't change: assert not conf.reread() with patch_conf(conf2): # Config changed: assert conf.reread() assert conf.checks == [{ 'name': 'Name', 'url': 'URL', 'schedule': [TimelineRule(interval=60, unit='seconds', at=None)] }]
def test_empty_period(): conf = "checks: [{name: x}]" with patch_conf(conf): conf = ReloadableSettings('::') assert conf.checks[0]['period'] == 300
def test_period_parse(): conf = "checks: [{period: 1 hour}]" with patch_conf(conf): conf = ReloadableSettings('::') assert conf.checks[0]['period'] == 3600
def test_name_from_url_population(): conf = "checks: [{url: 'http://example.com/page_name'}]" with patch_conf(conf): conf = ReloadableSettings('::') assert conf.checks[0]['name'] == 'http-example-com-page_name'
def test_complex_conf_sample(): with patch_conf(sample_conf): with patch_creds(sample_creds): conf = ReloadableSettings('::') assert conf.checks == checks assert conf.creds['mailgun']['url'] == 'ZZZ'