示例#1
0
def test_server_normalization():
    """
    Make sure server URLs are being normalized correctly
    """

    teamcity = TeamCityCheck("teamcity", {}, {})

    for server, expected_server in iteritems(TEAMCITY_SERVER_VALUES):
        normalized_server = teamcity._normalize_server_url(server)

        assert expected_server == normalized_server
示例#2
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
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_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)