def test_config_project(aggregator, instance, fixture_group): project = 'foo' project_tag = 'project:{}'.format(project) qparams = {'project': project} instance['project'] = project check = TwistlockCheck('twistlock', {}, [instance]) with mock.patch('requests.get', side_effect=mock_get_factory(fixture_group), autospec=True) as r: check.check(instance) r.assert_called_with( mock.ANY, params=qparams, auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY, allow_redirects=mock.ANY, ) # Check if metrics are tagged with the project. for metric in METRICS: aggregator.assert_metric_has_tag(metric, project_tag)
def test_err_response(aggregator): check = TwistlockCheck('twistlock', {}, [instance]) with pytest.raises(Exception, match='^Error in response'): with mock.patch('requests.get', return_value=MockResponse('{"err": "invalid credentials"}'), autospec=True): check.check(instance)
def test_check(aggregator): check = TwistlockCheck('twistlock', {}, {}) with mock.patch('requests.get', side_effect=mock_get, autospec=True): check.check(instance) check.check(instance) for metric in METRICS: aggregator.assert_metric(metric) aggregator.assert_metric_has_tag(metric, customtag) aggregator.assert_all_metrics_covered()
def test_check(aggregator, instance, fixture_group): check = TwistlockCheck('twistlock', {}, [instance]) with mock.patch('requests.get', side_effect=mock_get_factory(fixture_group), autospec=True): check.check(instance) check.check(instance) for metric in METRICS: aggregator.assert_metric(metric) aggregator.assert_metric_has_tag(metric, customtag) aggregator.assert_all_metrics_covered() aggregator.assert_metrics_using_metadata(get_metadata_metrics())