Code Monkey home page Code Monkey logo

Comments (14)

timothyaaron avatar timothyaaron commented on May 27, 2024 4

I'm currently just using pytest against...

tests/test_file.py

from skill import handler
from tests import new_request, context


def test_intent():
    request = new_request('MyIntent', {'SlotName': 'slot value'})
    response = handler(request, context)

    expected_response = 'Your intent was reached. My response is, "slot value".'
    assert expected_response in response['response']['outputSpeech']['ssml']
    assert expected_response in response['response']['reprompt']['outputSpeech']['ssml']

tests/__init__.py

import uuid
from datetime import datetime

context = {}


def new_request(name, slots={}):
    req_env = {
        "session": {
            "sessionId": f"amzn1.echo-api.session.{uuid.uuid1()}",
            "application": {
                "applicationId": f"amzn1.echo-sdk-ams.app.{uuid.uuid1()}"
            },
            "user": {
                "userId": f"amzn1.ask.account.{uuid.uuid1()}"
            },
            "new": False,
        },
        "request": {
            "requestId": f"amzn1.echo-api.request.{uuid.uuid1()}",
            "timestamp": f"{datetime.now().replace(second=0, microsecond=0).isoformat()}",
            "locale": "en-US",
            "type": "IntentRequest" if name.endswith('Intent') else name,
        }
    }

    if name.endswith('Intent'):
        req_env['request']['intent'] = {
            'name': name,
            'slots': {k: {'name': k, 'value': v} for k, v in slots.items()}
        }

    return req_env

from alexa-skills-kit-sdk-for-python.

ag1le avatar ag1le commented on May 27, 2024 1

Have you tried using ngrok? See example in https://developer.amazon.com/blogs/post/Tx14R0IYYGH3SKT/Flask-Ask-A-New-Python-Framework-for-Rapid-Alexa-Skills-Kit-Development

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

Hey @The-Gupta , we currently do not provide any testing framework with the SDK that helps in local testing. This falls under a feature request. We track them through the 'User Voice' portal.

Please pitch in ideas to User Voice. If it already exists, make sure to give your vote!

We think that local testing is a value-add to the skill development and will definitely look into it.

from alexa-skills-kit-sdk-for-python.

The-Gupta avatar The-Gupta commented on May 27, 2024

In the meantime, could anyone suggest any other possibility

  • steps I could follow,
  • maybe, use some other library...?

And, I repeat, I need to test an Alexa Skill locally using Python. Also, I need text I/O like Alexa Simulator on Amazon Developer Website under the Test tab, not voice using Echosim.

from alexa-skills-kit-sdk-for-python.

The-Gupta avatar The-Gupta commented on May 27, 2024

@nikhilym, could you suggest steps using Amazon API Gateway, preferably in Python?

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

@The-Gupta can you explain in brief what are you trying to achieve? Also, if this is something different from the intended question raised in this issue, please log another one.

If this issue has been addressed or a feature request has been raised on User Voice, please link the same here.

from alexa-skills-kit-sdk-for-python.

The-Gupta avatar The-Gupta commented on May 27, 2024

I'm trying to test an Alexa Skill locally, on my laptop, like Alexa Simulator on Amazon Developer Website under the Test tab.

from alexa-skills-kit-sdk-for-python.

sarang-rk avatar sarang-rk commented on May 27, 2024

Hi, I am also trying to run the code "Hello_World" and pressing the test tab. But it's not working. Some times it is timeout error and some times it is hello_world module not found.

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

Hey @sarang-rk. Looks like you are having a different issue than the discussion here. Please update the issue #26 with the issue template so that we can investigate the problem

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

Hey @The-Gupta , sorry for the late response. For lambda handler testing, pytests method as mentioned by @timothyaaron is the way. For testing the skill similar to alexa simulator, you can try the ask simulate commands as mentioned here.

The ask cli is currently Node specific. However, you can try these steps to get the alexa skill cloned locally for working with CLI. There is a feature request to provide a CLI similar to ask-cli for Python. Please voice your feedback if this is something you are interested in.

As for the ngrok approach mentioned by @ag1le , that is currently not supported in the SDK, since there is no web application wrapper on the lambda function. (Stay tuned for new features 😄 ) But, in case you want to follow that approach, create a wsgi app that can route the requests through the lambda handler, create a local http server using ngrok, run the webapp and tag it to the Skill endpoint for testing.

Let us know if you have questions.

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 27, 2024

Hey @The-Gupta , I checked on some of the Alexa repos that you wanted to test your skill code using API Gateway and Postman. Here is the link that explains how to do the same. I am closing this issue for now. Please reopen if you face any issues with the methods described.

As for the feature request, we suggest you to create one or upvote the requests on User Voice.

from alexa-skills-kit-sdk-for-python.

qo4on avatar qo4on commented on May 27, 2024

Two years later I have the same question.

Is there a way to test skills from a Python terminal without a need to go to Test Tab on the Amazon Developer website?

from alexa-skills-kit-sdk-for-python.

Shreyas-vgr avatar Shreyas-vgr commented on May 27, 2024

Hi @qo4on, we currently do not provide any testing framework with the SDK that helps in local testing.

But you can install ASK CLI and leverage its dialog command to test the skills locally.

from alexa-skills-kit-sdk-for-python.

qo4on avatar qo4on commented on May 27, 2024

Thanks for your answer @Shreyas-vgr.

As I know CLI shows text responses only. Is there any workaround for getting audio responses without Test Tab on Developer website?

from alexa-skills-kit-sdk-for-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.