receiveios.py 7.91 KB
Newer Older
liuxiaoxing committed
1 2 3
import requests
import json
import pytest
liuxiaoxing committed
4
import time
liuxiaoxing committed
5

liuxiaoxing committed
6 7
# url = "http://tkiomicro-receive-788931749.cn-north-1.elb.amazonaws.com.cn/receive/tkiov2/sdk"

liuxiaoxing committed
8 9 10
chaochang = '543214223221321321312131313133132131232131232132132543214223221321321312131313133132131232131232132132543214223221321321312131313133132131232131232132132'

headers = {
liuxiaoxing committed
11
    'Content-Type': 'application/json'
liuxiaoxing committed
12 13 14 15 16 17
}

global data
data = [
    {
        "application_info": {
liuxiaoxing committed
18
            # 线上-55705dbd45dd246751b87bba94b8c73c
liuxiaoxing committed
19
            # 测试-55705dbd45dd246751b87bba94b8c73c
liuxiaoxing committed
20
            "appkey": "55705dbd45dd246751b87bba94b8c73c",
liuxiaoxing committed
21 22 23 24 25 26
            "bundleid": "3423232",
            "app_version": "1.9.0",
            "channel_name": "default"
        },
        "timestamp_info": {
            "time_zone": "GMT+08",
liuxiaoxing committed
27 28 29
            "install_time": int(round(time.time() * 1000)),
            "current_event_time": int(round(time.time() * 1000)),
            "report_time": int(round(time.time() * 1000)),
liuxiaoxing committed
30 31 32 33 34 35 36 37
        },
        "collector_info": {
            "integration_type": "sdk",
            "collector_version": "1.8.4",
            "retried_times": ""
        },
        "device_info": {
            "ryid": "8e4888e488a40a17aed2f6752f51382a4eafc",
liuxiaoxing committed
38 39 40 41 42 43 44 45 46 47 48 49 50
            "device_id": "c3381276ae145b3663c8e0f6dd9f628a",
            "device_id_type": "idfa_md5",
            "device_id_md5": "c3381276ae145b3663c8e0f6dd9f628a",
            "device_id_md5_type": "idfa_md5",
            "os": "ios",
            "os_version": "19",
            "manufacturer": "HUAWEI",
            "model": "Mate 40",
            # "ipv4": "",
            "ipv6": "1.1.1",
            "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36",
            "att_status": "unknown",
            "lat_status": "disable",
liuxiaoxing committed
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
            "idfa": "3DEA635F-B24F-434B-833F-4ED028FEAEEF",
            "idfa_md5": "c3381276ae145b3663c8e0f6dd9f628a",
            "idfv": "3DEA635F-B24F-434B-833F-4ED028FEAEEF",
            "idfv_md5": "c3381276ae145b3663c8e0f6dd9f628a",

        },
        "event_info": {
            "event_name": "install",
            "event_type": "preset",
            "event_data": {
                "user_id": "guest123",
                "register_type": "WeChat",
                "login_type": "Wechat",
                "order_id": "2341242342676398724",
                "order_amount": "343432",
                "currency_type": "CNY",
                "purchase_type": "Alipay",
                "ad_platform": "csj",
                "placement_type": "interstitial",
                "placement_id": "23425334",
                "ad_price": "4.34",
                "ad_price_currency_type": "CNY",
                "is_rendered": "1"
            },
            "custom_params": {
                # "add_cart": "234234",
                # "sku": "234234",
                # "level_up": "234234",
                # "refund": "234234",
                # "refund_amount": "234234"
            }
        }
    }
]
data_temp = json.dumps(data)

liuxiaoxing committed
87

liuxiaoxing committed
88 89
def send_request():
    global data
liuxiaoxing committed
90 91 92 93 94
    # 测试
    # url = "http://tkiomicro-receive-788931749.cn-north-1.elb.amazonaws.com.cn/receive/tkiov2/sdk"
    # 线上
    url = "http://tkio-receive.solar-engine.com/receive/tkiov2/sdk"

liuxiaoxing committed
95
    data[0]['timestamp_info']['install_time'] = int(round(time.time() * 1000))
liuxiaoxing committed
96
    data[0]['timestamp_info']['current_event_time'] = int(round(time.time() * 1000))
liuxiaoxing committed
97
    print(data)
liuxiaoxing committed
98 99 100 101 102 103 104 105 106 107
    response = requests.request("POST", url, headers=headers, data=json.dumps(data))
    print(response.text)
    # 全局data
    data = json.loads(data_temp)
    response = json.loads(response.text)
    s = str(response["status"])
    response["status"] = s
    return response


liuxiaoxing committed
108 109 110
def send_request2():
    global data
    url = "http://tkiomicro-receive-788931749.cn-north-1.elb.amazonaws.com.cn/receive/tkiov2/s2s"
