Esempio n. 1
0
def test_create_metric_widget_with_missing_granularity(monkeypatch,
                                                       aws_credentials):
    monkeypatch.setenv("namespace", "namespace")
    repo_name = 'repo-name'
    metric_data = {'test_val_2': 12000}
    title = 'repo-name widget'
    metric_widget = cw.create_metric_widget(repo_name,
                                            metric_data,
                                            title=title,
                                            id_str='test')
    widget_metric_data = [['namespace', 'test_val_2', 'REPO_NAME', repo_name]]

    metric_widget_to_compare = {
        'type': 'metric',
        'width': 6,
        'height': 3,
        'properties': {
            'metrics': widget_metric_data,
            'view': 'singleValue',
            'period': 3600,
            'stat': 'Maximum',
            'region': 'us-west-2',
            'title': title
        }
    }

    assert metric_widget == metric_widget_to_compare
Esempio n. 2
0
def test_create_metric_widget_empty_metric_data(monkeypatch, aws_credentials):
    monkeypatch.setenv("namespace", "namespace")
    repo_name = 'repo-name'
    metric_data = {'test_val_2': 12000}
    title = 'repo-name widget'
    metric_widget = cw.create_metric_widget(repo_name, {}, title=title)
    assert not metric_widget
Esempio n. 3
0
def test_create_metric_widget_good_input_with_granularity_days(
        monkeypatch, aws_credentials):
    monkeypatch.setenv("namespace", "namespace")
    repo_name = 'repo-name'
    metric_data = {'test_val_2': 12000}
    title = 'repo-name widget'
    metric_widget = cw.create_metric_widget(repo_name,
                                            metric_data,
                                            title=title,
                                            id_str='test',
                                            granularity='days')
    widget_metric_data = [[
        'namespace', 'test_val_2', 'REPO_NAME', repo_name, {
            "id": 'test',
            "visible": False
        }
    ],
                          [{
                              'expression': 'test/(3600*24)',
                              'label': 'test_val_2 (in days)',
                              "id": "testExpression"
                          }]]

    metric_widget_to_compare = {
        'type': 'metric',
        'width': 6,
        'height': 3,
        'properties': {
            'metrics': widget_metric_data,
            'view': 'singleValue',
            'period': 3600,
            'stat': 'Maximum',
            'region': 'us-west-2',
            'title': title
        }
    }

    assert metric_widget == metric_widget_to_compare
Esempio n. 4
0
def test_create_metric_widget_verify_height_functionality(
        monkeypatch, aws_credentials):
    monkeypatch.setenv("namespace", "namespace")
    repo_name = 'repo-name'
    title = 'repo-name widget'

    metric_data_height_1 = {
        'test_val_1': 12000,
        'test_val_2': 12000,
        'test_val_3': 12000,
    }
    metric_widget_height_1 = cw.create_metric_widget(repo_name,
                                                     metric_data_height_1,
                                                     title=title)
    widget_metric_data_height_1 = [[
        'namespace', 'test_val_1', 'REPO_NAME', repo_name
    ], ['namespace', 'test_val_2', 'REPO_NAME',
        repo_name], ['namespace', 'test_val_3', 'REPO_NAME', repo_name]]
    metric_widget_to_compare_height_1 = {
        'type': 'metric',
        'width': 6,
        'height': 3,
        'properties': {
            'metrics': widget_metric_data_height_1,
            'view': 'singleValue',
            'period': 3600,
            'stat': 'Maximum',
            'region': 'us-west-2',
            'title': title
        }
    }

    metric_data_height_2 = {
        'test_val_1': 12000,
        'test_val_2': 12000,
        'test_val_3': 12000,
        'test_val_4': 12000
    }
    metric_widget_height_2 = cw.create_metric_widget(repo_name,
                                                     metric_data_height_2,
                                                     title=title)
    widget_metric_data_height_2 = [
        ['namespace', 'test_val_1', 'REPO_NAME', repo_name],
        ['namespace', 'test_val_2', 'REPO_NAME', repo_name],
        ['namespace', 'test_val_3', 'REPO_NAME', repo_name],
        ['namespace', 'test_val_4', 'REPO_NAME', repo_name]
    ]
    metric_widget_to_compare_height_2 = {
        'type': 'metric',
        'width': 6,
        'height': 6,
        'properties': {
            'metrics': widget_metric_data_height_2,
            'view': 'singleValue',
            'period': 3600,
            'stat': 'Maximum',
            'region': 'us-west-2',
            'title': title
        }
    }

    assert metric_widget_height_1 == metric_widget_to_compare_height_1
    assert metric_widget_height_2 == metric_widget_to_compare_height_2