# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01


from __future__ import division

from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Action.action_get import ActionGet

import allure

# allure.label("")


@allure.feature("测试模块：action.get")
class TestActionGet(object):
    log = UtilsLog()
    env = CaseBase().environment
    host = env["host"]
    db_url = env["db_url"]
    db_port = env["db_port"]
    db_user = env["db_user"]
    db_pw = env["db_pw"]
    db_base = env["db_base"]

    @classmethod
    def setup_class(cls):
        cls.log.debug("开始执行测试套件.......")

    @classmethod
    def teardown_class(cls):
        cls.log.debug("结束执行测试套件.......")

    def setup_method(self):
        self.log.debug("测试用例执行开始...")

    def teardown_method(self):
        self.log.debug("测试用例执行结束...")

    @allure.step("调用接口：action.get")
    def action_get(self, actionids=None, groupids=None, hostids=None, triggerids=None, mediatypeids=None, usrgrpids=None, userids=None,
                   scriptids=None, selectFilter=None, selectOperations=None, selectRecoveryOperations=None, selectAcknowledgeOperations=None,
                   countOutput=None, editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
                   searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
        api = ActionGet(_host=self.host)
        api.actionids = actionids
        api.groupids = groupids
        api.hostids = hostids
        api.triggerids = triggerids
        api.mediatypeids = mediatypeids
        api.usrgrpids = usrgrpids
        api.userids = userids
        api.scriptids = scriptids
        api.selectFilter = selectFilter
        api.selectOperations = selectOperations
        api.selectRecoveryOperations = selectRecoveryOperations
        api.selectAcknowledgeOperations = selectAcknowledgeOperations
        api.countOutput = countOutput
        api.editable = editable
        api.excludeSearch = excludeSearch
        api.filter = _filter
        api.limit = limit
        api.output = output
        api.preservekeys = preservekeys
        api.search = search
        api.searchByAny = searchByAny
        api.searchWildcardsEnabled = searchWildcardsEnabled
        api.sortfield = sortfield
        api.sortorder = sortorder
        api.startSearch = startSearch
        api.get_response()
        return api.response

    @allure.step("断言返回结果")
    def check_code(self, response, code):
        _code = UtilsResponse().get_code(response=response)
        assert _code == code

    @allure.title("action.get：无参数调用")
    @allure.story("查询动作：无参数调用")
    @allure.severity("blocker")
    def test_case_01(self):
        response = self.action_get()
        self.check_code(response=response, code=0)

    @allure.title("action.get：countOutput=true")
    @allure.story("查询动作：countOutput=true")
    def test_case_02(self):
        response = self.action_get(countOutput="true")
        self.check_code(response=response, code=0)

    @allure.title("action.get：actionids=特定IDs")
    @allure.story("查询动作：actionids=特定IDs")
    def test_case_03(self):
        response = self.action_get(actionids=[7])
        self.check_code(response=response, code=0)


if __name__ == "__main__":
    from WorkUtils.UtilsPyTest import UtilsPyTest
    from WorkUtils.UtilsCmd import UtilsCmd

    import os

    # 执行自动化测试用例
    case_info = os.path.split(__file__)
    case = UtilsCmd().pytest_cmd()
    r = UtilsPyTest(case=case, case_info=case_info)
    r.run_main()

    # a = TestActionGet()
    # a.test_case_04()
