Skip to content

Commit

Permalink
service-driven-test
Browse files Browse the repository at this point in the history
  • Loading branch information
changlong-liu committed Mar 8, 2022
1 parent 0e4a20b commit d365fdc
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#
# --------------------------------------------------------------------------
import pytest
import json
from azure.core.rest import HttpRequest

from dpgservicedriveninitiallowlevel.aio import DPGClient as DPGClientInitial
from dpgservicedrivenupdateonelowlevel.aio import DPGClient as DPGClientUpdateOne
Expand Down Expand Up @@ -62,3 +64,64 @@ async def test_required_to_optional(initial_send_request, update_one_send_reques

request = params_update_one.build_get_required_request(parameter="foo", new_parameter="bar")
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_none(initial_send_request, update_one_send_request):
request = params_initial.build_head_no_params_request()
await initial_send_request(request)

request = params_update_one.build_head_no_params_request(new_parameter="bar")
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_required_optional(initial_send_request, update_one_send_request):
request = params_initial.build_put_required_optional_request(required_param="foo", optional_param="bar")
await initial_send_request(request)

request = params_update_one.build_put_required_optional_request(required_param="foo", optional_param="bar", new_parameter="baz")
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_optional(initial_send_request, update_one_send_request):
request = params_initial.build_get_optional_request(optional_param="foo")
await initial_send_request(request)

request = params_update_one.build_get_optional_request(optional_param="foo", new_parameter="bar")
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_new_content_type(initial_send_request, update_one_send_request):
request = params_initial.build_post_parameters_request(json={ "url": "http://example.org/myimage.jpeg" })
await initial_send_request(request)

request = params_update_one.build_post_parameters_request(json={ "url": "http://example.org/myimage.jpeg" })
await update_one_send_request(request)
request = params_update_one.build_post_parameters_request(content=b"hello", content_type="image/jpeg")
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_new_operation(update_one_send_request):
with pytest.raises(AttributeError):
params_initial.build_delete_parameters_request()

request = params_update_one.build_delete_parameters_request()
await update_one_send_request(request)

@pytest.mark.asyncio
async def test_add_new_path(update_one_send_request):
with pytest.raises(AttributeError):
params_initial.build_get_new_operation_request()

request = params_update_one.build_get_new_operation_request()
response = await update_one_send_request(request)
assert response.content.decode('utf8') == json.dumps(
{'message': 'An object was successfully returned'},
separators=(',', ':')
)

@pytest.mark.asyncio
async def test_glass_breaker(update_one_send_request):
request = HttpRequest(method="GET", url="/servicedriven/glassbreaker", params=[], headers={"Accept": "application/json"})
response = await update_one_send_request(request)
assert response.status_code == 200
assert response.content.decode('utf8') == json.dumps({'message': 'An object was successfully returned'}, separators=(',', ':'))
55 changes: 55 additions & 0 deletions test/dpg/low-level/AcceptanceTests/test_service_driven.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#
# --------------------------------------------------------------------------
import pytest
import json
from azure.core.rest import HttpRequest

from dpgservicedriveninitiallowlevel import DPGClient as DPGClientInitial
from dpgservicedrivenupdateonelowlevel import DPGClient as DPGClientUpdateOne
Expand Down Expand Up @@ -62,3 +64,56 @@ def test_required_to_optional(initial_send_request, update_one_send_request):

request = params_update_one.build_get_required_request(parameter="foo", new_parameter="bar")
update_one_send_request(request)

def test_add_optional_parameter_to_none(initial_send_request, update_one_send_request):
request = params_initial.build_head_no_params_request()
initial_send_request(request)

request = params_update_one.build_head_no_params_request(new_parameter="bar")
update_one_send_request(request)

def test_add_optional_parameter_to_required_optional(initial_send_request, update_one_send_request):
request = params_initial.build_put_required_optional_request(required_param="foo", optional_param="bar")
initial_send_request(request)

request = params_update_one.build_put_required_optional_request(required_param="foo", optional_param="bar", new_parameter="baz")
update_one_send_request(request)

def test_add_optional_parameter_to_optional(initial_send_request, update_one_send_request):
request = params_initial.build_get_optional_request(optional_param="foo")
initial_send_request(request)

request = params_update_one.build_get_optional_request(optional_param="foo", new_parameter="bar")
update_one_send_request(request)

def test_add_new_content_type(initial_send_request, update_one_send_request):
request = params_initial.build_post_parameters_request(json={ "url": "http://example.org/myimage.jpeg" })
initial_send_request(request)

request = params_update_one.build_post_parameters_request(json={ "url": "http://example.org/myimage.jpeg" })
update_one_send_request(request)
request = params_update_one.build_post_parameters_request(content=b"hello", content_type="image/jpeg")
update_one_send_request(request)

def test_add_new_operation(update_one_send_request):
with pytest.raises(AttributeError):
params_initial.build_delete_parameters_request()

request = params_update_one.build_delete_parameters_request()
update_one_send_request(request)

def test_add_new_path(update_one_send_request):
with pytest.raises(AttributeError):
params_initial.build_get_new_operation_request()

request = params_update_one.build_get_new_operation_request()
assert update_one_send_request(request).content.decode('utf8') == json.dumps(
{'message': 'An object was successfully returned'},
separators=(',', ':')
)

def test_glass_breaker(update_one_send_request):
request = HttpRequest(method="GET", url="/servicedriven/glassbreaker", params=[], headers={"Accept": "application/json"})
response = update_one_send_request(request)
assert response.status_code == 200
assert response.content.decode('utf8') == json.dumps({'message': 'An object was successfully returned'}, separators=(',', ':'))
74 changes: 74 additions & 0 deletions test/dpg/low-level/AcceptanceTests/test_zzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# --------------------------------------------------------------------------
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the ""Software""), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import platform
import warnings
from azure.core.rest import HttpRequest

