# -*- 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.MediaType.mediatype_create import MediaTypeCreate

import allure

# allure.label("")


@allure.feature("测试模块：mediatype.create")
class TestMediaTypeCreate(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"]

    base_description = "SS测试媒体"

    @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("调用接口：mediatype.create")
    def mediatype_create(self, description=None, _type=None, exec_path=None, gsm_modem=None, passwd=None, smtp_email=None,
                         smtp_helo=None, smtp_server=None, smtp_port=None, smtp_security=None, smtp_verify_host=None, smtp_verify_peer=None,
                         smtp_authentication=None, status=None, username=None, exec_params=None, maxsessions=None, maxattempts=None,
                         attempt_interval=None, content_type=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 = MediaTypeCreate(_host=self.host)
        api.description = description
        api.type = _type
        api.exec_path = exec_path
        api.gsm_modem = gsm_modem
        api.passwd = passwd
        api.smtp_email = smtp_email
        api.smtp_helo = smtp_helo
        api.smtp_server = smtp_server
        api.smtp_port = smtp_port
        api.smtp_security = smtp_security
        api.smtp_verify_host = smtp_verify_host
        api.smtp_verify_peer = smtp_verify_peer
        api.smtp_authentication = smtp_authentication
        api.status = status
        api.username = username
        api.exec_params = exec_params
        api.maxsessions = maxsessions
        api.maxattempts = maxattempts
        api.attempt_interval = attempt_interval
        api.content_type = content_type
        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("mediatype.create：description=字符串, _type=0")
    @allure.story("创建媒体：description=字符串, _type=0")
    @allure.severity("blocker")
    def test_case_01(self):
        description = self.base_description + "01"
        _type = 0
        response = self.mediatype_create(description=description, _type=_type)
        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 = TestMediaTypeCreate()
    # a.test_case_01()
