test_Save_calculationlevel_rulesettings.py 7.89 KB
import unittest
from atdd.PcApiTest import PcApiTest
import json
import os
from atdd.Config import Errocode
from tests.Integral.IntergalPC.test_jobLevel import jobLevel


# <新增>保存计算等级规则设置
class Saverulesetting(PcApiTest):
    def setUp(self):
        self.do_login(self.host, self.mobile, self.psw, self.domain)

    # 不传参数>>提示计算类型不能为空
    def test_save_none(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        code = Errocode().ERR_PARAM_CAN_NOT_BE_EMPTY   #预期结果
        data = {
        }
        result = self.PcApiTestAbnormal(interfaceUrl, data, code)

        self.assertEquals(code,result['errcode'])
        print(self.host + "/" + self.domain + interfaceUrl)

        self.assertEqual("积分等级计算类型不能为空", result["errmsg"], msg=result["errmsg"])
        print(result)
        return result


    # 计算类型>>角色>>roleId:测试
    def test_save_eilType2(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        data = {
            "eilType": 2,
            "eilObjId": "03A1C1127F0000012F7E32BF04E12787"
        }
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        self.assertEqual(0, result["errcode"], msg=result["errmsg"])
        self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result

    # 计算类型>>岗位>>jobId:研发工程师
    def test_save_eilType1(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        data = {
            "eilType": 1,
            "eilObjId": "BF2816A97F0000016AB2D549B08BE681"
        }
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        self.assertEqual(0, result["errcode"], msg=result["errmsg"])
        self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result

    # 计算类型>>角色>>列表中已存在的角色>>roleId:测试
    def test_save_reeilType2(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        data = {
            "eilType": 2,
            "eilObjId": "03A1C1127F0000012F7E32BF04E12787"
        }
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        self.assertEqual(0, result["errcode"], msg=result["errmsg"])
        self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result

    # 计算类型>>岗位>>列表中已存在的岗位
    def test_save_reeilType1(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        resultJobLevel = jobLevel().test_levelList_job()  #获取岗位信息list
        listJobLevel = resultJobLevel['result']['list']
        self.assertNotEquals(1, len(listJobLevel))
        lastJobeilObjId = listJobLevel[len(listJobLevel) - 1]['eilObjId']  # 最后一个岗位的岗位ID

        print(lastJobeilObjId)
        data = {
            "eilType": 1,
            "eilObjId": lastJobeilObjId
        }
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        #self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result

    # 上传参数数据类型转换
    def parse_array(self, prop, value_array):
        req_params = {}
        count = 0
        tpl = "{prop}[{count}][{key}]"
        for value in value_array:
            for key, val in value.items():
                req_params[tpl.format_map({
                    "prop": prop,
                    "count": count,
                    "key": key
                })] = val

            count += 1

        return req_params

    # 上传等级icon接口
    def test_UploadAtta(self):
        url = self.host + "/" + self.domain + "/Public/Apicp/Attachment/UploadAtta"
        # interfaceUrl = "/Public/Apicp/Attachment/UploadAtta"
        data = {
            "atMediatype": 1,
            "_identifier": "dengta"
        }
        file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + '/Integral/data/image/psb.jpg'
        files = {'file': ('psb.jpg', open(file_path, 'rb'), 'image/jpg')}

        print("上传文件", url)
        r = self.post(url, data, files=files)
        if(r.status_code == 200):  # 接口调用成功
            errcode = json.loads(r.text)['errcode']
            print(r.text)
            self.assertEquals(errcode, 0)
            return r.text
        else:
            print("接口调用失败:" + str(r.status_code))

    # 新增岗位类型>>jobId:研发工程师>>2个等级>>默认图标
    def test_save_eilType2level2(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        uploadAtta = json.loads(self.test_UploadAtta())
        # 获取icon的ID和URL
        icon = uploadAtta['result']['atId']
        iconUrl = uploadAtta['result']['atAttachment']
        data = self.parse_array("eilLevelSetting", [{
            "name": "api测试专用by-pooja1",
            "max": "10",
            "icon": icon,
            "iconType": "2",
            "iconUrl": iconUrl
            },
            {
                "name": "api测试专用by-pooja1",
                "max": "-1",
                "icon": icon,
                "iconType": "2",
                "iconUrl": iconUrl
            }
        ])
        data["eilId"] = "3F3D62517F00000164C1D217D101BD11"
        data["eilType"] = 1
        data["eilObjId"] = "BF2816A97F0000016AB2D549B08BE681"
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        self.assertEqual(0, result["errcode"], msg=result["errmsg"])
        self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result

    # 新增角色类型>>roleId:测试>>2个等级>>默认图标
    # def test_save_eilType1level2(self):
    #     interfaceUrl = "/Integral/Apicp/Level/Save"
    #     data = self.parse_array("eilLevelSetting", [{
    #         "name": "api测试专用by-pooja1",
    #         "max": "10",
    #         "icon": "3BDFA0A37F0000012C69697B395F092C",
    #         "iconType": "1"
    #     },
    #         {
    #         "name": "api测试专用by-pooja1",
    #         "max": "-1",
    #         "icon": "3BDFA0A37F0000012C69697B395F092C",
    #         "iconType": "1"
    #         }
    #     ])
    #     data["eilType"] = 2
    #     data["eilObjId"] = "03A1C1127F0000012F7E32BF04E12787"
    #     result = self.PcApiTest(interfaceUrl, data)
    #     print(self.host + "/" + self.domain + interfaceUrl)
    #     print(result)
    #     self.assertEqual(0, result["errcode"], msg=result["errmsg"])
    #     self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
    #     return result


    # 新增岗位类型>>jobId:研发工程师>>2个等级>>自定义图标
    def test_save_eilType2iconType2(self):
        interfaceUrl = "/Integral/Apicp/Level/Save"
        data = self.parse_array("eilLevelSetting", [{
            "name": "api测试专用by-pooja1",
            "max": "10",
            "icon": "3BDFA0A37F0000012C69697B395F092C",
            "iconType": "2",
            "iconUrl": "https://www.baidu.com/img/bd_logo1.png"
        },
        {
            "name": "api测试专用by-pooja1",
            "max": "-1",
            "icon": "3BDFA0A37F0000012C69697B395F092C",
            "iconType": "2",
            "iconUrl": "https://www.baidu.com/img/bd_logo1.png"
        }
        ])
        data["eilType"] = 1
        data["eilObjId"] = "BF2816A97F0000016AB2D549B08BE681"
        result = self.PcApiTest(interfaceUrl, data)
        print(self.host + "/" + self.domain + interfaceUrl)
        print(result)
        self.assertEqual(0, result["errcode"], msg=result["errmsg"])
        self.assertEqual("ok", result["errmsg"], msg=result["errmsg"])
        return result


if __name__ == '__main__':
    unittest.main()