liuxiaoxing committed
111 112
    # 线上
    url = "http://tkio-receive.solar-engine.com/receive/tkiov2/s2s"
liuxiaoxing committed
113 114 115 116 117 118 119 120 121 122 123 124
    data[0]['timestamp_info']['install_time'] = int(round(time.time() * 1000))
    data[0]['timestamp_info']['current_event_time'] = int(round(time.time() * 1000))
    # print(data)
    response = requests.request("POST", url, headers=headers, data=json.dumps(data))
    print(response.text)
    # 全局data
    data = json.loads(data_temp)
    response = json.loads(response.text)
    s = str(response["status"])
    response["status"] = s
    return response

liuxiaoxing committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

# os为ios,channel_name不等于default
def test_os_ios():
    data[0]["device_info"]["os"] = 'ios'
    data[0]['application_info']['channel_name'] = 'xiaomi'
    response = send_request()
    assert response["status"] == "104"


# os为大写iOS
def test_os_ios():
    data[0]["device_info"]["os"] = 'iOS'
    response = send_request()
    assert response["status"] == "115"


# ATT框架启用状态,为固定值
def test_att_status1():
    lis = ['denied', 'restricted', 'authorized', 'unknown']
    for astatus in lis:
        data[0]['device_info']['att_status'] = astatus
        response = send_request()
        assert response["status"] == "0"


# ATT框架启用状态,为其他值
def test_att_status2():
    data[0]['device_info']['att_status'] = "aaa"
    response = send_request()
    assert response["status"] == "122"


# ATT框架启用状态,为空
def test_att_status3():
    data[0]['device_info']['att_status'] = ""
    response = send_request()
    assert response["status"] == "0"


# LAT启用状态,固定值
def test_lat_status1():
    lis = ['enable', 'disable', 'unknown']
    for astatus in lis:
        data[0]['device_info']['lat_status'] = astatus
        response = send_request()
        assert response["status"] == "0"


# LAT启用状态,其他值
def test_lat_status2():
    data[0]['device_info']['lat_status'] = "aaa"
    response = send_request()
    assert response["status"] == "123"


# LAT启用状态,空
def test_lat_status3():
    data[0]['device_info']['lat_status'] = ""
    response = send_request()
    assert response["status"] == "0"

liuxiaoxing committed
186

liuxiaoxing committed
187 188 189 190 191 192 193 194 195 196 197 198 199
# idfa为空,idfa_md5不为空
def test_idfa1():
    data[0]['device_info']['idfa'] = ''
    response = send_request()
    assert response["status"] == "0"


# idfa超长
def test_idfa2():
    data[0]['device_info']['idfa'] = chaochang
    response = send_request()
    assert response["status"] == "124"

liuxiaoxing committed
200

liuxiaoxing committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
# idfa为空,idfa_md5也为空
def test_idfa3():
    data[0]['device_info']['idfa'] = ''
    data[0]['device_info']['idfa_md5'] = ''
    response = send_request()
    assert response["status"] == "124"


# idfa不为空,idfa_md5为空
def test_idfa_md51():
    data[0]['device_info']['idfa_md5'] = ''
    response = send_request()
    assert response["status"] == "0"


# idfa_md5超长
def test_idfa_md52():
    data[0]['device_info']['idfa_md5'] = chaochang
    response = send_request()
    assert response["status"] == "124"


# device_id与device_id_type不一致
def test_device_id():
    data[0]['device_info']['device_id_type'] = "idfa"
    data[0]['device_info']['device_id'] = "c3381276ae145b3663c8e0f6dd9f628a"
    data[0]['device_info']['idfa_md5'] = "c3381276ae145b3663c8e0f6dd9f628a"
    response = send_request()
    assert response["status"] == "0"


# idfv为空,idfv_md5不为空
def test_idfv1():
    data[0]['device_info']['idfv'] = ''
    response = send_request()
    assert response["status"] == "0"


# idfv超长
def test_idfv2():
    data[0]['device_info']['idfv'] = chaochang
    response = send_request()
    assert response["status"] == "125"


# idfv为空,idfv_md5也为空
def test_idfv3():
    data[0]['device_info']['idfv'] = ''
    data[0]['device_info']['idfv_md5'] = ''
    response = send_request()
    assert response["status"] == "125"


# idfv不为空,idfv_md5为空
def test_idfv_md51():
    data[0]['device_info']['idfv_md5'] = ''
    response = send_request()
    assert response["status"] == "0"


# idfv_md5超长
def test_idfv_md52():
    data[0]['device_info']['idfv_md5'] = chaochang
    response = send_request()
    assert response["status"] == "125"

liuxiaoxing committed
267

liuxiaoxing committed
268 269
if __name__ == '__main__':
    pytest.main()