Beispiel #1
0
def test_compare(policy, mocker):
    mocker.patch("django.core.cache.cache.get", side_effect=query_result)
    datas = DataSource(policy).get_data()
    alarms = Judge(datas, policy).compare()
    expect_alarms = [{"node": "server01"}, {"node": "server03"}]

    assert alarms == expect_alarms
Beispiel #2
0
def test_compare(policy, mocker):
    mocker.patch("django.core.cache.cache.get", side_effect=query_result)
    datas = DataSource(policy).get_data()
    alarms = Judge(datas, policy).compare()
    expect_alarms = [{"node": "server02"}, {"node": "server05"}]

    assert len(alarms) == len(expect_alarms)
    for alarm in alarms:
        assert alarm in expect_alarms
Beispiel #3
0
def test_create_alarm(policy, mocker):
    mocker.patch("django.core.cache.cache.get", side_effect=query_result)
    mock = mocker.patch("antilles.alarm.models.Alarm.objects.create")
    datas = DataSource(policy).get_data()
    alarms = Judge(datas, policy).compare()

    for alarm in alarms:
        alarm.update({"policy_id": policy.id})
        create_alarm(alarm)

        mock.assert_called_with(**dict({"policy": policy}, **alarm))
Beispiel #4
0
def test_create_alarm(policy, mocker):
    mocker.patch("django.core.cache.cache.get", side_effect=query_result)
    mock = mocker.patch("antilles.alarm.models.Alarm.objects.create")
    datas = DataSource(policy).get_data()
    alarms = Judge(datas, policy).compare()
    alarms[0].update({"policy_id": policy.id})
    create_alarm(alarms[0])

    mock.assert_called_once_with(**{
        "policy_id": policy.id,
        "policy": policy,
        "node": "server01"
    })