test_warning_operations.py 4.1 KB
Newer Older
lcn's avatar
lcn committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
import json
import pytest
from unify_api.tests.constants_t import post_request, get_request


# 返回平台
class TestProduct(object):
    url = "/unify-api/zhiwei-u/warning-operations/product"

    @pytest.mark.asyncio
    async def test_product(self):
        resp_str, status = await get_request(self.url)
        assert status == 200


# 报警类型 工单类型
class TestWarningType(object):
    url = "/unify-api/zhiwei-u/warning-operations/warning-type"

    @pytest.mark.asyncio
    async def test_warning_type(self):
        resp_str, status = await get_request(self.url)
        assert status == 200


# 返回平台
class TestSelectUser(object):
    url = "/unify-api/zhiwei-u/warning-operations/select-user"

    @pytest.mark.parametrize('data', [{
        "prod_id": 0}, {"prod_id": 3}, {"prod_id": 9}
    ])
    @pytest.mark.asyncio
    async def test_select_user(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert isinstance(resp_dict["data"]["data"], list)


# 平台、客户选择监测点
class TestSelectPoint(object):
    url = "/unify-api/zhiwei-u/warning-operations/select-point"

    @pytest.mark.parametrize('data', [{
        "cid": 44}, {"cid": 117}, {"cid": 119}, {"cid": 10000}, {"cid": 0}
    ])
    @pytest.mark.asyncio
    async def test_select_point(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert isinstance(resp_dict["data"]["data"], list)


# 运维报警状态改变为已忽略
class TestWarningStateIgnore:
    url = "/unify-api/zhiwei-u/warning-operations/warning-state-ignore"

    @pytest.mark.parametrize('data', [{
        "id": [10, 11, 12, 1000, 0, -1, "15"], "remark": "错误告警"}
    ])
    @pytest.mark.asyncio
    async def test_warning_state_ignore(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 1

    @pytest.mark.parametrize('data', [{
        "id": [], "remark": ""}, {"id": ["sss"], "remark": ""}
    ])
    @pytest.mark.asyncio
    async def test_warning_state_ignore_no_data(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 0


# 运维报警 已忽略撤销
class TestWarningStateFocus:
    url = "/unify-api/zhiwei-u/warning-operations/warning-state-focus"

    @pytest.mark.parametrize('data', [{
        "id": [10, 11, 12, 1000, 0, -1, "15"]}
    ])
    @pytest.mark.asyncio
    async def test_warning_state_focus(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 1

    @pytest.mark.parametrize('data', [{
        "id": []}, {"id": ["sss"]}
    ])
    @pytest.mark.asyncio
    async def test_warning_state_focus_no_data(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 0


# 运维报警 转为工单
class TestWarningToOrder:
    url = "/unify-api/zhiwei-u/warning-operations/warning-to-order"

    @pytest.mark.parametrize('data', [{
        "id": [10, 11, 12, 1000, 0, -1, "15"], "user_id": 88}
    ])
    @pytest.mark.asyncio
    async def test_warning_to_order(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 1

    @pytest.mark.parametrize('data', [{
        "id": [], "user_id": 12}, {"id": ["sss"], "user_id": 88}
    ])
    @pytest.mark.asyncio
    async def test_warning_to_order_no_data(self, data):
        resp_str, status = await post_request(self.url, data)
        assert status == 200
        resp_dict = json.loads(resp_str)
        assert resp_dict["data"]["success"] == 0