Skip to content

Commit

Permalink
Cleanup tests (#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored May 2, 2024
1 parent 081bdb2 commit 03910c8
Show file tree
Hide file tree
Showing 69 changed files with 3,185 additions and 2,289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def _build_client(client_type):
if client:
await client.close()


@pytest.fixture()
def token_credential(core_library):
class FakeCredential:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ async def test_language(client: NamingClient):

@pytest.mark.asyncio
async def test_compatible_with_encoded_name(client: NamingClient):
await client.compatible_with_encoded_name(
models.ClientNameAndJsonEncodedNameModel(client_name=True)
)
await client.compatible_with_encoded_name(models.ClientNameAndJsonEncodedNameModel(client_name=True))


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from client.structure.renamedoperation.aio import RenamedOperationClient
from client.structure.twooperationgroup.aio import TwoOperationGroupClient


@pytest.mark.asyncio
async def test_structure_default():
client = ServiceClient(endpoint="http://localhost:3000", client=ClientType.DEFAULT)
Expand All @@ -23,6 +24,7 @@ async def test_structure_default():
await client.qux.eight()
await client.qux.bar.nine()


@pytest.mark.asyncio
async def test_structure_multiclient():
client_a = ClientAClient(endpoint="http://localhost:3000", client=ClientType.MULTI_CLIENT)
Expand All @@ -35,6 +37,7 @@ async def test_structure_multiclient():
await client_b.renamed_four()
await client_b.renamed_six()


@pytest.mark.asyncio
async def test_structure_renamed_operation():
client = RenamedOperationClient(endpoint="http://localhost:3000", client=ClientType.RENAMED_OPERATION)
Expand All @@ -46,6 +49,7 @@ async def test_structure_renamed_operation():
await client.group.renamed_four()
await client.group.renamed_six()


@pytest.mark.asyncio
async def test_structure_two_operation_group():
client = TwoOperationGroupClient(endpoint="http://localhost:3000", client=ClientType.RENAMED_OPERATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

FILE_FOLDER = Path(__file__).parent.parent


@pytest.fixture
async def client():
async with BytesClient() as client:
Expand Down Expand Up @@ -105,11 +106,22 @@ def png_data() -> bytes:

@pytest.mark.asyncio
async def test_request_body(client: BytesClient, png_data: bytes):
await client.request_body.default(value=bytes("test", "utf-8"), )
await client.request_body.octet_stream(value=png_data, )
await client.request_body.custom_content_type(value=png_data, )
await client.request_body.base64(value=bytes("test", "utf-8"), )
await client.request_body.base64url(value=bytes("test", "utf-8"), )
await client.request_body.default(
value=bytes("test", "utf-8"),
)
await client.request_body.octet_stream(
value=png_data,
)
await client.request_body.custom_content_type(
value=png_data,
)
await client.request_body.base64(
value=bytes("test", "utf-8"),
)
await client.request_body.base64url(
value=bytes("test", "utf-8"),
)


@pytest.mark.asyncio
async def test_response_body(client: BytesClient, png_data: bytes):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,36 @@ async def test_query(client: DatetimeClient):
async def test_property(client: DatetimeClient):
result = await client.property.default(
DefaultDatetimeProperty(
value=datetime.datetime(
2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc
),
value=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
)
)
assert result.value == datetime.datetime(
2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc
)
assert result.value == datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc)

result = await client.property.rfc3339(
Rfc3339DatetimeProperty(
value=datetime.datetime(
2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc
),
value=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
)
)
assert result.value == datetime.datetime(
2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc
)
assert result.value == datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc)

result = await client.property.rfc7231(
Rfc7231DatetimeProperty(
value=datetime.datetime(
2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc
),
value=datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc),
)
)
assert result.value == datetime.datetime(
2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc
)
assert result.value == datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc)

result = await client.property.unix_timestamp(
UnixTimestampDatetimeProperty(
value=datetime.datetime(
2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc
),
value=datetime.datetime(2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc),
)
)
assert result.value == datetime.datetime(
2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc
)
assert result.value == datetime.datetime(2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc)