from dpgservicedriveninitiallowlevel import DPGClient


class TestAcceptance(object):

def test_ensure_coverage(self):
client = DPGClient()
request = HttpRequest("GET", "http://localhost:3000/report/dpg", params={"qualifier": platform.python_version()})
response = client.send_request(request)
response.raise_for_status()
support_dict = response.json()
# Add tests that wont be supported due to the nature of Python here
not_supported = {
}

# Please add missing features or failing tests here
missing_features_or_bugs = {
}
for name in support_dict:
if "DPG" not in name:
# this folder only does dpg
missing_features_or_bugs[name] = 1

print("Coverage:")
self._print_report(support_dict, not_supported, missing_features_or_bugs)

def _print_report(self, report, not_supported=None, missing_features_or_bugs=None):
if not_supported:
report.update(not_supported)
for s in not_supported.keys():
print("IGNORING {0}".format(s))

if missing_features_or_bugs:
report.update(missing_features_or_bugs)
for s in missing_features_or_bugs.keys():
print("PENDING {0}".format(s))

failed = [k for k, v in report.items() if v == 0]
for s in failed:
print("FAILED TO EXECUTE {0}".format(s))

total_tests = len(report)
warnings.warn ("The test coverage is {0}/{1}.".format(total_tests - len(failed), total_tests))

assert 0 == len(failed)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#
# --------------------------------------------------------------------------
import pytest
import json
from azure.core.rest import HttpRequest
from dpgservicedriveninitialversiontolerant.aio import DPGClient as DPGClientInitial
from dpgservicedrivenupdateoneversiontolerant.aio import DPGClient as DPGClientUpdateOne

Expand All @@ -39,7 +41,7 @@ async def update_one_client():
yield client

@pytest.mark.asyncio
async def test_add_optional_parameter(initial_client, update_one_client):
async def test_add_optional_parameter_to_required(initial_client, update_one_client):
await initial_client.params.get_required(
parameter="foo"
)
Expand All @@ -48,6 +50,47 @@ async def test_add_optional_parameter(initial_client, update_one_client):
new_parameter="bar",
)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_none(initial_client, update_one_client):
await initial_client.params.head_no_params()
await update_one_client.params.head_no_params()
await update_one_client.params.head_no_params(
new_parameter="bar"
)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_required_optional(initial_client, update_one_client):
await initial_client.params.put_required_optional(
required_param="foo",
optional_param="bar"
)
await update_one_client.params.put_required_optional(
required_param="foo",
optional_param="bar"
)
await update_one_client.params.put_required_optional(
required_param="foo",
optional_param="bar",
new_parameter="baz"
)
await update_one_client.params.put_required_optional(
required_param="foo",
new_parameter="baz"
)

