Created behave test for the google stt endpoint

pull/46/head
Matheus Lima 2019-02-18 20:36:25 -03:00
parent d6bab8fb8f
commit c02f308392
6 changed files with 56 additions and 9 deletions

View File

@ -1,19 +1,23 @@
import os
from flask import Flask
from selene.api import SeleneResponse, selene_api
from selene.api.base_config import get_base_config
from .public_api.endpoints.device import DeviceEndpoint
from .public_api.endpoints.device_setting import DeviceSettingEndpoint
from .public_api.endpoints.device_skill import DeviceSkillEndpoint
from .public_api.endpoints.device_skills import DeviceSkillsEndpoint
from .public_api.endpoints.device_subscription import DeviceSubscriptionEndpoint
from .public_api.endpoints.open_weather_map import OpenWeatherMapEndpoint
from .public_api.endpoints.wolfram_alpha import WolframAlphaEndpoint
from .public_api.endpoints.google_stt import GoogleSTTEndpoint
from public_api.endpoints.device import DeviceEndpoint
from public_api.endpoints.device_setting import DeviceSettingEndpoint
from public_api.endpoints.device_skill import DeviceSkillEndpoint
from public_api.endpoints.device_skills import DeviceSkillsEndpoint
from public_api.endpoints.device_subscription import DeviceSubscriptionEndpoint
from public_api.endpoints.open_weather_map import OpenWeatherMapEndpoint
from public_api.endpoints.wolfram_alpha import WolframAlphaEndpoint
from public_api.endpoints.google_stt import GoogleSTTEndpoint
public = Flask(__name__)
public.config.from_object(get_base_config())
public.config['GOOGLE_STT_KEY'] = os.environ['GOOGLE_STT_KEY']
public.response_class = SeleneResponse
public.register_blueprint(selene_api)

View File

@ -10,7 +10,7 @@ class GoogleSTTEndpoint(SeleneEndpoint):
""" Endpoint to send a flac audio file with voice and get back a utterance"""
def __init__(self):
super(GoogleSTTEndpoint, self).__init__()
self.google_stt_key = os.environ['GOOGLE_STT_KEY']
self.google_stt_key = self.config['GOOGLE_STT_KEY']
self.recognizer = Recognizer()
def post(self):

View File

@ -0,0 +1,15 @@
from behave import fixture, use_fixture
from api import public
@fixture
def public_api_client(context):
public.testing = True
context.client_config = public.config
context.client = public.test_client()
yield context.client
def before_feature(context, _):
use_fixture(public_api_client, context)

View File

@ -0,0 +1,6 @@
Feature: Get an utterance
Test the google STT integration
Scenario: A valid flac audio with a voice record is passed
When A flac audio with the utterance "tell me a joke" is passed
Then return the utterance "tell me a joke"

View File

@ -0,0 +1,22 @@
import json
from http import HTTPStatus
from io import BytesIO
from os import path
from behave import When, Then
from hamcrest import assert_that, equal_to
@When('A flac audio with the utterance "tell me a joke" is passed')
def call_google_stt_endpoint(context):
with open(path.join(path.dirname(__file__), 'resources/test_stt.flac'), 'rb') as flac:
audio = BytesIO(flac.read())
context.response = context.client.post('/stt?lang=en-US&limit=1', data=audio)
@Then('return the utterance "tell me a joke"')
def validate_response(context):
assert_that(context.response.status_code, equal_to(HTTPStatus.OK))
response_data = json.loads(context.response.data)
expected_response = ['tell me a joke']
assert_that(response_data, equal_to(expected_response))