question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SimpleREST ContainerMode not working with SIMPLEREST_HEADERS_TEMPLATE

See original GitHub issue

Hello,

After many hours testing, I think it may be a bug: botium-cli --version: 0.0.38 node --version: v10.15.0

I have a simple bot (bot.py) that only answers the same string “Adeus, obrigado pelo contato =)” for POST requests passing the parameters user_id and message:

from flask import Flask, request, jsonify

def create_app(test_config=None):
    app = Flask(__name__)
    app.config['JSON_AS_ASCII'] = False # retrieve UTF-8 messages
    app.config['DEBUG'] = True

     @app.route('/reply', methods=['POST'])
     def reply():
         params = request.json
         if not params:
             return jsonify({
                 "status": "error",
                 "error": "Request must be of the application/json type!",
             })
 
         user_id = params.get("user_id")
         message  = params.get("message")
         
         # Make sure the required params are present.
         if not user_id or not message:
             return jsonify({
                 "status": "error",
                 "error": "user_id and message are required keys",
         })
         
         reply = "Adeus, obrigado pelo contato =)"
         
         # Send the response.
         return jsonify({
             "status": "ok",
             "reply": reply
         })
 
     return app

I can test it with a simple curl:

curl -X POST   http://localhost:5002/reply   -H 'content-type: application/json'   -d '{
    "message": "tchau",
    "user_id": "dummy123"
}'

Response:

{
  "reply": "Adeus, obrigado pelo contato =)", 
  "status": "ok"
}

I’ve made a simple convo file (despedida.convo.txt):

#me
tchau

#bot
Adeus, obrigado pelo contato =)

I’ve also made a simple config to match the curl (botium.json):

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "First Test",
      "CONTAINERMODE": "simplerest",
      "SIMPLEREST_URL": "http://localhost:5002/reply",
      "SIMPLEREST_METHOD": "POST",
      "SIMPLEREST_HEADERS_TEMPLATE": { "content-type": "application/json" },
      "SIMPLEREST_BODY_TEMPLATE": { "message": "{{msg.messageText}}", "user_id": "{{context.conversation_id}}" },
      "SIMPLEREST_RESPONSE_JSONPATH": "$.reply.*"
    },
    "Sources": {},
    "Envs": {}
  }
}

But when I do the botium-cli run --verbose, I see my application returns an error that suggests SIMPLEREST_HEADERS_TEMPLATE is being ignored:

botium-SimpleRestContainer got response body: "{\n \"error\": \"Request must be of the application/json type!\", \n \"status\": \"error\"\n}\n" +32ms

And the normal outputs this:

  Botium Test-Suite
    1) convos/despedida.convo.txt


  0 passing (10s)
  1 failing

  1) Botium Test-Suite
       convos/despedida.convo.txt:
     AssertionError: convos/despedida.convo.txt/Line 5: bot says nothing
      at ScriptingProvider.compiler.scriptingEvents.fail (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12)
      at scriptingEvents.onBotStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:179:40)

It seems to timeout in 10 seconds everytime, even though the application responds instantly to the curl command. I also tried to change the SIMPLEREST_HEADERS_TEMPLATE as in issue #162: "SIMPLEREST_HEADERS_TEMPLATE": "{ \"Content-Type\": \"application/json\"}"

But then I get the instant error:

  Botium Test-Suite
    1) convos/despedida.convo.txt


  0 passing (118ms)
  1 failing

  1) Botium Test-Suite
       convos/despedida.convo.txt:
     Error: convos/despedida.convo.txt/Line 4: error sending to bot { AssertionError: Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
    at Object.render (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
    at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
    at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
    at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
    at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
    at ScriptingProvider.compiler.scriptingEvents.fail (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12)
    at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:38)
  message:
   Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
       at Object.render (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
       at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
       at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
       at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
       at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
       at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:43),
  showDiff: false,
  actual: null,
  expected: null,
  operator: undefined }
      at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:163:33)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
staticdevcommented, Dec 28, 2018

From the Wiki I though conversation_id is automatic (https://github.com/codeforequity-at/botium-core/wiki/operation-mode-simplerest).

I used “SIMPLEREST_INIT_CONTEXT”: “{ "conversation_id": "botium" }” and it worked!

I think you can close this issue then. Thanks a lot! Botium is a very nice product and I will make good marketing with my fellow developer friends.

0reactions
codeforequity-atcommented, Dec 28, 2018

Thanks In two weeks we will publish Botium Stack (free) and Botium Platform (commercial), which includes Botium Box as user interface and test management based on Botium Core. You can drop us a line at info@botium.at if you are interested in notification.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found