From 01af79131c2de8905f8b0f51c0fb6be34d2f582f Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Thu, 14 Nov 2019 10:46:41 -0800 Subject: [PATCH 01/32] Cleanup --- .../functionaltestbot/Dockerfile | 48 ---- .../functionaltestbot/Dockfile | 27 -- .../functionaltestbot/README.md | 9 + .../functionaltestbot/application.py | 89 +++++++ .../{flask_bot_app => bots}/__init__.py | 4 +- .../functionaltestbot/bots/echo_bot.py | 17 ++ .../functionaltestbot/client_driver/README.md | 5 - .../{functionaltestbot => }/config.py | 6 +- .../functionaltestbot/flask_bot_app/app.py | 21 -- .../flask_bot_app/bot_app.py | 108 -------- .../flask_bot_app/default_config.py | 12 - .../functionaltestbot/flask_bot_app/my_bot.py | 19 -- .../functionaltestbot/README.md | 35 --- .../functionaltestbot/about.py | 14 -- .../functionaltestbot/app.py | 86 ------- .../functionaltestbot/bot.py | 19 -- .../functionaltestbot/requirements.txt | 3 - .../functionaltestbot/init.sh | 8 - .../functionaltestbot/requirements.txt | 12 +- .../functionaltestbot/runserver.py | 16 -- .../functionaltestbot/setup.py | 40 --- .../functionaltestbot/sshd_config | 21 -- .../template/linux/template.json | 238 ------------------ .../functionaltestbot/test.sh | 1 - .../tests/direct_line_client.py | 2 +- .../functionaltestbot/tests/test_py_bot.py | 44 ++++ .../functional-tests/tests/test_py_bot.py | 26 -- 27 files changed, 173 insertions(+), 757 deletions(-) delete mode 100644 libraries/functional-tests/functionaltestbot/Dockerfile delete mode 100644 libraries/functional-tests/functionaltestbot/Dockfile create mode 100644 libraries/functional-tests/functionaltestbot/README.md create mode 100644 libraries/functional-tests/functionaltestbot/application.py rename libraries/functional-tests/functionaltestbot/{flask_bot_app => bots}/__init__.py (65%) create mode 100644 libraries/functional-tests/functionaltestbot/bots/echo_bot.py delete mode 100644 libraries/functional-tests/functionaltestbot/client_driver/README.md rename libraries/functional-tests/functionaltestbot/{functionaltestbot => }/config.py (69%) delete mode 100644 libraries/functional-tests/functionaltestbot/flask_bot_app/app.py delete mode 100644 libraries/functional-tests/functionaltestbot/flask_bot_app/bot_app.py delete mode 100644 libraries/functional-tests/functionaltestbot/flask_bot_app/default_config.py delete mode 100644 libraries/functional-tests/functionaltestbot/flask_bot_app/my_bot.py delete mode 100644 libraries/functional-tests/functionaltestbot/functionaltestbot/README.md delete mode 100644 libraries/functional-tests/functionaltestbot/functionaltestbot/about.py delete mode 100644 libraries/functional-tests/functionaltestbot/functionaltestbot/app.py delete mode 100644 libraries/functional-tests/functionaltestbot/functionaltestbot/bot.py delete mode 100644 libraries/functional-tests/functionaltestbot/functionaltestbot/requirements.txt delete mode 100644 libraries/functional-tests/functionaltestbot/init.sh delete mode 100644 libraries/functional-tests/functionaltestbot/runserver.py delete mode 100644 libraries/functional-tests/functionaltestbot/setup.py delete mode 100644 libraries/functional-tests/functionaltestbot/sshd_config delete mode 100644 libraries/functional-tests/functionaltestbot/template/linux/template.json delete mode 100644 libraries/functional-tests/functionaltestbot/test.sh rename libraries/functional-tests/{ => functionaltestbot}/tests/direct_line_client.py (98%) create mode 100644 libraries/functional-tests/functionaltestbot/tests/test_py_bot.py delete mode 100644 libraries/functional-tests/tests/test_py_bot.py diff --git a/libraries/functional-tests/functionaltestbot/Dockerfile b/libraries/functional-tests/functionaltestbot/Dockerfile deleted file mode 100644 index 3364fc380..000000000 --- a/libraries/functional-tests/functionaltestbot/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -FROM tiangolo/uwsgi-nginx-flask:python3.6 - - -RUN mkdir /functionaltestbot - -EXPOSE 443 -# EXPOSE 2222 - -COPY ./functionaltestbot /functionaltestbot -COPY setup.py / -COPY test.sh / -# RUN ls -ltr -# RUN cat prestart.sh -# RUN cat main.py - -ENV FLASK_APP=/functionaltestbot/app.py -ENV LANG=C.UTF-8 -ENV LC_ALL=C.UTF-8 -ENV PATH ${PATH}:/home/site/wwwroot - -WORKDIR / - -# Initialize the bot -RUN pip3 install -e . - -# ssh -ENV SSH_PASSWD "root:Docker!" -RUN apt-get update \ - && apt-get install -y --no-install-recommends dialog \ - && apt-get update \ - && apt-get install -y --no-install-recommends openssh-server \ - && echo "$SSH_PASSWD" | chpasswd \ - && apt install -y --no-install-recommends vim -COPY sshd_config /etc/ssh/ -COPY init.sh /usr/local/bin/ -RUN chmod u+x /usr/local/bin/init.sh - -# For Debugging, uncomment the following: -# ENTRYPOINT ["python3.6", "-c", "import time ; time.sleep(500000)"] -ENTRYPOINT ["init.sh"] - -# For Devops, they don't like entry points. This is now in the devops -# pipeline. -# ENTRYPOINT [ "flask" ] -# CMD [ "run", "--port", "3978", "--host", "0.0.0.0" ] diff --git a/libraries/functional-tests/functionaltestbot/Dockfile b/libraries/functional-tests/functionaltestbot/Dockfile deleted file mode 100644 index 8383f9a2b..000000000 --- a/libraries/functional-tests/functionaltestbot/Dockfile +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -FROM python:3.7-slim as pkg_holder - -ARG EXTRA_INDEX_URL -RUN pip config set global.extra-index-url "${EXTRA_INDEX_URL}" - -COPY requirements.txt . -RUN pip download -r requirements.txt -d packages - -FROM python:3.7-slim - -ENV VIRTUAL_ENV=/opt/venv -RUN python3.7 -m venv $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" - -COPY . /app -WORKDIR /app - -COPY --from=pkg_holder packages packages - -RUN pip install -r requirements.txt --no-index --find-links=packages && rm -rf packages - -ENTRYPOINT ["python"] -EXPOSE 3978 -CMD ["runserver.py"] diff --git a/libraries/functional-tests/functionaltestbot/README.md b/libraries/functional-tests/functionaltestbot/README.md new file mode 100644 index 000000000..f6d8e670f --- /dev/null +++ b/libraries/functional-tests/functionaltestbot/README.md @@ -0,0 +1,9 @@ +# Functional Test Bot +This bot is the "Echo" bot which perform E2E functional test. +- Cleans up +- Deploys the python echo bot to Azure +- Creates an Azure Bot and associates with the deployed python bot. +- Creates a DirectLine channel and associates with the newly created bot. +- Runs a client test, using the DirectLine channel and and verifies response. + +This is modeled in a Devops. \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/application.py b/libraries/functional-tests/functionaltestbot/application.py new file mode 100644 index 000000000..45680e243 --- /dev/null +++ b/libraries/functional-tests/functionaltestbot/application.py @@ -0,0 +1,89 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import asyncio +import sys +import os +from datetime import datetime + +from flask import Flask, request, Response +from botbuilder.core import BotFrameworkAdapterSettings, TurnContext, BotFrameworkAdapter, \ +ActivityHandler, MessageFactory, TurnContext +from botbuilder.schema import Activity, ActivityTypes +from botbuilder.schema import ChannelAccount + +from bots import EchoBot + +# Create the loop and Flask app +LOOP = asyncio.get_event_loop() +app = Flask(__name__, instance_relative_config=True) +app.config.from_object("config.DefaultConfig") + +# Create adapter. +# See https://aka.ms/about-bot-adapter to learn more about how bots work. +SETTINGS = BotFrameworkAdapterSettings(os.environ.get("MicrosoftAppId", ""), os.environ.get("MicrosoftAppPassword", "")) +ADAPTER = BotFrameworkAdapter(SETTINGS) + + +# Catch-all for errors. +async def on_error(context: TurnContext, error: Exception): + # This check writes out errors to console log .vs. app insights. + # NOTE: In production environment, you should consider logging this to Azure + # application insights. + print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr) + + # Send a message to the user + await context.send_activity("The bot encountered an error or bug.") + await context.send_activity("To continue to run this bot, please fix the bot source code.") + # Send a trace activity if we're talking to the Bot Framework Emulator + if context.activity.channel_id == 'emulator': + # Create a trace activity that contains the error object + trace_activity = Activity( + label="TurnError", + name="on_turn_error Trace", + timestamp=datetime.utcnow(), + type=ActivityTypes.trace, + value=f"{error}", + value_type="https://www.botframework.com/schemas/error" + ) + # Send a trace activity, which will be displayed in Bot Framework Emulator + await context.send_activity(trace_activity) + +ADAPTER.on_turn_error = on_error + +# Create the Bot +BOT = EchoBot() + +# Listen for incoming requests on /api/messages +@app.route("/api/messages", methods=["POST"]) +def messages(): + # Main bot message handler. + if "application/json" in request.headers["Content-Type"]: + body = request.json + else: + return Response(status=415) + + activity = Activity().deserialize(body) + auth_header = ( + request.headers["Authorization"] if "Authorization" in request.headers else "" + ) + + try: + task = LOOP.create_task( + ADAPTER.process_activity(activity, auth_header, BOT.on_turn) + ) + LOOP.run_until_complete(task) + return Response(status=201) + except Exception as exception: + raise exception + +@app.route("/", methods=["GET"]) +def ping(): + return "Hello World!" + + +if __name__ == "__main__": + try: + app.run(debug=False, port=3978) # nosec debug + except Exception as exception: + raise exception \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/flask_bot_app/__init__.py b/libraries/functional-tests/functionaltestbot/bots/__init__.py similarity index 65% rename from libraries/functional-tests/functionaltestbot/flask_bot_app/__init__.py rename to libraries/functional-tests/functionaltestbot/bots/__init__.py index d5d099805..c215edb22 100644 --- a/libraries/functional-tests/functionaltestbot/flask_bot_app/__init__.py +++ b/libraries/functional-tests/functionaltestbot/bots/__init__.py @@ -1,6 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -from .app import APP +from .echo_bot import EchoBot -__all__ = ["APP"] +__all__ = ["EchoBot"] \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/bots/echo_bot.py b/libraries/functional-tests/functionaltestbot/bots/echo_bot.py new file mode 100644 index 000000000..985c0694c --- /dev/null +++ b/libraries/functional-tests/functionaltestbot/bots/echo_bot.py @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +from botbuilder.core import ActivityHandler, MessageFactory, TurnContext +from botbuilder.schema import ChannelAccount + + +class EchoBot(ActivityHandler): + async def on_members_added_activity( + self, members_added: [ChannelAccount], turn_context: TurnContext + ): + for member in members_added: + if member.id != turn_context.activity.recipient.id: + await turn_context.send_activity("Hello and welcome!") + + async def on_message_activity(self, turn_context: TurnContext): + return await turn_context.send_activity(MessageFactory.text(f"Echo: {turn_context.activity.text}")) diff --git a/libraries/functional-tests/functionaltestbot/client_driver/README.md b/libraries/functional-tests/functionaltestbot/client_driver/README.md deleted file mode 100644 index 317a457c9..000000000 --- a/libraries/functional-tests/functionaltestbot/client_driver/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Client Driver for Function E2E test - -This contains the client code that drives the bot functional test. - -It performs simple operations against the bot and validates results. \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/config.py b/libraries/functional-tests/functionaltestbot/config.py similarity index 69% rename from libraries/functional-tests/functionaltestbot/functionaltestbot/config.py rename to libraries/functional-tests/functionaltestbot/config.py index a3bd72174..b2bdd7fb2 100644 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/config.py +++ b/libraries/functional-tests/functionaltestbot/config.py @@ -4,10 +4,12 @@ import os +""" Bot Configuration """ + class DefaultConfig: """ Bot Configuration """ - PORT = 443 + PORT = 3978 APP_ID = os.environ.get("MicrosoftAppId", "") - APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") + APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/flask_bot_app/app.py b/libraries/functional-tests/functionaltestbot/flask_bot_app/app.py deleted file mode 100644 index 10f99452e..000000000 --- a/libraries/functional-tests/functionaltestbot/flask_bot_app/app.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -"""Bot app with Flask routing.""" - -from flask import Response - -from .bot_app import BotApp - - -APP = BotApp() - - -@APP.flask.route("/api/messages", methods=["POST"]) -def messages() -> Response: - return APP.messages() - - -@APP.flask.route("/api/test", methods=["GET"]) -def test() -> Response: - return APP.test() diff --git a/libraries/functional-tests/functionaltestbot/flask_bot_app/bot_app.py b/libraries/functional-tests/functionaltestbot/flask_bot_app/bot_app.py deleted file mode 100644 index 5fb109576..000000000 --- a/libraries/functional-tests/functionaltestbot/flask_bot_app/bot_app.py +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -import asyncio -import sys -from types import MethodType -from flask import Flask, Response, request - -from botbuilder.core import ( - BotFrameworkAdapter, - BotFrameworkAdapterSettings, - MessageFactory, - TurnContext, -) -from botbuilder.schema import Activity, InputHints - -from .default_config import DefaultConfig -from .my_bot import MyBot - - -class BotApp: - """A Flask echo bot.""" - - def __init__(self): - # Create the loop and Flask app - self.loop = asyncio.get_event_loop() - self.flask = Flask(__name__, instance_relative_config=True) - self.flask.config.from_object(DefaultConfig) - - # Create adapter. - # See https://aka.ms/about-bot-adapter to learn more about how bots work. - self.settings = BotFrameworkAdapterSettings( - self.flask.config["APP_ID"], self.flask.config["APP_PASSWORD"] - ) - self.adapter = BotFrameworkAdapter(self.settings) - - # Catch-all for errors. - async def on_error(adapter, context: TurnContext, error: Exception): - # This check writes out errors to console log .vs. app insights. - # NOTE: In production environment, you should consider logging this to Azure - # application insights. - print(f"\n [on_turn_error]: {error}", file=sys.stderr) - - # Send a message to the user - error_message_text = "Sorry, it looks like something went wrong." - error_message = MessageFactory.text( - error_message_text, error_message_text, InputHints.expecting_input - ) - await context.send_activity(error_message) - - # pylint: disable=protected-access - if adapter._conversation_state: - # If state was defined, clear it. - await adapter._conversation_state.delete(context) - - self.adapter.on_turn_error = MethodType(on_error, self.adapter) - - # Create the main dialog - self.bot = MyBot() - - def messages(self) -> Response: - """Main bot message handler that listens for incoming requests.""" - - if "application/json" in request.headers["Content-Type"]: - body = request.json - else: - return Response(status=415) - - activity = Activity().deserialize(body) - auth_header = ( - request.headers["Authorization"] - if "Authorization" in request.headers - else "" - ) - - async def aux_func(turn_context): - await self.bot.on_turn(turn_context) - - try: - task = self.loop.create_task( - self.adapter.process_activity(activity, auth_header, aux_func) - ) - self.loop.run_until_complete(task) - return Response(status=201) - except Exception as exception: - raise exception - - @staticmethod - def test() -> Response: - """ - For test only - verify if the flask app works locally - e.g. with: - ```bash - curl http://127.0.0.1:3978/api/test - ``` - You shall get: - ``` - test - ``` - """ - return Response(status=200, response="test\n") - - def run(self, host=None) -> None: - try: - self.flask.run( - host=host, debug=False, port=self.flask.config["PORT"] - ) # nosec debug - except Exception as exception: - raise exception diff --git a/libraries/functional-tests/functionaltestbot/flask_bot_app/default_config.py b/libraries/functional-tests/functionaltestbot/flask_bot_app/default_config.py deleted file mode 100644 index 96c277e09..000000000 --- a/libraries/functional-tests/functionaltestbot/flask_bot_app/default_config.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -from os import environ - - -class DefaultConfig: - """ Bot Configuration """ - - PORT: int = 3978 - APP_ID: str = environ.get("MicrosoftAppId", "") - APP_PASSWORD: str = environ.get("MicrosoftAppPassword", "") diff --git a/libraries/functional-tests/functionaltestbot/flask_bot_app/my_bot.py b/libraries/functional-tests/functionaltestbot/flask_bot_app/my_bot.py deleted file mode 100644 index 58f002986..000000000 --- a/libraries/functional-tests/functionaltestbot/flask_bot_app/my_bot.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -from botbuilder.core import ActivityHandler, TurnContext -from botbuilder.schema import ChannelAccount - - -class MyBot(ActivityHandler): - """See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.""" - - async def on_message_activity(self, turn_context: TurnContext): - await turn_context.send_activity(f"You said '{ turn_context.activity.text }'") - - async def on_members_added_activity( - self, members_added: ChannelAccount, turn_context: TurnContext - ): - for member_added in members_added: - if member_added.id != turn_context.activity.recipient.id: - await turn_context.send_activity("Hello and welcome!") diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/README.md b/libraries/functional-tests/functionaltestbot/functionaltestbot/README.md deleted file mode 100644 index 996e0909b..000000000 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Console EchoBot -Bot Framework v4 console echo sample. - -This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to create a simple bot that you can talk to from the console window. - -This sample shows a simple echo bot and demonstrates the bot working as a console app using a sample console adapter. - -## To try this sample -- Clone the repository -```bash -git clone https://github.com/Microsoft/botbuilder-python.git -``` - - -### Visual studio code -- open `botbuilder-python\samples\01.console-echo` folder -- Bring up a terminal, navigate to `botbuilder-python\samples\01.console-echo` folder -- type 'python main.py' - - -# Adapters -[Adapters](https://docs.microsoft.com/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0#the-bot-adapter) provide an abstraction for your bot to work with a variety of environments. - -A bot is directed by it's adapter, which can be thought of as the conductor for your bot. The adapter is responsible for directing incoming and outgoing communication, authentication, and so on. The adapter differs based on it's environment (the adapter internally works differently locally versus on Azure) but in each instance it achieves the same goal. - -In most situations we don't work with the adapter directly, such as when creating a bot from a template, but it's good to know it's there and what it does. -The bot adapter encapsulates authentication processes and sends activities to and receives activities from the Bot Connector Service. When your bot receives an activity, the adapter wraps up everything about that activity, creates a [context object](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0#turn-context), passes it to your bot's application logic, and sends responses generated by your bot back to the user's channel. - - -# Further reading - -- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0) -- [Bot basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0) -- [Channels and Bot Connector service](https://docs.microsoft.com/azure/bot-service/bot-concepts?view=azure-bot-service-4.0) -- [Activity processing](https://docs.microsoft.com/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0) \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/about.py b/libraries/functional-tests/functionaltestbot/functionaltestbot/about.py deleted file mode 100644 index 223c72f3d..000000000 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/about.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. -"""Package information.""" -import os - -__title__ = "functionaltestbot" -__version__ = ( - os.environ["packageVersion"] if "packageVersion" in os.environ else "0.0.1" -) -__uri__ = "https://www.github.com/Microsoft/botbuilder-python" -__author__ = "Microsoft" -__description__ = "Microsoft Bot Framework Bot Builder" -__summary__ = "Microsoft Bot Framework Bot Builder SDK for Python." -__license__ = "MIT" diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/app.py b/libraries/functional-tests/functionaltestbot/functionaltestbot/app.py deleted file mode 100644 index 071a17d2b..000000000 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/app.py +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -import asyncio -import sys -from types import MethodType - -from flask import Flask, request, Response -from botbuilder.core import ( - BotFrameworkAdapter, - BotFrameworkAdapterSettings, - MessageFactory, - TurnContext, -) -from botbuilder.schema import Activity, InputHints -from bot import MyBot - -# Create the loop and Flask app -LOOP = asyncio.get_event_loop() -APP = Flask(__name__, instance_relative_config=True) -APP.config.from_object("config.DefaultConfig") - -# Create adapter. -# See https://aka.ms/about-bot-adapter to learn more about how bots work. -SETTINGS = BotFrameworkAdapterSettings(APP.config["APP_ID"], APP.config["APP_PASSWORD"]) -ADAPTER = BotFrameworkAdapter(SETTINGS) - -# Catch-all for errors. -# pylint: disable=unused-argument -async def on_error(self, context: TurnContext, error: Exception): - # This check writes out errors to console log .vs. app insights. - # NOTE: In production environment, you should consider logging this to Azure - # application insights. - print(f"\n [on_turn_error]: {error}", file=sys.stderr) - - # Send a message to the user - error_message_text = "Sorry, it looks like something went wrong." - error_message = MessageFactory.text( - error_message_text, error_message_text, InputHints.expecting_input - ) - await context.send_activity(error_message) - - -ADAPTER.on_turn_error = MethodType(on_error, ADAPTER) - -# Create the main dialog -BOT = MyBot() - -# Listen for incoming requests on GET / for Azure monitoring -@APP.route("/", methods=["GET"]) -def ping(): - return Response(status=200) - - -# Listen for incoming requests on /api/messages. -@APP.route("/api/messages", methods=["POST"]) -def messages(): - # Main bot message handler. - if "application/json" in request.headers["Content-Type"]: - body = request.json - else: - return Response(status=415) - - activity = Activity().deserialize(body) - auth_header = ( - request.headers["Authorization"] if "Authorization" in request.headers else "" - ) - - async def aux_func(turn_context): - await BOT.on_turn(turn_context) - - try: - task = LOOP.create_task( - ADAPTER.process_activity(activity, auth_header, aux_func) - ) - LOOP.run_until_complete(task) - return Response(status=201) - except Exception as exception: - raise exception - - -if __name__ == "__main__": - try: - APP.run(debug=False, port=APP.config["PORT"]) # nosec debug - except Exception as exception: - raise exception diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/bot.py b/libraries/functional-tests/functionaltestbot/functionaltestbot/bot.py deleted file mode 100644 index 128f47cf6..000000000 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/bot.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -from botbuilder.core import ActivityHandler, TurnContext -from botbuilder.schema import ChannelAccount - - -class MyBot(ActivityHandler): - # See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types. - - async def on_message_activity(self, turn_context: TurnContext): - await turn_context.send_activity(f"You said '{ turn_context.activity.text }'") - - async def on_members_added_activity( - self, members_added: ChannelAccount, turn_context: TurnContext - ): - for member_added in members_added: - if member_added.id != turn_context.activity.recipient.id: - await turn_context.send_activity("Hello and welcome!") diff --git a/libraries/functional-tests/functionaltestbot/functionaltestbot/requirements.txt b/libraries/functional-tests/functionaltestbot/functionaltestbot/requirements.txt deleted file mode 100644 index 2e5ecf3fc..000000000 --- a/libraries/functional-tests/functionaltestbot/functionaltestbot/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -botbuilder-core>=4.5.0.b4 -flask>=1.0.3 - diff --git a/libraries/functional-tests/functionaltestbot/init.sh b/libraries/functional-tests/functionaltestbot/init.sh deleted file mode 100644 index 4a5a5be78..000000000 --- a/libraries/functional-tests/functionaltestbot/init.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -echo "Starting SSH ..." -service ssh start - -# flask run --port 3978 --host 0.0.0.0 -python /functionaltestbot/app.py --host 0.0.0.0 \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/requirements.txt b/libraries/functional-tests/functionaltestbot/requirements.txt index a348b59af..38ad6c528 100644 --- a/libraries/functional-tests/functionaltestbot/requirements.txt +++ b/libraries/functional-tests/functionaltestbot/requirements.txt @@ -1,5 +1,7 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -botbuilder-core>=4.5.0.b4 -flask==1.1.1 +click==6.7 +Flask==1.0.2 +itsdangerous==0.24 +Jinja2==2.10 +MarkupSafe==1.0 +Werkzeug==0.14.1 +botbuilder-core>=4.4.0b1 \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/runserver.py b/libraries/functional-tests/functionaltestbot/runserver.py deleted file mode 100644 index 9b0e449a7..000000000 --- a/libraries/functional-tests/functionaltestbot/runserver.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -To run the Flask bot app, in a py virtual environment, -```bash -pip install -r requirements.txt -python runserver.py -``` -""" - -from flask_bot_app import APP - - -if __name__ == "__main__": - APP.run(host="0.0.0.0") diff --git a/libraries/functional-tests/functionaltestbot/setup.py b/libraries/functional-tests/functionaltestbot/setup.py deleted file mode 100644 index 1378ac4b0..000000000 --- a/libraries/functional-tests/functionaltestbot/setup.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -import os -from setuptools import setup - -REQUIRES = [ - "botbuilder-core>=4.5.0.b4", - "flask==1.1.1", -] - -root = os.path.abspath(os.path.dirname(__file__)) - -with open(os.path.join(root, "functionaltestbot", "about.py")) as f: - package_info = {} - info = f.read() - exec(info, package_info) - -setup( - name=package_info["__title__"], - version=package_info["__version__"], - url=package_info["__uri__"], - author=package_info["__author__"], - description=package_info["__description__"], - keywords="botframework azure botbuilder", - long_description=package_info["__summary__"], - license=package_info["__license__"], - packages=["functionaltestbot"], - install_requires=REQUIRES, - dependency_links=["https://github.com/pytorch/pytorch"], - include_package_data=True, - classifiers=[ - "Programming Language :: Python :: 3.6", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Development Status :: 3 - Alpha", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - ], -) diff --git a/libraries/functional-tests/functionaltestbot/sshd_config b/libraries/functional-tests/functionaltestbot/sshd_config deleted file mode 100644 index 7afb7469f..000000000 --- a/libraries/functional-tests/functionaltestbot/sshd_config +++ /dev/null @@ -1,21 +0,0 @@ -# -# /etc/ssh/sshd_config -# - -Port 2222 -ListenAddress 0.0.0.0 -LoginGraceTime 180 -X11Forwarding yes -Ciphers aes128-cbc,3des-cbc,aes256-cbc -MACs hmac-sha1,hmac-sha1-96 -StrictModes yes -SyslogFacility DAEMON -PrintMotd no -IgnoreRhosts no -#deprecated option -#RhostsAuthentication no -RhostsRSAAuthentication yes -RSAAuthentication no -PasswordAuthentication yes -PermitEmptyPasswords no -PermitRootLogin yes \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/template/linux/template.json b/libraries/functional-tests/functionaltestbot/template/linux/template.json deleted file mode 100644 index dcf832eb2..000000000 --- a/libraries/functional-tests/functionaltestbot/template/linux/template.json +++ /dev/null @@ -1,238 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "botName": { - "defaultValue": "nightly-build-python-linux", - "type": "string", - "minLength": 2 - }, - "sku": { - "defaultValue": { - "name": "S1", - "tier": "Standard", - "size": "S1", - "family": "S", - "capacity": 1 - }, - "type": "object" - }, - "linuxFxVersion": { - "type": "string", - "defaultValue": "PYTHON|3.6" - }, - "location": { - "type": "string", - "defaultValue": "West US", - "metadata": { - "description": "Location for all resources." - } - }, - "appId": { - "defaultValue": "1234", - "type": "string" - }, - "appSecret": { - "defaultValue": "blank", - "type": "string" - } - }, - "variables": { - "siteHost": "[concat(parameters('botName'), '.azurewebsites.net')]", - "botEndpoint": "[concat('https://', variables('siteHost'), '/api/mybot')]" - }, - "resources": [ - { - "type": "Microsoft.Web/serverfarms", - "apiVersion": "2017-08-01", - "name": "[parameters('botName')]", - "kind": "linux", - "location": "[parameters('location')]", - "sku": "[parameters('sku')]", - "properties": { - "name": "[parameters('botName')]", - "reserved": true, - "perSiteScaling": false, - "targetWorkerCount": 0, - "targetWorkerSizeId": 0 - } - }, - { - "type": "Microsoft.Web/sites", - "apiVersion": "2016-08-01", - "name": "[parameters('botName')]", - "location": "[parameters('location')]", - "dependsOn": [ - "[resourceId('Microsoft.Web/serverfarms', parameters('botName'))]" - ], - "kind": "app,linux", - "properties": { - "enabled": true, - "hostNameSslStates": [ - { - "name": "[concat(parameters('botName'), '.azurewebsites.net')]", - "sslState": "Disabled", - "hostType": "Standard" - }, - { - "name": "[concat(parameters('botName'), '.scm.azurewebsites.net')]", - "sslState": "Disabled", - "hostType": "Repository" - } - ], - "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('botName'))]", - "siteConfig": { - "linuxFxVersion": "[parameters('linuxFxVersion')]", - "appSettings": [ - { - "name": "WEBSITE_NODE_DEFAULT_VERSION", - "value": "10.14.1" - }, - { - "name": "MicrosoftAppId", - "value": "[parameters('appId')]" - }, - { - "name": "MicrosoftAppPassword", - "value": "[parameters('appSecret')]" - } - ] - }, - "reserved": true, - "scmSiteAlsoStopped": false, - "clientAffinityEnabled": true, - "clientCertEnabled": false, - "hostNamesDisabled": false, - "containerSize": 0, - "dailyMemoryTimeQuota": 0, - "httpsOnly": false - } - }, - { - "type": "Microsoft.Web/sites/config", - "apiVersion": "2016-08-01", - "name": "[concat(parameters('botName'), '/web')]", - "location": "West US", - "dependsOn": [ - "[resourceId('Microsoft.Web/sites', parameters('botName'))]" - ], - "properties": { - "numberOfWorkers": 1, - "defaultDocuments": [ - "Default.htm", - "Default.html", - "Default.asp", - "index.htm", - "index.html", - "iisstart.htm", - "default.aspx", - "index.php", - "hostingstart.html" - ], - "netFrameworkVersion": "v4.0", - "phpVersion": "", - "pythonVersion": "", - "nodeVersion": "", - "linuxFxVersion": "[parameters('linuxFxVersion')]", - "requestTracingEnabled": false, - "remoteDebuggingEnabled": false, - "httpLoggingEnabled": false, - "logsDirectorySizeLimit": 35, - "detailedErrorLoggingEnabled": false, - "publishingUsername": "parameters('botName')", - "scmType": "LocalGit", - "use32BitWorkerProcess": true, - "webSocketsEnabled": false, - "alwaysOn": true, - "appCommandLine": "", - "managedPipelineMode": "Integrated", - "virtualApplications": [ - { - "virtualPath": "/", - "physicalPath": "site\\wwwroot", - "preloadEnabled": true, - "virtualDirectories": null - } - ], - "winAuthAdminState": 0, - "winAuthTenantState": 0, - "customAppPoolIdentityAdminState": false, - "customAppPoolIdentityTenantState": false, - "loadBalancing": "LeastRequests", - "routingRules": [], - "experiments": { - "rampUpRules": [] - }, - "autoHealEnabled": false, - "vnetName": "", - "siteAuthEnabled": false, - "siteAuthSettings": { - "enabled": null, - "unauthenticatedClientAction": null, - "tokenStoreEnabled": null, - "allowedExternalRedirectUrls": null, - "defaultProvider": null, - "clientId": null, - "clientSecret": null, - "clientSecretCertificateThumbprint": null, - "issuer": null, - "allowedAudiences": null, - "additionalLoginParams": null, - "isAadAutoProvisioned": false, - "googleClientId": null, - "googleClientSecret": null, - "googleOAuthScopes": null, - "facebookAppId": null, - "facebookAppSecret": null, - "facebookOAuthScopes": null, - "twitterConsumerKey": null, - "twitterConsumerSecret": null, - "microsoftAccountClientId": null, - "microsoftAccountClientSecret": null, - "microsoftAccountOAuthScopes": null - }, - "localMySqlEnabled": false, - "http20Enabled": true, - "minTlsVersion": "1.2", - "ftpsState": "AllAllowed", - "reservedInstanceCount": 0 - } - }, - { - "apiVersion": "2017-12-01", - "type": "Microsoft.BotService/botServices", - "name": "[parameters('botName')]", - "location": "global", - "kind": "bot", - "sku": { - "name": "[parameters('botName')]" - }, - "properties": { - "name": "[parameters('botName')]", - "displayName": "[parameters('botName')]", - "endpoint": "[variables('botEndpoint')]", - "msaAppId": "[parameters('appId')]", - "developerAppInsightsApplicationId": null, - "developerAppInsightKey": null, - "publishingCredentials": null, - "storageResourceId": null - }, - "dependsOn": [ - "[resourceId('Microsoft.Web/sites/', parameters('botName'))]" - ] - }, - { - "type": "Microsoft.Web/sites/hostNameBindings", - "apiVersion": "2016-08-01", - "name": "[concat(parameters('botName'), '/', parameters('botName'), '.azurewebsites.net')]", - "location": "West US", - "dependsOn": [ - "[resourceId('Microsoft.Web/sites', parameters('botName'))]" - ], - "properties": { - "siteName": "parameters('botName')", - "hostNameType": "Verified" - } - } - ] -} \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/test.sh b/libraries/functional-tests/functionaltestbot/test.sh deleted file mode 100644 index 1c987232e..000000000 --- a/libraries/functional-tests/functionaltestbot/test.sh +++ /dev/null @@ -1 +0,0 @@ -curl -X POST --header 'Accept: application/json' -d '{"text": "Hi!"}' http://localhost:3979 diff --git a/libraries/functional-tests/tests/direct_line_client.py b/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py similarity index 98% rename from libraries/functional-tests/tests/direct_line_client.py rename to libraries/functional-tests/functionaltestbot/tests/direct_line_client.py index 2adda6b0d..252e80b7c 100644 --- a/libraries/functional-tests/tests/direct_line_client.py +++ b/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py @@ -89,4 +89,4 @@ def _start_conversation(self) -> None: # Extract the conversationID for sending messages to bot json_response = bot_response.json() - self._conversation_id = json_response["conversationId"] + self._conversation_id = json_response["conversationId"] \ No newline at end of file diff --git a/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py new file mode 100644 index 000000000..e001df186 --- /dev/null +++ b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py @@ -0,0 +1,44 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +""" +Unit test for testing DirectLine + +To execute: + python -m unittest test_py_bot.py + +This assumes a DirectLine configuration json file is available (DirectLineConfig.json) +that was generated when adding DirectLine to the bot's channel. + + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" + +""" + + +import os +import json +from unittest import TestCase + +from direct_line_client import DirectLineClient + + +class PyBotTest(TestCase): + def setUp(self): + direct_line_config = os.environ.get("DIRECT_LINE_CONFIG", "DirectLineConfig.json") + with open(direct_line_config) as direct_line_file: + self.direct_line_config = json.load(direct_line_file) + self.direct_line_secret = self.direct_line_config['properties']['properties']['sites'][0]['key'] + self.assertIsNotNone(self.direct_line_secret) + + def test_deployed_bot_answer(self): + client = DirectLineClient(self.direct_line_secret) + user_message: str = "Contoso" + + send_result = client.send_message(user_message) + self.assertIsNotNone(send_result) + self.assertEqual(200, send_result.status_code) + + response, text = client.get_message() + self.assertIsNotNone(response) + self.assertEqual(200, response.status_code) + self.assertEqual(f"Echo: {user_message}", text) + print('SUCCESS!') diff --git a/libraries/functional-tests/tests/test_py_bot.py b/libraries/functional-tests/tests/test_py_bot.py deleted file mode 100644 index bdea7fd6c..000000000 --- a/libraries/functional-tests/tests/test_py_bot.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -import os -from unittest import TestCase - -from direct_line_client import DirectLineClient - - -class PyBotTest(TestCase): - def test_deployed_bot_answer(self): - direct_line_secret = os.environ.get("DIRECT_LINE_KEY", "") - if direct_line_secret == "": - return - - client = DirectLineClient(direct_line_secret) - user_message: str = "Contoso" - - send_result = client.send_message(user_message) - self.assertIsNotNone(send_result) - self.assertEqual(200, send_result.status_code) - - response, text = client.get_message() - self.assertIsNotNone(response) - self.assertEqual(200, response.status_code) - self.assertEqual(f"You said '{user_message}'", text) From 23f9fd25daa7078f10eb4f28b89ec4a99cac935a Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 10:49:28 -0800 Subject: [PATCH 02/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 64 ++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c424c7f01..09146c4db 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,61 +1,53 @@ trigger: branches: include: - - daveta-python-functional + - daveta-funtest exclude: - master variables: # Container registry service connection established during pipeline creation - dockerRegistryServiceConnection: 'NightlyE2E-Acr' - azureRmServiceConnection: 'NightlyE2E-RM' - dockerFilePath: 'libraries/functional-tests/functionaltestbot/Dockerfile' buildIdTag: $(Build.BuildNumber) - webAppName: 'e2epython' - containerRegistry: 'nightlye2etest.azurecr.io' - imageRepository: 'functionaltestpy' - - - + webAppName: 'pyfuntest' + resourceGroupName: 'pyfuntest' jobs: -# Build and publish container +# Build and publish - job: Build pool: vmImage: 'Ubuntu-16.04' - displayName: Build and push bot image + displayName: Build environment continueOnError: false steps: - - task: Docker@2 - displayName: Build and push bot image + - task: AzureCLI@2 inputs: - command: buildAndPush - repository: $(imageRepository) - dockerfile: $(dockerFilePath) - containerRegistry: $(dockerRegistryServiceConnection) - tags: $(buildIdTag) - - - -- job: Deploy - displayName: Provision bot container + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az group delete --name $(resourceGroupName) -y + az group create --location westus --name $(resourceGroupName) + cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot + az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) + az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" + az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" + + +- job: Run + displayName: Run Test pool: vmImage: 'Ubuntu-16.04' dependsOn: - Build steps: - - task: AzureRMWebAppDeployment@4 - displayName: Python Functional E2E test. + - task: AzureCLI@2 inputs: - ConnectionType: AzureRM - ConnectedServiceName: $(azureRmServiceConnection) - appType: webAppContainer - WebAppName: $(webAppName) - DockerNamespace: $(containerRegistry) - DockerRepository: $(imageRepository) - DockerImageTag: $(buildIdTag) - AppSettings: '-MicrosoftAppId $(botAppId) -MicrosoftAppPassword $(botAppPassword) -FLASK_APP /functionaltestbot/app.py -FLASK_DEBUG 1' - - #StartupCommand: 'flask run --host=0.0.0.0 --port=3978' + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" + python -m unittest test_py_bot.py From 280d98da0b9ec121bba06102607770e0d66f4255 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 12:13:43 -0800 Subject: [PATCH 03/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 09146c4db..7b92e37f8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -48,6 +48,6 @@ jobs: inlineScript: | cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" - python -m unittest test_py_bot.py + python3 -m unittest test_py_bot.py From 4db927f9642d86c5b4006026566744ff42174d01 Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Thu, 14 Nov 2019 12:27:44 -0800 Subject: [PATCH 04/32] Update --- .../functional-tests/functionaltestbot/tests/test_py_bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py index e001df186..bd444f769 100644 --- a/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py +++ b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py @@ -25,13 +25,13 @@ class PyBotTest(TestCase): def setUp(self): direct_line_config = os.environ.get("DIRECT_LINE_CONFIG", "DirectLineConfig.json") with open(direct_line_config) as direct_line_file: - self.direct_line_config = json.load(direct_line_file) + self.direct_line_config = json.load(direct_line_file) self.direct_line_secret = self.direct_line_config['properties']['properties']['sites'][0]['key'] self.assertIsNotNone(self.direct_line_secret) def test_deployed_bot_answer(self): client = DirectLineClient(self.direct_line_secret) - user_message: str = "Contoso" + user_message = "Contoso" send_result = client.send_message(user_message) self.assertIsNotNone(send_result) From abc11ade9787f140f3eee887e0fdfeb4418112a9 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 12:32:37 -0800 Subject: [PATCH 05/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7b92e37f8..0a039d407 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,11 +12,28 @@ variables: resourceGroupName: 'pyfuntest' jobs: +- job: Cleanup + pool: + vmImage: 'Ubuntu-16.04' + displayName: Cleanup old resource group + continueOnError: true + steps: + - task: AzureCLI@2 + inputs: + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az group delete --name $(resourceGroupName) -y + az group create --location westus --name $(resourceGroupName) + # Build and publish - job: Build pool: vmImage: 'Ubuntu-16.04' - displayName: Build environment + dependsOn: + - Cleanup + displayName: Provision and Deploy Azure Bot continueOnError: false steps: - task: AzureCLI@2 @@ -25,8 +42,6 @@ jobs: scriptType: 'bash' scriptLocation: 'inlineScript' inlineScript: | - az group delete --name $(resourceGroupName) -y - az group create --location westus --name $(resourceGroupName) cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" @@ -34,7 +49,7 @@ jobs: - job: Run - displayName: Run Test + displayName: Run DirectLine test pool: vmImage: 'Ubuntu-16.04' dependsOn: From 139591a49b3b3e021045ba8ccd63104d45af01a5 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 12:49:23 -0800 Subject: [PATCH 06/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0a039d407..3212116ad 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -55,6 +55,9 @@ jobs: dependsOn: - Build steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.6' - task: AzureCLI@2 inputs: azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' @@ -63,6 +66,9 @@ jobs: inlineScript: | cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" - python3 -m unittest test_py_bot.py + + - task: PythonScript@0 + inputs: + script: python3 -m unittest test_py_bot.py From 9e70c3ca1fde99c0740b4f3e30c3cc7c6b3b24f8 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:05:42 -0800 Subject: [PATCH 07/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3212116ad..d7fa406d3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,27 +46,11 @@ jobs: az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" - - -- job: Run - displayName: Run DirectLine test - pool: - vmImage: 'Ubuntu-16.04' - dependsOn: - - Build - steps: + cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" - task: UsePythonVersion@0 inputs: versionSpec: '3.6' - - task: AzureCLI@2 - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests - az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" - - task: PythonScript@0 inputs: script: python3 -m unittest test_py_bot.py From 515f774abff69d3fb99dca6e6ef092eff2821234 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:15:25 -0800 Subject: [PATCH 08/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d7fa406d3..9c41b0a21 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,13 +46,18 @@ jobs: az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" + - task: AzureCLI@2 + inputs: + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.6' - task: PythonScript@0 + displayName: 'Upgrade pip/setuptools. Install deps, pytorch and fastai' inputs: - script: python3 -m unittest test_py_bot.py - - + versionSpec: '3.6' + script: | + python3 -m unittest test_py_bot.py + continueOnError: false \ No newline at end of file From ac5e64a8b1da70a5fb850bbc7c8af8c4c00cf03b Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:16:57 -0800 Subject: [PATCH 09/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9c41b0a21..ebac746df 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,6 +58,6 @@ jobs: displayName: 'Upgrade pip/setuptools. Install deps, pytorch and fastai' inputs: versionSpec: '3.6' - script: | + - script: | python3 -m unittest test_py_bot.py continueOnError: false \ No newline at end of file From 3d211edbfc577b503e56e7395bb2b63cc6d698df Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:44:10 -0800 Subject: [PATCH 10/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ebac746df..7a0ee12a0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,10 +33,11 @@ jobs: vmImage: 'Ubuntu-16.04' dependsOn: - Cleanup - displayName: Provision and Deploy Azure Bot + displayName: Provision/Deploy/Test Azure Bot continueOnError: false steps: - task: AzureCLI@2 + displayName: 'Provision/Deploy Bot' inputs: azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' scriptType: 'bash' @@ -47,17 +48,17 @@ jobs: az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" - task: AzureCLI@2 + displayName: 'Create DirectLine' inputs: azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' scriptType: 'bash' scriptLocation: 'inlineScript' inlineScript: | - cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests - az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > "DirectLineConfig.json" + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/DirectLineConfig.json - task: PythonScript@0 - displayName: 'Upgrade pip/setuptools. Install deps, pytorch and fastai' + displayName: 'Run tests' inputs: - versionSpec: '3.6' - - script: | - python3 -m unittest test_py_bot.py + pythonInterpreter: '/usr/bin/python3' + workingDirectory: $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests + arguments: -m unittest test_py_bot.py continueOnError: false \ No newline at end of file From 0659ef92a984380ed306ced510a69f278629e3ba Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 14:00:34 -0800 Subject: [PATCH 11/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7a0ee12a0..f4fe48aaa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -54,11 +54,11 @@ jobs: scriptType: 'bash' scriptLocation: 'inlineScript' inlineScript: | - az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/DirectLineConfig.json + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json - task: PythonScript@0 displayName: 'Run tests' inputs: - pythonInterpreter: '/usr/bin/python3' - workingDirectory: $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests - arguments: -m unittest test_py_bot.py + versionSpec: '3.6' + workingDirectory: $(Agent.TempDirectory) + arguments: -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py continueOnError: false \ No newline at end of file From c4e332420fca811ed2a1b68a9099969e29e15263 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 14:12:53 -0800 Subject: [PATCH 12/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f4fe48aaa..c4a627538 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,10 +15,10 @@ jobs: - job: Cleanup pool: vmImage: 'Ubuntu-16.04' - displayName: Cleanup old resource group - continueOnError: true + steps: - task: AzureCLI@2 + displayName: Cleanup old resource group inputs: azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' scriptType: 'bash' @@ -26,16 +26,7 @@ jobs: inlineScript: | az group delete --name $(resourceGroupName) -y az group create --location westus --name $(resourceGroupName) - -# Build and publish -- job: Build - pool: - vmImage: 'Ubuntu-16.04' - dependsOn: - - Cleanup - displayName: Provision/Deploy/Test Azure Bot - continueOnError: false - steps: + continueOnError: true - task: AzureCLI@2 displayName: 'Provision/Deploy Bot' inputs: @@ -47,6 +38,7 @@ jobs: az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" + continueOnError: false - task: AzureCLI@2 displayName: 'Create DirectLine' inputs: @@ -55,10 +47,13 @@ jobs: scriptLocation: 'inlineScript' inlineScript: | az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json + continueOnError: false + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.6' - task: PythonScript@0 displayName: 'Run tests' inputs: - versionSpec: '3.6' workingDirectory: $(Agent.TempDirectory) arguments: -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py continueOnError: false \ No newline at end of file From ecffe3b3d9e1c9c2a44fafb722c2ab204cf7bd75 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 14:43:27 -0800 Subject: [PATCH 13/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c4a627538..ce976fa46 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,9 +51,8 @@ jobs: - task: UsePythonVersion@0 inputs: versionSpec: '3.6' - - task: PythonScript@0 - displayName: 'Run tests' - inputs: - workingDirectory: $(Agent.TempDirectory) - arguments: -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py - continueOnError: false \ No newline at end of file + - bash: '/usr/bin/python3 -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py' + workingDirectory: $(Agent.TempDirectory) + displayName: 'Run Test' + continueOnError: false + \ No newline at end of file From ee2fa7762b3f33c441161254f1aba7196127cd35 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 14:57:08 -0800 Subject: [PATCH 14/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ce976fa46..decd34f60 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,6 +51,15 @@ jobs: - task: UsePythonVersion@0 inputs: versionSpec: '3.6' + - bash: 'ls -ltr $(Build.SourcesDirectory)' + workingDirectory: $(Agent.TempDirectory) + displayName: 'SHOW SOURCES' + continueOnError: false + - bash: 'ls -ltr $(Agent.TempDirectory)' + workingDirectory: $(Agent.TempDirectory) + displayName: 'SHOW TEMP' + continueOnError: false + - bash: '/usr/bin/python3 -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py' workingDirectory: $(Agent.TempDirectory) displayName: 'Run Test' From 73f8253a47094d58b9ebcac065ad3c89c0d14535 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:12:15 -0800 Subject: [PATCH 15/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index decd34f60..1b62a7c78 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -60,6 +60,11 @@ jobs: displayName: 'SHOW TEMP' continueOnError: false + - bash: 'pip3 install unittest' + workingDirectory: $(Agent.TempDirectory) + displayName: 'Install Unittest' + continueOnError: false + - bash: '/usr/bin/python3 -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py' workingDirectory: $(Agent.TempDirectory) displayName: 'Run Test' From 7b5dc2f90a7f288e1bd6e8550d2992846d18de3f Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:19:33 -0800 Subject: [PATCH 16/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1b62a7c78..3d6ad3ed6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,19 +51,19 @@ jobs: - task: UsePythonVersion@0 inputs: versionSpec: '3.6' - - bash: 'ls -ltr $(Build.SourcesDirectory)' + - bash: 'ls -ltr $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/' workingDirectory: $(Agent.TempDirectory) displayName: 'SHOW SOURCES' - continueOnError: false + continueOnError: true - bash: 'ls -ltr $(Agent.TempDirectory)' workingDirectory: $(Agent.TempDirectory) displayName: 'SHOW TEMP' - continueOnError: false + continueOnError: true - - bash: 'pip3 install unittest' + - bash: '/usr/bin/python3 -m unittest' workingDirectory: $(Agent.TempDirectory) - displayName: 'Install Unittest' - continueOnError: false + displayName: 'TRY UNITTEST' + continueOnError: true - bash: '/usr/bin/python3 -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py' workingDirectory: $(Agent.TempDirectory) From eb5f003b7c14a658ca19a653efab23a7270e9ef6 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:29:47 -0800 Subject: [PATCH 17/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3d6ad3ed6..1ad0438b6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,21 +51,13 @@ jobs: - task: UsePythonVersion@0 inputs: versionSpec: '3.6' - - bash: 'ls -ltr $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/' - workingDirectory: $(Agent.TempDirectory) - displayName: 'SHOW SOURCES' - continueOnError: true - - bash: 'ls -ltr $(Agent.TempDirectory)' - workingDirectory: $(Agent.TempDirectory) - displayName: 'SHOW TEMP' - continueOnError: true - - bash: '/usr/bin/python3 -m unittest' + - bash: 'cp $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/* $(Agent.TempDirectory)' workingDirectory: $(Agent.TempDirectory) - displayName: 'TRY UNITTEST' - continueOnError: true + displayName: 'Copy Tests' + continueOnError: false - - bash: '/usr/bin/python3 -m unittest $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py' + - bash: '/usr/bin/python3 -m unittest test_py_bot.py' workingDirectory: $(Agent.TempDirectory) displayName: 'Run Test' continueOnError: false From bd964bfb83f8a3ec45351eb1199c909c73d91a46 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:44:46 -0800 Subject: [PATCH 18/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1ad0438b6..b04968548 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -57,7 +57,7 @@ jobs: displayName: 'Copy Tests' continueOnError: false - - bash: '/usr/bin/python3 -m unittest test_py_bot.py' + - bash: 'python -m unittest test_py_bot.py' workingDirectory: $(Agent.TempDirectory) displayName: 'Run Test' continueOnError: false From 69a78d70750523d71b08fdbe6f81723cd645a12e Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:45:31 -0800 Subject: [PATCH 19/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b04968548..a9848e3bf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -17,28 +17,28 @@ jobs: vmImage: 'Ubuntu-16.04' steps: - - task: AzureCLI@2 - displayName: Cleanup old resource group - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az group delete --name $(resourceGroupName) -y - az group create --location westus --name $(resourceGroupName) - continueOnError: true - - task: AzureCLI@2 - displayName: 'Provision/Deploy Bot' - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot - az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) - az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" - az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" - continueOnError: false + # - task: AzureCLI@2 + # displayName: Cleanup old resource group + # inputs: + # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + # scriptType: 'bash' + # scriptLocation: 'inlineScript' + # inlineScript: | + # az group delete --name $(resourceGroupName) -y + # az group create --location westus --name $(resourceGroupName) + # continueOnError: true + # - task: AzureCLI@2 + # displayName: 'Provision/Deploy Bot' + # inputs: + # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + # scriptType: 'bash' + # scriptLocation: 'inlineScript' + # inlineScript: | + # cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot + # az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) + # az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" + # az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" + # continueOnError: false - task: AzureCLI@2 displayName: 'Create DirectLine' inputs: From 3c9b1536db905fd7610b657986cc9eca40e3a66b Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:48:48 -0800 Subject: [PATCH 20/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a9848e3bf..b4a301c09 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -39,15 +39,15 @@ jobs: # az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" # az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" # continueOnError: false - - task: AzureCLI@2 - displayName: 'Create DirectLine' - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json - continueOnError: false + # - task: AzureCLI@2 + # displayName: 'Create DirectLine' + # inputs: + # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + # scriptType: 'bash' + # scriptLocation: 'inlineScript' + # inlineScript: | + # az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json + # continueOnError: false - task: UsePythonVersion@0 inputs: versionSpec: '3.6' @@ -57,8 +57,11 @@ jobs: displayName: 'Copy Tests' continueOnError: false - - bash: 'python -m unittest test_py_bot.py' + - bash: 'python --version' workingDirectory: $(Agent.TempDirectory) - displayName: 'Run Test' + displayName: 'VERSION' continueOnError: false - \ No newline at end of file + # - bash: 'python -m unittest test_py_bot.py' + # workingDirectory: $(Agent.TempDirectory) + # displayName: 'Run Test' + # continueOnError: false From 4eec711a57e3fa3fd001dab7fb39d6b560271580 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:50:06 -0800 Subject: [PATCH 21/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 70 +++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b4a301c09..6c71e1ffa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -17,37 +17,37 @@ jobs: vmImage: 'Ubuntu-16.04' steps: - # - task: AzureCLI@2 - # displayName: Cleanup old resource group - # inputs: - # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - # scriptType: 'bash' - # scriptLocation: 'inlineScript' - # inlineScript: | - # az group delete --name $(resourceGroupName) -y - # az group create --location westus --name $(resourceGroupName) - # continueOnError: true - # - task: AzureCLI@2 - # displayName: 'Provision/Deploy Bot' - # inputs: - # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - # scriptType: 'bash' - # scriptLocation: 'inlineScript' - # inlineScript: | - # cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot - # az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) - # az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" - # az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" - # continueOnError: false - # - task: AzureCLI@2 - # displayName: 'Create DirectLine' - # inputs: - # azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - # scriptType: 'bash' - # scriptLocation: 'inlineScript' - # inlineScript: | - # az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json - # continueOnError: false + - task: AzureCLI@2 + displayName: Cleanup old resource group + inputs: + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az group delete --name $(resourceGroupName) -y + az group create --location westus --name $(resourceGroupName) + continueOnError: true + - task: AzureCLI@2 + displayName: 'Provision/Deploy Bot' + inputs: + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot + az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) + az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" + az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" + continueOnError: false + - task: AzureCLI@2 + displayName: 'Create DirectLine' + inputs: + azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json + continueOnError: false - task: UsePythonVersion@0 inputs: versionSpec: '3.6' @@ -57,11 +57,7 @@ jobs: displayName: 'Copy Tests' continueOnError: false - - bash: 'python --version' + - bash: 'python -m unittest test_py_bot.py' workingDirectory: $(Agent.TempDirectory) - displayName: 'VERSION' + displayName: 'Run Test' continueOnError: false - # - bash: 'python -m unittest test_py_bot.py' - # workingDirectory: $(Agent.TempDirectory) - # displayName: 'Run Test' - # continueOnError: false From f38bece732813e456257ecccc3b879f7e677fb44 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:56:46 -0800 Subject: [PATCH 22/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6c71e1ffa..0b333091f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -52,11 +52,16 @@ jobs: inputs: versionSpec: '3.6' + - bash: 'cp $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/* $(Agent.TempDirectory)' workingDirectory: $(Agent.TempDirectory) displayName: 'Copy Tests' continueOnError: false + - bash: 'pip install requests' + displayName: 'Install dependencies for test' + continueOnError: false + - bash: 'python -m unittest test_py_bot.py' workingDirectory: $(Agent.TempDirectory) displayName: 'Run Test' From 3daade79fe0b0c66e7463bbb51167e0c9e418069 Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Fri, 15 Nov 2019 12:10:01 -0800 Subject: [PATCH 23/32] Add deploy script with retries --- .../scripts/deploy_webapp.sh | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh diff --git a/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh b/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh new file mode 100644 index 000000000..7792643e5 --- /dev/null +++ b/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh @@ -0,0 +1,160 @@ +#!/bin/bash +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# This Script provisions and deploys a Python bot with retries. + +# Make errors stop the script (set -e) +set -e +# Uncomment to debug: print commands (set -x) +#set -x + +# Define Environment Variables +WEBAPP_NAME="pyfuntest" +WEBAPP_URL= +BOT_NAME="pyfuntest" +BOT_ID="python_functional" +AZURE_RESOURCE_GROUP= +BOT_APPID= +BOT_PASSWORD= + +usage() +{ + echo "${0##*/} [options]" + echo "" + echo "Runs Python DirectLine bot test." + echo "- Deletes and recreates given Azure Resource Group (cleanup)" + echo "- Provision and deploy python bot" + echo "- Provision DirectLine support for bot" + echo "- Run python directline client against deployed bot using DirectLine" + echo " as a test." + echo "" + echo "Note: Assumes you are logged into Azure." + echo "" + echo "options" + echo " -a, --appid Bot App ID" + echo " -p, --password Bot App Password" + echo " -g, --resource-group Azure Resource Group name" + exit 1; +} + +print_help_and_exit() +{ + echo "Run '${0##*/} --help' for more information." + exit 1 +} + +process_args() +{ + if [ "${PWD##*/}" != 'functionaltestbot' ]; then + echo "ERROR: Must run from '/functional-tests/functionaltestbot' directory." + echo "Your current directory: ${PWD##*/}" + echo "" + echo "For example:" + echo "$ ./scripts/deploy_webapp.sh --appid X --password Y -g Z" + exit 1 + fi + + save_next_arg=0 + for arg in "$@" + do + if [[ ${save_next_arg} -eq 1 ]]; then + BOT_APPID="$arg" + save_next_arg=0 + elif [[ ${save_next_arg} -eq 2 ]]; then + BOT_PASSWORD="$arg" + save_next_arg=0 + elif [[ ${save_next_arg} -eq 3 ]]; then + AZURE_RESOURCE_GROUP="$arg" + save_next_arg=0 + else + case "$arg" in + "-h" | "--help" ) usage;; + "-a" | "--appid" ) save_next_arg=1;; + "-p" | "--password" ) save_next_arg=2;; + "-g" | "--resource-group" ) save_next_arg=3;; + * ) usage;; + esac + fi + done + if [[ -z ${BOT_APPID} ]]; then + echo "Bot appid parameter invalid" + print_help_and_exit + fi + if [[ -z ${BOT_PASSWORD} ]]; then + echo "Bot password parameter invalid" + print_help_and_exit + fi + if [[ -z ${AZURE_RESOURCE_GROUP} ]]; then + echo "Azure Resource Group parameter invalid" + print_help_and_exit + fi +} + +############################################################################### +# Main Script Execution +############################################################################### +process_args "$@" + +# Recreate Resource Group + +# It's ok to fail (set +e) - script continues on error result code. +set +e +az group delete --name ${AZURE_RESOURCE_GROUP} -y + +n=0 +until [ $n -ge 3 ] +do + az group create --location westus --name ${AZURE_RESOURCE_GROUP} && break + n=$[$n+1] + sleep 15 +done + +# Push Web App +n=0 +until [ $n -ge 3 ] +do + az webapp up --sku F1 -n ${WEBAPP_NAME} -l westus --resource-group ${AZURE_RESOURCE_GROUP} && break + n=$[$n+1] + sleep 15 +done + + +# Create Bot +n=0 +until [ $n -ge 3 ] +do + az bot create --appid ${BOT_APPID} --name ${BOT_NAME} --password ${BOT_PASSWORD} --resource-group ${AZURE_RESOURCE_GROUP} --sku F0 --kind registration --location westus --endpoint "https://${WEBAPP_NAME}.azurewebsites.net/api/messages" && break + n=$[$n+1] + sleep 15 +done + +# Create bot settings +n=0 +until [ $n -ge 3 ] +do + az webapp config appsettings set -g ${AZURE_RESOURCE_GROUP} -n ${AZURE_RESOURCE_GROUP} --settings MicrosoftAppId=${BOT_APPID} MicrosoftAppPassword=${BOT_PASSWORD} botId=${BOT_ID} && break + n=$[$n+1] + sleep 15 +done + +# Create DirectLine +cd tests +n=0 +until [ $n -ge 3 ] +do + az bot directline create --name ${BOT_NAME} --resource-group ${AZURE_RESOURCE_GROUP} > "DirectLineConfig.json" && break + n=$[$n+1] + sleep 15 +done + +# Run Tests +pip install requests +n=0 +until [ $n -ge 3 ] +do + python -m unittest test_py_bot.py && break + n=$[$n+1] + sleep 15 +done + From c547db87076b9cce37d4e82eff58ae910d6763dd Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:14:47 -0800 Subject: [PATCH 24/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 49 +++------------------------------------------ 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0b333091f..a7d152074 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,63 +6,20 @@ trigger: - master variables: - # Container registry service connection established during pipeline creation - buildIdTag: $(Build.BuildNumber) - webAppName: 'pyfuntest' resourceGroupName: 'pyfuntest' jobs: -- job: Cleanup +- job: Doit pool: vmImage: 'Ubuntu-16.04' - steps: - task: AzureCLI@2 - displayName: Cleanup old resource group - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az group delete --name $(resourceGroupName) -y - az group create --location westus --name $(resourceGroupName) - continueOnError: true - - task: AzureCLI@2 - displayName: 'Provision/Deploy Bot' + displayName: Provision, Deploy and run tests inputs: azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' scriptType: 'bash' scriptLocation: 'inlineScript' inlineScript: | cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot - az webapp up --sku F1 -n $(webAppName) -l westus --resource-group $(resourceGroupName) - az bot create --appid $(botAppId) --name $(webAppName) --password $(botAppPassword) --resource-group $(resourceGroupName) --sku F0 --kind registration --location westus --endpoint "https://pyfuntest.azurewebsites.net/api/messages" - az webapp config appsettings set -g $(resourceGroupName) -n $(webAppName) --settings MicrosoftAppId=$(botAppId) MicrosoftAppPassword=$(botAppPassword) botId="pythonfunctional" - continueOnError: false - - task: AzureCLI@2 - displayName: 'Create DirectLine' - inputs: - azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az bot directline create --name "pyfuntest" --resource-group "pyfuntest" > $(Agent.TempDirectory)/DirectLineConfig.json - continueOnError: false - - task: UsePythonVersion@0 - inputs: - versionSpec: '3.6' - - - - bash: 'cp $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot/tests/* $(Agent.TempDirectory)' - workingDirectory: $(Agent.TempDirectory) - displayName: 'Copy Tests' - continueOnError: false - - - bash: 'pip install requests' - displayName: 'Install dependencies for test' - continueOnError: false - - - bash: 'python -m unittest test_py_bot.py' - workingDirectory: $(Agent.TempDirectory) - displayName: 'Run Test' + ./scripts/deploy_webapp.sh --appid $(botAppId) --password $(botAppPassword) -g $(resourceGroupName) continueOnError: false From 0d8c983757a974f1858288037be94d08d1d2e455 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:16:30 -0800 Subject: [PATCH 25/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a7d152074..344afae6e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,5 +21,6 @@ jobs: scriptLocation: 'inlineScript' inlineScript: | cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot + chmod +x ./scripts/deploy_webapp.sh ./scripts/deploy_webapp.sh --appid $(botAppId) --password $(botAppPassword) -g $(resourceGroupName) continueOnError: false From cfb983beb743e194e82bb9fbf717941b02e55c24 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:23:32 -0800 Subject: [PATCH 26/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 344afae6e..357d39621 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,7 +12,13 @@ jobs: - job: Doit pool: vmImage: 'Ubuntu-16.04' + steps: + - task: UsePythonVersion@0 + displayName: Use Python 3.6 + inputs: + versionSpec: '3.6' + - task: AzureCLI@2 displayName: Provision, Deploy and run tests inputs: From 81b7ff7f37f958542062ad376917649db31f8d8a Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Fri, 15 Nov 2019 12:49:55 -0800 Subject: [PATCH 27/32] Better error checking --- .../scripts/deploy_webapp.sh | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh b/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh index 7792643e5..c1e7efd4d 100644 --- a/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh +++ b/libraries/functional-tests/functionaltestbot/scripts/deploy_webapp.sh @@ -107,8 +107,12 @@ until [ $n -ge 3 ] do az group create --location westus --name ${AZURE_RESOURCE_GROUP} && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Could not create group ${AZURE_RESOURCE_GROUP}" + exit 3 +fi # Push Web App n=0 @@ -116,18 +120,26 @@ until [ $n -ge 3 ] do az webapp up --sku F1 -n ${WEBAPP_NAME} -l westus --resource-group ${AZURE_RESOURCE_GROUP} && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Could not create webapp ${WEBAPP_NAME}" + exit 4 +fi -# Create Bot n=0 until [ $n -ge 3 ] do az bot create --appid ${BOT_APPID} --name ${BOT_NAME} --password ${BOT_PASSWORD} --resource-group ${AZURE_RESOURCE_GROUP} --sku F0 --kind registration --location westus --endpoint "https://${WEBAPP_NAME}.azurewebsites.net/api/messages" && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Could not create BOT ${BOT_NAME}" + exit 5 +fi + # Create bot settings n=0 @@ -135,8 +147,12 @@ until [ $n -ge 3 ] do az webapp config appsettings set -g ${AZURE_RESOURCE_GROUP} -n ${AZURE_RESOURCE_GROUP} --settings MicrosoftAppId=${BOT_APPID} MicrosoftAppPassword=${BOT_PASSWORD} botId=${BOT_ID} && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Could not create BOT configuration" + exit 6 +fi # Create DirectLine cd tests @@ -145,8 +161,13 @@ until [ $n -ge 3 ] do az bot directline create --name ${BOT_NAME} --resource-group ${AZURE_RESOURCE_GROUP} > "DirectLineConfig.json" && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Could not create Directline configuration" + exit 7 +fi + # Run Tests pip install requests @@ -155,6 +176,11 @@ until [ $n -ge 3 ] do python -m unittest test_py_bot.py && break n=$[$n+1] - sleep 15 + sleep 25 done +if [[ $n -ge 3 ]]; then + echo "Tests failed!" + exit 8 +fi + From cec121389d825137d586538bb7c877dd5737b53a Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Fri, 15 Nov 2019 13:06:32 -0800 Subject: [PATCH 28/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 357d39621..a61f19888 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,6 @@ trigger: branches: include: - - daveta-funtest - exclude: - master variables: From 76167771f1f60dde5e8dee7fa3ca69f1f1a13308 Mon Sep 17 00:00:00 2001 From: daveta <6182197+daveta@users.noreply.github.com> Date: Fri, 15 Nov 2019 14:56:43 -0800 Subject: [PATCH 29/32] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a61f19888..f2eb246e9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,4 +1,6 @@ -trigger: +schedules: +- cron: "0 0 * * *" + displayName: Daily midnight build branches: include: - master From 8befa399138160b16e4b995285c2df08a251171e Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Fri, 15 Nov 2019 14:57:52 -0800 Subject: [PATCH 30/32] Don't run pytest on functional-tests --- .coveragerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 4dd59303b..304e0a883 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,4 +3,5 @@ source = ./libraries/ omit = */tests/* setup.py - */botbuilder-schema/* \ No newline at end of file + */botbuilder-schema/* + */functional-tests/* From 5486fd56f967168ae8d29a950625afd120f3c483 Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Fri, 15 Nov 2019 16:29:32 -0800 Subject: [PATCH 31/32] Fix black/pylint --- .../functionaltestbot/application.py | 25 +++++++++++++------ .../functionaltestbot/bots/__init__.py | 2 +- .../functionaltestbot/bots/echo_bot.py | 4 ++- .../functionaltestbot/config.py | 5 +--- .../tests/direct_line_client.py | 2 +- .../functionaltestbot/tests/test_py_bot.py | 10 +++++--- setup.cfg | 2 ++ 7 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 setup.cfg diff --git a/libraries/functional-tests/functionaltestbot/application.py b/libraries/functional-tests/functionaltestbot/application.py index 45680e243..cf8de8edc 100644 --- a/libraries/functional-tests/functionaltestbot/application.py +++ b/libraries/functional-tests/functionaltestbot/application.py @@ -7,21 +7,26 @@ from datetime import datetime from flask import Flask, request, Response -from botbuilder.core import BotFrameworkAdapterSettings, TurnContext, BotFrameworkAdapter, \ -ActivityHandler, MessageFactory, TurnContext +from botbuilder.core import ( + BotFrameworkAdapterSettings, + BotFrameworkAdapter, + TurnContext, +) from botbuilder.schema import Activity, ActivityTypes -from botbuilder.schema import ChannelAccount from bots import EchoBot # Create the loop and Flask app LOOP = asyncio.get_event_loop() +# pylint: disable=invalid-name app = Flask(__name__, instance_relative_config=True) app.config.from_object("config.DefaultConfig") # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. -SETTINGS = BotFrameworkAdapterSettings(os.environ.get("MicrosoftAppId", ""), os.environ.get("MicrosoftAppPassword", "")) +SETTINGS = BotFrameworkAdapterSettings( + os.environ.get("MicrosoftAppId", ""), os.environ.get("MicrosoftAppPassword", "") +) ADAPTER = BotFrameworkAdapter(SETTINGS) @@ -34,9 +39,11 @@ async def on_error(context: TurnContext, error: Exception): # Send a message to the user await context.send_activity("The bot encountered an error or bug.") - await context.send_activity("To continue to run this bot, please fix the bot source code.") + await context.send_activity( + "To continue to run this bot, please fix the bot source code." + ) # Send a trace activity if we're talking to the Bot Framework Emulator - if context.activity.channel_id == 'emulator': + if context.activity.channel_id == "emulator": # Create a trace activity that contains the error object trace_activity = Activity( label="TurnError", @@ -44,11 +51,12 @@ async def on_error(context: TurnContext, error: Exception): timestamp=datetime.utcnow(), type=ActivityTypes.trace, value=f"{error}", - value_type="https://www.botframework.com/schemas/error" + value_type="https://www.botframework.com/schemas/error", ) # Send a trace activity, which will be displayed in Bot Framework Emulator await context.send_activity(trace_activity) + ADAPTER.on_turn_error = on_error # Create the Bot @@ -77,6 +85,7 @@ def messages(): except Exception as exception: raise exception + @app.route("/", methods=["GET"]) def ping(): return "Hello World!" @@ -86,4 +95,4 @@ def ping(): try: app.run(debug=False, port=3978) # nosec debug except Exception as exception: - raise exception \ No newline at end of file + raise exception diff --git a/libraries/functional-tests/functionaltestbot/bots/__init__.py b/libraries/functional-tests/functionaltestbot/bots/__init__.py index c215edb22..f95fbbbad 100644 --- a/libraries/functional-tests/functionaltestbot/bots/__init__.py +++ b/libraries/functional-tests/functionaltestbot/bots/__init__.py @@ -3,4 +3,4 @@ from .echo_bot import EchoBot -__all__ = ["EchoBot"] \ No newline at end of file +__all__ = ["EchoBot"] diff --git a/libraries/functional-tests/functionaltestbot/bots/echo_bot.py b/libraries/functional-tests/functionaltestbot/bots/echo_bot.py index 985c0694c..90a094640 100644 --- a/libraries/functional-tests/functionaltestbot/bots/echo_bot.py +++ b/libraries/functional-tests/functionaltestbot/bots/echo_bot.py @@ -14,4 +14,6 @@ async def on_members_added_activity( await turn_context.send_activity("Hello and welcome!") async def on_message_activity(self, turn_context: TurnContext): - return await turn_context.send_activity(MessageFactory.text(f"Echo: {turn_context.activity.text}")) + return await turn_context.send_activity( + MessageFactory.text(f"Echo: {turn_context.activity.text}") + ) diff --git a/libraries/functional-tests/functionaltestbot/config.py b/libraries/functional-tests/functionaltestbot/config.py index b2bdd7fb2..7163a79aa 100644 --- a/libraries/functional-tests/functionaltestbot/config.py +++ b/libraries/functional-tests/functionaltestbot/config.py @@ -4,12 +4,9 @@ import os -""" Bot Configuration """ - - class DefaultConfig: """ Bot Configuration """ PORT = 3978 APP_ID = os.environ.get("MicrosoftAppId", "") - APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") \ No newline at end of file + APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") diff --git a/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py b/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py index 252e80b7c..2adda6b0d 100644 --- a/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py +++ b/libraries/functional-tests/functionaltestbot/tests/direct_line_client.py @@ -89,4 +89,4 @@ def _start_conversation(self) -> None: # Extract the conversationID for sending messages to bot json_response = bot_response.json() - self._conversation_id = json_response["conversationId"] \ No newline at end of file + self._conversation_id = json_response["conversationId"] diff --git a/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py index bd444f769..3a78aca08 100644 --- a/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py +++ b/libraries/functional-tests/functionaltestbot/tests/test_py_bot.py @@ -23,10 +23,14 @@ class PyBotTest(TestCase): def setUp(self): - direct_line_config = os.environ.get("DIRECT_LINE_CONFIG", "DirectLineConfig.json") + direct_line_config = os.environ.get( + "DIRECT_LINE_CONFIG", "DirectLineConfig.json" + ) with open(direct_line_config) as direct_line_file: self.direct_line_config = json.load(direct_line_file) - self.direct_line_secret = self.direct_line_config['properties']['properties']['sites'][0]['key'] + self.direct_line_secret = self.direct_line_config["properties"]["properties"][ + "sites" + ][0]["key"] self.assertIsNotNone(self.direct_line_secret) def test_deployed_bot_answer(self): @@ -41,4 +45,4 @@ def test_deployed_bot_answer(self): self.assertIsNotNone(response) self.assertEqual(200, response.status_code) self.assertEqual(f"Echo: {user_message}", text) - print('SUCCESS!') + print("SUCCESS!") diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..dd4ed50bd --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[tool:pytest] +norecursedirs = functionaltestbot From 8ca9591837091dd79d7b003be25d2341a979040a Mon Sep 17 00:00:00 2001 From: Dave Taniguchi Date: Fri, 15 Nov 2019 16:33:03 -0800 Subject: [PATCH 32/32] Black fix --- libraries/functional-tests/functionaltestbot/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/functional-tests/functionaltestbot/config.py b/libraries/functional-tests/functionaltestbot/config.py index 7163a79aa..6b5116fba 100644 --- a/libraries/functional-tests/functionaltestbot/config.py +++ b/libraries/functional-tests/functionaltestbot/config.py @@ -4,6 +4,7 @@ import os + class DefaultConfig: """ Bot Configuration """