*** Settings ***
Resource          flow_zmx.resource
Resource          res_zmx.resource

*** Variables ***
${path}           /api/chat/write
${jpg_file}       testpicture.jpg
${gif_file}       testpicture.gif
${jpeg_file}      testpicture.jpeg
${png_file}       testpicture.png
${webp_file}      testpicture.webp
${csv_file}       testfile.csv
${doc_file}       testfile.doc
${docx_file}      testfile.docx
${md_file}        testfile.md
${txt_file}       testfile.txt
${xls_file}       testfile.xls
${xlsx_file}      testfile.xlsx

*** Test Cases ***
正例-正常发送文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${text_streamId}    ${content["data"]}

正例-正常发送jpg消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${jpg_file}', open(r'${CURDIR}${/}testfiles${/}${jpg_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${jpg_streamId}    ${content["data"]}

正例-正常发送jpg+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${jpg_file}', open(r'${CURDIR}${/}testfiles${/}${jpg_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这张图是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${j&t_streamId}    ${content["data"]}

正例-正常发送gif消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${gif_file}', open(r'${CURDIR}${/}testfiles${/}${gif_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${gif_streamId}    ${content["data"]}

正例-正常发送gif+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${gif_file}', open(r'${CURDIR}${/}testfiles${/}${gif_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这张图是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${g&t_streamId}    ${content["data"]}

正例-正常发送jpeg消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${jpeg_file}', open(r'${CURDIR}${/}testfiles${/}${jpeg_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${jpeg_streamId}    ${content["data"]}

正例-正常发送jpeg+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${jpeg_file}', open(r'${CURDIR}${/}testfiles${/}${jpeg_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这张图是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${je&t_streamId}    ${content["data"]}

正例-正常发送png消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${png_file}', open(r'${CURDIR}${/}testfiles${/}${png_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${png_streamId}    ${content["data"]}

正例-正常发送png+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${png_file}', open(r'${CURDIR}${/}testfiles${/}${png_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这张图是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${p&t_streamId}    ${content["data"]}

正例-正常发送webp消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${webp_file}', open(r'${CURDIR}${/}testfiles${/}${webp_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${webp_streamId}    ${content["data"]}

正例-正常发送webp+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${webp_file}', open(r'${CURDIR}${/}testfiles${/}${webp_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这张图是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${we&t_streamId}    ${content["data"]}

正例-正常发送csv消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${csv_file}', open(r'${CURDIR}${/}testfiles${/}${csv_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${csv_streamId}    ${content["data"]}

正例-正常发送csv+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${csv_file}', open(r'${CURDIR}${/}testfiles${/}${csv_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${c&t_streamId}    ${content["data"]}

正例-正常发送doc消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${doc_file}', open(r'${CURDIR}${/}testfiles${/}${doc_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${doc_streamId}    ${content["data"]}

正例-正常发送doc+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${doc_file}', open(r'${CURDIR}${/}testfiles${/}${doc_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${d&t_streamId}    ${content["data"]}

正例-正常发送docx消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${docx_file}', open(r'${CURDIR}${/}testfiles${/}${docx_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${docx_streamId}    ${content["data"]}

正例-正常发送docx+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${docx_file}', open(r'${CURDIR}${/}testfiles${/}${docx_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${dx&t_streamId}    ${content["data"]}

正例-正常发送md消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${md_file}', open(r'${CURDIR}${/}testfiles${/}${md_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${md_streamId}    ${content["data"]}

正例-正常发送md+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${md_file}', open(r'${CURDIR}${/}testfiles${/}${md_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${md&t_streamId}    ${content["data"]}

正例-正常发送txt消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${txt_file}', open(r'${CURDIR}${/}testfiles${/}${txt_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${txt_streamId}    ${content["data"]}

正例-正常发送txt+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${txt_file}', open(r'${CURDIR}${/}testfiles${/}${txt_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${txt&t_streamId}    ${content["data"]}

正例-正常发送xls消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${xls_file}', open(r'${CURDIR}${/}testfiles${/}${xls_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${xls_streamId}    ${content["data"]}

正例-正常发送xls+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${xls_file}', open(r'${CURDIR}${/}testfiles${/}${xls_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${xls&t_streamId}    ${content["data"]}

正例-正常发送xlsx消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${xlsx_file}', open(r'${CURDIR}${/}testfiles${/}${xlsx_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${xlsx_streamId}    ${content["data"]}

正例-正常发送xlsx+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${file}    Evaluate    (r'${xlsx_file}', open(r'${CURDIR}${/}testfiles${/}${xlsx_file}', 'rb'))
    ${data}    Create Dictionary    sessionId=${sessionId}    text="这个文件是什么格式"
    ${header}    Create Dictionary    Authorization=${token}
    ${files}    Create Dictionary    files=${file}
    ${resp}    Post On Session    URI    ${path}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${xlsx&t_streamId}    ${content["data"]}

反例-传入错误token
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好"}    401    {}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401
    Should Be Equal As Strings    ${content["message"]}    无效的access token

反例-传入空白token
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好"}    401    ${EMPTY}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401
    Should Be Equal As Strings    ${content["message"]}    没有找到认证信息

反例-不传入sessionId参数
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_PARAMS    ${path}    {}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    500
    Should Be Equal As Strings    ${content["message"]}    Server busy, please try later

正例-正常发送文字消息，进入探索
    [Tags]    F
    create session    URI    ${URL}
    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"使用探索工具，打开百度"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Should Be Equal As Strings    ${content["message"]}    成功
    Set Global Variable    ${ex_streamId}    ${content["data"]}
