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

*** Variables ***
${path}           /api/chat/write
${uploadpath}     /api/file-ref/upload
${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请求结果_data    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${text_streamId}    ${content["data"]}
    Sleep    10

正例-正常发送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    file=${file}
    ${resp}    Post On Session    URI    ${uploadpath}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${jpg_streamId}    ${content["data"]["id"]}
    Sleep    10

正例-正常发送jpg+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${content}    POST请求结果_data    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${jpg_streamId}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${j&t_streamId}    ${content["data"]}
    Sleep    10

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

正例-正常发送gif+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${gif_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${g&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送jpeg+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${jpeg_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${je&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送png+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${png_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${p&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送webp+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${webp_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${we&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送csv+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${csv_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${c&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送doc+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${doc_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${d&t_streamId}    ${content["data"]}
    Comment    Sleep    10

正例-正常发送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    file=${file}
    ${resp}    Post On Session    URI    ${uploadpath}    files=${files}    data=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${docx_streamId}    ${content["data"]["id"]}
    Sleep    10

正例-正常发送docx+文字消息
    [Tags]    F
    create session    URI    ${URL}
    ${content}    POST请求结果_data    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${docx_streamId}"}    200    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    200
    Set Global Variable    ${dx&t_streamId}    ${content["data"]}
    Sleep    10

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

正例-正常发送md+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${md_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${md&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送txt+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${txt_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${txt&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送xls+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xls_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${xls&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

正例-正常发送xlsx+文字消息
    [Tags]    F
    Comment    create session    URI    ${URL}
    Comment    ${content}    POST请求结果_PARAMS    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xlsx_streamId}"}    200    ${token}
    Comment    log    ${content}
    Comment    Should Be Equal As Strings    ${content["code"]}    200
    Comment    Should Be Equal As Strings    ${content["message"]}    成功
    Comment    Set Global Variable    ${xlsx&t_streamId}    ${content["data"]}
    Comment    Sleep    10

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

反例-传入空白token
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_data    ${path}    {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}"}    401    ${EMPTY}
    log    ${content}
    Should Be Equal As Strings    ${content["code"]}    401

反例-不传入sessionId参数
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_data    ${path}    {"text":"你好","workerId":"${clientId}"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["msg"]}    Field required

反例-不传入workerId参数
    [Tags]    E
    create session    URI    ${URL}
    ${content}    POST请求结果_data    ${path}    {"sessionId":"${sessionId}","text":"你好"}    422    ${token}
    log    ${content}
    Should Be Equal As Strings    ${content["detail"][0]["msg"]}    Field required

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