-
Notifications
You must be signed in to change notification settings - Fork 107
Configurable file name #1323
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
Configurable file name #1323
Changes from 14 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
8f80e5d
configurable file name
hallvictoria 7b36194
lint & error fix
hallvictoria be976ae
test fix
hallvictoria a2fc96b
Merge branch de into hallvictoria/configurable_file_name
hallvictoria 9b3ce3a
fix merge lint errors
hallvictoria d0351ac
e2e and loader test
hallvictoria cc0f762
test linting errors
hallvictoria 665b2ea
test linting errors
hallvictoria 389e7d6
e2e file name test
hallvictoria b7bb44b
test lint checks
hallvictoria 9150156
testing fixes
hallvictoria d187db7
moved tests to new file
hallvictoria 11abe8b
fixed last test
hallvictoria f11a1bf
merge with dev
hallvictoria 1c15b57
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 9452139
file name, conciseness
hallvictoria 88c695e
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria f0a01b8
Merge branch 'dev' into hallvictoria/configurable_file_name
vrdmr a40c5ff
additional tests
hallvictoria 479d3a3
Merge branch 'hallvictoria/configurable_file_name' of https://github.…
hallvictoria af861b8
merge with dev
hallvictoria 5ce888a
slight test changes
hallvictoria 0175c33
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 9cc2985
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 1bea4ae
updated tests
hallvictoria 008ad85
fixing tests
hallvictoria 43b21fb
refactored tests
hallvictoria 24119e5
lint
hallvictoria ed2555c
moved invalid stein tests to broken tests file
hallvictoria acefbdd
fixed test check
hallvictoria 11a74cb
sep broken stein tests
hallvictoria e3465a9
renamed, removed prints
hallvictoria 23e1de5
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria e0fe45c
edited logs to now also show script file name
hallvictoria 52b3784
formatting
hallvictoria 7b927a2
Merge branch 'dev' into hallvictoria/configurable_file_name
hallvictoria 4657b15
increase timeout
hallvictoria f36e463
Merge branch 'hallvictoria/configurable_file_name' of https://github.…
hallvictoria 935c4d7
env vars method
hallvictoria c9c2035
printing env variables for failing tests
hallvictoria a1a7a78
cls stop env
hallvictoria 6fee33f
class methods
hallvictoria 97d1045
setting file name explicitly
hallvictoria 0f66e14
reset script file name after test ends
hallvictoria 0be62f8
lint + misc fixes
hallvictoria 791ddea
refactor tests
hallvictoria 447a699
added extra tests
hallvictoria cec0b35
debugging logs
hallvictoria adf54a9
global var
hallvictoria 8fcd03d
added method to testutils
hallvictoria c13c997
validate file name + tests
hallvictoria d05f4ad
fixed tests
hallvictoria 98023be
copyright
hallvictoria b29ac0d
Merge branch 'dev' into hallvictoria/configurable_file_name
hallvictoria 9347e42
Merge branch 'dev' into hallvictoria/configurable_file_name
gavin-aguiar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/endtoend/http_functions/http_functions_stein/file_name/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from datetime import datetime | ||
import logging | ||
import time | ||
|
||
import azure.functions as func | ||
|
||
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) | ||
|
||
|
||
@app.route(route="default_template") | ||
def default_template(req: func.HttpRequest) -> func.HttpResponse: | ||
logging.info('Python HTTP trigger function processed a request.') | ||
|
||
name = req.params.get('name') | ||
if not name: | ||
try: | ||
req_body = req.get_json() | ||
except ValueError: | ||
pass | ||
else: | ||
name = req_body.get('name') | ||
|
||
if name: | ||
return func.HttpResponse( | ||
f"Hello, {name}. This HTTP triggered function " | ||
f"executed successfully.") | ||
else: | ||
return func.HttpResponse( | ||
"This HTTP triggered function executed successfully. " | ||
"Pass a name in the query string or in the request body for a" | ||
" personalized response.", | ||
status_code=200 | ||
) | ||
|
||
|
||
@app.route(route="http_func") | ||
def http_func(req: func.HttpRequest) -> func.HttpResponse: | ||
time.sleep(1) | ||
|
||
current_time = datetime.now().strftime("%H:%M:%S") | ||
return func.HttpResponse(f"{current_time}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import os | ||
from unittest.mock import patch | ||
|
||
import requests | ||
|
||
from azure_functions_worker.constants import SCRIPT_FILE_NAME | ||
from tests.utils import testutils | ||
|
||
REQUEST_TIMEOUT_SEC = 5 | ||
|
||
|
||
class TestHttpFunctionsFileName(testutils.WebHostTestCase): | ||
hallvictoria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Test the native Http Trigger in the local webhost. | ||
|
||
This test class will spawn a webhost from your <project_root>/build/webhost | ||
folder and replace the built-in Python with azure_functions_worker from | ||
your code base. Since the Http Trigger is a native suport from host, we | ||
don't need to setup any external resources. | ||
|
||
Compared to the unittests/test_http_functions.py, this file is more focus | ||
on testing the E2E flow scenarios. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.env_variables['SCRIPT_FILE_NAME'] = 'main.py' | ||
|
||
os_environ = os.environ.copy() | ||
os_environ.update(cls.env_variables) | ||
|
||
cls._patch_environ = patch.dict('os.environ', os_environ) | ||
cls._patch_environ.start() | ||
super().setUpClass() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self._patch_environ.stop() | ||
|
||
@classmethod | ||
def get_script_dir(cls): | ||
return testutils.E2E_TESTS_FOLDER / 'http_functions' / \ | ||
'http_functions_stein' / \ | ||
'file_name' | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_function_index_page_should_return_ok(self): | ||
"""The index page of Azure Functions should return OK in any | ||
circumstances | ||
""" | ||
r = self.webhost.request('GET', '', no_prefix=True, | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_default_http_template_should_return_ok(self): | ||
"""Test if the default template of Http trigger in Python Function app | ||
will return OK | ||
""" | ||
r = self.webhost.request('GET', 'default_template', | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_default_http_template_should_accept_query_param(self): | ||
"""Test if the azure.functions SDK is able to deserialize query | ||
parameter from the default template | ||
""" | ||
r = self.webhost.request('GET', 'default_template', | ||
params={'name': 'query'}, | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
self.assertEqual( | ||
r.content, | ||
b'Hello, query. This HTTP triggered function executed successfully.' | ||
) | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_default_http_template_should_accept_body(self): | ||
"""Test if the azure.functions SDK is able to deserialize http body | ||
and pass it to default template | ||
""" | ||
r = self.webhost.request('POST', 'default_template', | ||
data='{ "name": "body" }'.encode('utf-8'), | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
self.assertEqual( | ||
r.content, | ||
b'Hello, body. This HTTP triggered function executed successfully.' | ||
) | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_worker_status_endpoint_should_return_ok(self): | ||
"""Test if the worker status endpoint will trigger | ||
_handle__worker_status_request and sends a worker status response back | ||
to host | ||
""" | ||
root_url = self.webhost._addr | ||
health_check_url = f'{root_url}/admin/host/ping' | ||
r = requests.post(health_check_url, | ||
params={'checkHealth': '1'}, | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
|
||
@testutils.retryable_test(3, 5) | ||
def test_worker_status_endpoint_should_return_ok_when_disabled(self): | ||
"""Test if the worker status endpoint will trigger | ||
_handle__worker_status_request and sends a worker status response back | ||
to host | ||
""" | ||
os.environ['WEBSITE_PING_METRICS_SCALE_ENABLED'] = '0' | ||
root_url = self.webhost._addr | ||
health_check_url = f'{root_url}/admin/host/ping' | ||
r = requests.post(health_check_url, | ||
params={'checkHealth': '1'}, | ||
timeout=REQUEST_TIMEOUT_SEC) | ||
self.assertTrue(r.ok) | ||
|
||
def test_correct_file_name(self): | ||
os.environ.update({SCRIPT_FILE_NAME: "main.py"}) | ||
self.assertIsNotNone(os.environ.get(SCRIPT_FILE_NAME)) | ||
self.assertEqual(os.environ.get(SCRIPT_FILE_NAME), | ||
'main.py') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.