Skip to content

Functional Test #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
01af791
Cleanup
daveta Nov 14, 2019
23f9fd2
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
280d98d
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
4db927f
Update
daveta Nov 14, 2019
14c010a
Merge branch 'daveta-funtest' of https://github.com/microsoft/botbuil…
daveta Nov 14, 2019
abc11ad
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
139591a
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
9e70c3c
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
515f774
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
ac5e64a
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
3d211ed
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
0659ef9
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
c4e3324
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
ecffe3b
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
ee2fa77
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
73f8253
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
7b5dc2f
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
eb5f003
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
bd964bf
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
69a78d7
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
3c9b153
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
4eec711
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
f38bece
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 14, 2019
3daade7
Add deploy script with retries
daveta Nov 15, 2019
c547db8
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 15, 2019
0d8c983
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 15, 2019
cfb983b
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 15, 2019
81b7ff7
Better error checking
daveta Nov 15, 2019
cec1213
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 15, 2019
dacc276
Merge branch 'master' into daveta-funtest
axelsrz Nov 15, 2019
7616777
Update azure-pipelines.yml for Azure Pipelines
daveta Nov 15, 2019
8befa39
Don't run pytest on functional-tests
daveta Nov 15, 2019
245d384
Merge branch 'daveta-funtest' of https://github.com/microsoft/botbuil…
daveta Nov 15, 2019
5486fd5
Fix black/pylint
daveta Nov 16, 2019
8ca9591
Black fix
daveta Nov 16, 2019
6d0834d
Merge branch 'master' into daveta-funtest
axelsrz Dec 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ source = ./libraries/
omit =
*/tests/*
setup.py
*/botbuilder-schema/*
*/botbuilder-schema/*
*/functional-tests/*
67 changes: 19 additions & 48 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,32 @@
trigger:
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- daveta-python-functional
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'



resourceGroupName: 'pyfuntest'

jobs:
# Build and publish container
- job: Build
- job: Doit
pool:
vmImage: 'Ubuntu-16.04'
displayName: Build and push bot image
continueOnError: false
steps:
- task: Docker@2
displayName: Build and push bot image
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerFilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: $(buildIdTag)



- job: Deploy
displayName: Provision bot container
pool:
vmImage: 'Ubuntu-16.04'
dependsOn:
- Build
steps:
- task: AzureRMWebAppDeployment@4
displayName: Python Functional E2E test.
- task: UsePythonVersion@0
displayName: Use Python 3.6
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'

versionSpec: '3.6'

- task: AzureCLI@2
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
chmod +x ./scripts/deploy_webapp.sh
./scripts/deploy_webapp.sh --appid $(botAppId) --password $(botAppPassword) -g $(resourceGroupName)
continueOnError: false
48 changes: 0 additions & 48 deletions libraries/functional-tests/functionaltestbot/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions libraries/functional-tests/functionaltestbot/Dockfile

This file was deleted.

9 changes: 9 additions & 0 deletions libraries/functional-tests/functionaltestbot/README.md
Original file line number Diff line number Diff line change
@@ -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.
98 changes: 98 additions & 0 deletions libraries/functional-tests/functionaltestbot/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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,
BotFrameworkAdapter,
TurnContext,
)
from botbuilder.schema import Activity, ActivityTypes

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", "")
)
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
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions libraries/functional-tests/functionaltestbot/bots/echo_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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}")
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
class DefaultConfig:
""" Bot Configuration """

PORT = 443
PORT = 3978
APP_ID = os.environ.get("MicrosoftAppId", "")
APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")
21 changes: 0 additions & 21 deletions libraries/functional-tests/functionaltestbot/flask_bot_app/app.py

This file was deleted.

Loading