result = await client.property.unix_timestamp_array(
UnixTimestampArrayDatetimeProperty(
value=[
datetime.datetime(
2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc
),
datetime.datetime(2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc),
datetime.datetime(2023, 6, 14, 9, 17, 36, tzinfo=datetime.timezone.utc),
],
)
Expand Down Expand Up @@ -131,7 +113,15 @@ async def test_header(client: DatetimeClient):
@pytest.mark.asyncio
async def test_response_header(client: DatetimeClient):
cls = lambda x, y, z: z
assert (await client.response_header.default(cls=cls))["value"] == datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc)
assert (await client.response_header.rfc3339(cls=cls))["value"] == datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc)
assert (await client.response_header.rfc7231(cls=cls))["value"] == datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc)
assert (await client.response_header.unix_timestamp(cls=cls))["value"] == datetime.datetime(2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc)
assert (await client.response_header.default(cls=cls))["value"] == datetime.datetime(
2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc
)
assert (await client.response_header.rfc3339(cls=cls))["value"] == datetime.datetime(
2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc
)
assert (await client.response_header.rfc7231(cls=cls))["value"] == datetime.datetime(
2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc
)
assert (await client.response_header.unix_timestamp(cls=cls))["value"] == datetime.datetime(
2023, 6, 12, 10, 47, 44, tzinfo=datetime.timezone.utc
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,19 @@ async def test_query(client: DurationClient):

@pytest.mark.asyncio
async def test_property(client: DurationClient):
result = await client.property.default(
DefaultDurationProperty(value=datetime.timedelta(days=40))
)
result = await client.property.default(DefaultDurationProperty(value=datetime.timedelta(days=40)))
assert result.value == datetime.timedelta(days=40)
result = await client.property.default(DefaultDurationProperty(value="P40D"))
assert result.value == datetime.timedelta(days=40)
result = await client.property.iso8601(
ISO8601DurationProperty(value=datetime.timedelta(days=40))
)
result = await client.property.iso8601(ISO8601DurationProperty(value=datetime.timedelta(days=40)))
assert result.value == datetime.timedelta(days=40)
result = await client.property.iso8601(ISO8601DurationProperty(value="P40D"))
assert result.value == datetime.timedelta(days=40)
result = await client.property.int32_seconds(Int32SecondsDurationProperty(value=36))
assert result.value == 36
result = await client.property.float_seconds(
FloatSecondsDurationProperty(value=35.621)
)
result = await client.property.float_seconds(FloatSecondsDurationProperty(value=35.621))
assert abs(result.value - 35.621) < 0.0001
result = await client.property.float_seconds_array(
FloatSecondsDurationArrayProperty(value=[35.621, 46.781])
)
result = await client.property.float_seconds_array(FloatSecondsDurationArrayProperty(value=[35.621, 46.781]))
assert abs(result.value[0] - 35.621) < 0.0001
assert abs(result.value[1] - 46.781) < 0.0001

Expand All @@ -62,8 +54,6 @@ async def test_property(client: DurationClient):
async def test_header(client: DurationClient):
await client.header.default(duration=datetime.timedelta(days=40))
await client.header.iso8601(duration=datetime.timedelta(days=40))
await client.header.iso8601_array(
duration=[datetime.timedelta(days=40), datetime.timedelta(days=50)]
)
await client.header.iso8601_array(duration=[datetime.timedelta(days=40), datetime.timedelta(days=50)])
await client.header.int32_seconds(duration=36)
await client.header.float_seconds(duration=35.621)
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
from headasbooleanfalse.aio import VisibilityClient as HeadAsBooleanFalseClient
from headasbooleanfalse import models as models_false


@pytest.fixture
async def client_true():
async with HeadAsBooleanTrueClient() as client:
yield client


@pytest.fixture
async def client_false():
async with HeadAsBooleanFalseClient() as client:
yield client


@pytest.mark.asyncio
async def test_head_true(client_true):
body = models_true.VisibilityModel(query_prop=123)
assert await client_true.head_model(body) == True


@pytest.mark.asyncio
async def test_head_false(client_false):
body = models_false.VisibilityModel(query_prop=123)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ async def test_alias_body(client: SpreadClient):

@pytest.mark.asyncio
async def test_alias_parameter(client: SpreadClient):
await client.alias.spread_as_request_parameter(
"1", x_ms_test_header="bar", name="foo"
)
await client.alias.spread_as_request_parameter("1", x_ms_test_header="bar", name="foo")


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@
from payload.contentnegotiation.aio import ContentNegotiationClient
from payload.contentnegotiation.models import PngImageAsJson


@pytest.fixture
async def client():
async with ContentNegotiationClient(endpoint="http://localhost:3000") as client:
yield client


@pytest.mark.asyncio
async def test_get_avatar_as_png(client: ContentNegotiationClient, png_data: bytes):
assert b"".join([d async for d in (await client.same_body.get_avatar_as_png())]) == png_data


@pytest.mark.asyncio
async def test_get_avatar_as_jpeg(client: ContentNegotiationClient, jpg_data: bytes):
assert b"".join([d async for d in (await client.same_body.get_avatar_as_jpeg())]) == jpg_data


@pytest.mark.asyncio
async def test_different_body_get_avatar_as_png(client: ContentNegotiationClient, png_data: bytes):
assert b"".join([d async for d in (await client.different_body.get_avatar_as_png())]) == png_data


@pytest.mark.asyncio
async def test_different_body_get_avatar_as_json(client: ContentNegotiationClient, png_data: bytes):
result = await client.different_body.get_avatar_as_json()
Expand Down
Loading

0 comments on commit 03910c8

Please sign in to comment.