@pytest.mark.asyncio
async def test_add_optional_parameter_to_optional(initial_client, update_one_client):
await initial_client.params.get_optional(
optional_param="foo"
)
await update_one_client.params.get_optional(
optional_param="foo"
)
await update_one_client.params.get_optional(
optional_param="foo",
new_parameter="bar"
)

@pytest.mark.asyncio
async def test_add_new_content_type(initial_client, update_one_client):
await initial_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" })
Expand All @@ -65,3 +108,10 @@ async def test_add_new_path(initial_client, update_one_client):
with pytest.raises(AttributeError):
await initial_client.params.get_new_operation()
assert await update_one_client.params.get_new_operation() == {'message': 'An object was successfully returned'}

@pytest.mark.asyncio
async def test_glass_breaker(update_one_client):
request = HttpRequest(method="GET", url="/servicedriven/glassbreaker", params=[], headers={"Accept": "application/json"})
response = await update_one_client.send_request(request)
assert response.status_code == 200
assert response.content.decode('utf8') == json.dumps({'message': 'An object was successfully returned'}, separators=(',', ':'))
51 changes: 50 additions & 1 deletion test/dpg/version-tolerant/AcceptanceTests/test_service_driven.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#
# --------------------------------------------------------------------------
import pytest
import json
from azure.core.rest import HttpRequest
from dpgservicedriveninitialversiontolerant import DPGClient as DPGClientInitial
from dpgservicedrivenupdateoneversiontolerant import DPGClient as DPGClientUpdateOne

Expand All @@ -38,15 +40,56 @@ def update_one_client():
with DPGClientUpdateOne() as client:
yield client

def test_add_optional_parameter(initial_client, update_one_client):
def test_add_optional_parameter_to_required(initial_client, update_one_client):
initial_client.params.get_required(
parameter="foo"
)
update_one_client.params.get_required(
parameter="foo"
)
update_one_client.params.get_required(
parameter="foo",
new_parameter="bar",
)

def test_add_optional_parameter_to_none(initial_client, update_one_client):
initial_client.params.head_no_params()
update_one_client.params.head_no_params()
update_one_client.params.head_no_params(
new_parameter="bar"
)

def test_add_optional_parameter_to_required_optional(initial_client, update_one_client):
initial_client.params.put_required_optional(
required_param="foo",
optional_param="bar"
)
update_one_client.params.put_required_optional(
required_param="foo",
optional_param="bar"
)
update_one_client.params.put_required_optional(
required_param="foo",
optional_param="bar",
new_parameter="baz"
)
update_one_client.params.put_required_optional(
required_param="foo",
new_parameter="baz"
)

def test_add_optional_parameter_to_optional(initial_client, update_one_client):
initial_client.params.get_optional(
optional_param="foo"
)
update_one_client.params.get_optional(
optional_param="foo"
)
update_one_client.params.get_optional(
optional_param="foo",
new_parameter="bar"
)

def test_add_new_content_type(initial_client, update_one_client):
initial_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" })
update_one_client.params.post_parameters({ "url": "http://example.org/myimage.jpeg" })
Expand All @@ -61,3 +104,9 @@ def test_add_new_path(initial_client, update_one_client):
with pytest.raises(AttributeError):
initial_client.params.get_new_operation()
assert update_one_client.params.get_new_operation() == {'message': 'An object was successfully returned'}

def test_glass_breaker(update_one_client):
request = HttpRequest(method="GET", url="/servicedriven/glassbreaker", params=[], headers={"Accept": "application/json"})
response = update_one_client.send_request(request)
assert response.status_code == 200
assert response.content.decode('utf8') == json.dumps({'message': 'An object was successfully returned'}, separators=(',', ':'))
6 changes: 0 additions & 6 deletions test/dpg/version-tolerant/AcceptanceTests/test_zzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from dpgservicedriveninitialversiontolerant import DPGClient




class TestAcceptance(object):

def test_ensure_coverage(self):
Expand All @@ -46,10 +44,6 @@ def test_ensure_coverage(self):

# Please add missing features or failing tests here
missing_features_or_bugs = {
'DPGAddOptionalInput_NoParams': 1,
'DPGAddOptionalInput_RequiredOptionalParam': 1,
'DPGAddOptionalInput_OptionalParam': 1,
'DPGGlassBreaker': 1,
}
for name in support_dict:
if "DPG" not in name:
Expand Down
Loading

0 comments on commit d365fdc

Please sign in to comment.