Bespoken Code Coverage for self-hosted Alexa Skill written in Python (Flask)

179 Views Asked by At

I am working on an Alexa Skill written in Python using the ask-sdk for Python. This skill is running self-hosted on a Flask server listening to port 5000. Now i would like to integrate Unit-Tests using the Bespoken Framework.

My testing.json file looks like this:

{

    "locales": "de-DE",
    "interactionModel": "models/de-DE.json",
    "trace": true,
    "jest": {
        "silent": true
    },
    "skillURL": "http://localhost:5000"
}

i am locally running an http.server on port 9998 to get the report.html. The tests passed successfully, but the code coverage is not working correctly. It seems like the files used in this skills are not recognized at all. Instead they are looking up the files slides.js, debugger.js, jquery.js

-----------------------------------------|----------|----------|
File                                     |  % Stmts | % Branch | 
-----------------------------------------|----------|----------|
All files                                |        0 |        0 | 
 docutils/writers/s5_html/themes/default |        0 |        0 | 
  slides.js                              |        0 |        0 |     ...
 werkzeug/debug/shared                   |        0 |        0 | 
  debugger.js                            |        0 |        0 | 
  jquery.js                              |        0 |        0 |
-----------------------------------------|----------|----------|

Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
Snapshots:   0 total
Time:        9.475s

I followed this guide https://read.bespoken.io/cli/tutorials/tutorial-flask-ask-python/#getting-started.

Therefore I looked up the FAQ and got this information from https://read.bespoken.io/unit-testing/faq/#what-are-continuous-integration-ci-and-automated-unit-testing:


Can I unit-test skills written in programming languages other than Javascript? Yes, you can. It does require having a server running locally on your laptop that our library can call, but otherwise it will "just work".

Before the test is run, start the server to receive payloads. It will be listening on something like: http://localhost:9000.

Set that URL in the skillURL configuration element in the testing.json file. This should be set instead of the handler element - the handler only works with Javascript lambdas/functions.

After tests are run, shut the server down - we recommend doing this as part of a regular process. It can be added to one of our filters, for example - read about filters here XXX. Finally, if you have request signature checking or timestamp filtering being performed on the requests, you will need to disable this.


This is my app.py:


SB = SkillBuilder()
app = Flask(__name__)

app.config.setdefault(VERIFY_SIGNATURE_APP_CONFIG, False)
id = "XXXX"
skill_obj = SB.create()


webservice_handler = WebserviceSkillHandler(skill=skill_obj)
webservice_handler.verify_signture = False


skill_adapter = SkillAdapter(skill=skill_obj, skill_id=id, app=app)

skill_adapter.VERIFY_SIGNATURE_APP_CONFIG = False

skill_adapter.register(app=app, route="/")



if __name__ == '__main__':

    if 'ASK_VERIFY_REQUESTS' in os.environ:
        verify = str(os.environ.get('ASK_VERIFY_REQUESTS', '')).lower()
        if verify == 'false':
            app.config['ASK_VERIFY_REQUESTS'] = False
    app.run(host='0.0.0.0', port=5000, debug=True)

I am thankful for any idea!

1

There are 1 best solutions below

0
On

the locally running server on port 9998 is not needed. you must allow post methods on port 5000