def test_config(test_case, extra_config, expected_http_kwargs): instance = deepcopy(CONFIG['instances'][0]) instance.update(extra_config) check = TeamCityCheck(CHECK_NAME, {}, [instance]) with patch('datadog_checks.base.utils.http.requests.get') as r: check.check(instance) http_wargs = dict(auth=ANY, cert=ANY, headers=ANY, proxies=ANY, timeout=ANY, verify=ANY) http_wargs.update(expected_http_kwargs) r.assert_called_with(ANY, **http_wargs)
def test_build_event(aggregator): teamcity = TeamCityCheck('teamcity', {}, {}) with patch('requests.get', get_mock_first_build): teamcity.check(CONFIG['instances'][0]) assert len(aggregator.metric_names) == 0 assert len(aggregator.events) == 0 aggregator.reset() with patch('requests.get', get_mock_one_more_build): teamcity.check(CONFIG['instances'][0]) events = aggregator.events assert len(events) == 1 assert events[0]['msg_title'] == "Build for One test build successful" assert ( events[0]['msg_text'] == "Build Number: 2\nDeployed To: buildhost42.dtdg.co\n\nMore Info: " + "http://localhost:8111/viewLog.html?buildId=2&buildTypeId=TestProject_TestBuild" ) assert events[0]['tags'] == ['build', 'one:tag', 'one:test'] assert events[0]['host'] == "buildhost42.dtdg.co" aggregator.reset() # One more check should not create any more events with patch('requests.get', get_mock_one_more_build): teamcity.check(CONFIG['instances'][0]) assert len(aggregator.events) == 0
def test_build_event(aggregator): agent_config = {'version': '0.1', 'api_key': 'toto'} check = TeamCityCheck('teamcity', {}, agent_config, INSTANCES) with patch('requests.get', get_mock_first_build): check.check(check.instances[0]) assert len(aggregator.metric_names) == 0 assert len(aggregator.events) == 0 aggregator.reset() with patch('requests.get', get_mock_one_more_build): check.check(check.instances[0]) events = aggregator.events assert len(events) == 1 assert events[0]['msg_title'] == "Build for One test build successful" assert events[0]['msg_text'] == "Build Number: 2\nDeployed To: buildhost42.dtdg.co\n\nMore Info: " + \ "http://localhost:8111/viewLog.html?buildId=2&buildTypeId=TestProject_TestBuild" assert events[0]['tags'] == ['build', 'one:tag', 'one:test'] assert events[0]['host'] == "buildhost42.dtdg.co" aggregator.reset() # One more check should not create any more events with patch('requests.get', get_mock_one_more_build): check.check(check.instances[0]) assert len(aggregator.events) == 0