2021-12-15 08:33:25 -08:00
|
|
|
import os
|
2023-08-30 15:59:51 -07:00
|
|
|
from typing import Dict, Optional, Union
|
2023-05-04 00:58:06 -07:00
|
|
|
|
2021-12-15 06:49:45 -08:00
|
|
|
import pytest
|
|
|
|
|
2023-01-27 16:22:14 -08:00
|
|
|
from .api.api_tokens import list_api_tokens_for_user
|
2023-08-30 15:59:51 -07:00
|
|
|
from .api.file import create_file_conversion, create_file_mass, create_file_volume
|
2023-05-04 00:58:06 -07:00
|
|
|
from .api.meta import ping
|
|
|
|
from .api.users import get_user_self, list_users_extended
|
|
|
|
from .client import ClientFromEnv
|
|
|
|
from .models import (
|
|
|
|
ApiCallStatus,
|
|
|
|
ApiTokenResultsPage,
|
2023-08-30 15:59:51 -07:00
|
|
|
Base64Data,
|
2023-05-04 00:58:06 -07:00
|
|
|
CreatedAtSortMode,
|
2023-05-08 12:58:35 -07:00
|
|
|
Error,
|
2023-05-04 00:58:06 -07:00
|
|
|
ExtendedUserResultsPage,
|
|
|
|
FileConversion,
|
|
|
|
FileExportFormat,
|
|
|
|
FileImportFormat,
|
|
|
|
FileMass,
|
|
|
|
FileVolume,
|
|
|
|
Pong,
|
2023-07-31 12:50:30 -07:00
|
|
|
UnitDensity,
|
|
|
|
UnitMass,
|
|
|
|
UnitVolume,
|
2023-05-04 00:58:06 -07:00
|
|
|
User,
|
|
|
|
)
|
2023-08-30 15:59:51 -07:00
|
|
|
from .types import Unset
|
2021-12-15 06:42:39 -08:00
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2021-12-15 06:42:39 -08:00
|
|
|
def test_get_session():
|
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 06:42:39 -08:00
|
|
|
|
|
|
|
# Get the session.
|
2023-05-08 12:58:35 -07:00
|
|
|
session: Union[User, Error, None] = get_user_self.sync(client=client)
|
2021-12-15 06:42:39 -08:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(session, User)
|
2021-12-15 06:56:56 -08:00
|
|
|
|
2021-12-15 06:42:39 -08:00
|
|
|
print(f"Session: {session}")
|
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2023-01-27 16:22:14 -08:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_get_api_tokens_async():
|
|
|
|
# Create our client.
|
|
|
|
client = ClientFromEnv()
|
|
|
|
|
|
|
|
# List API tokens.
|
2023-05-08 12:58:35 -07:00
|
|
|
fc: Union[ApiTokenResultsPage, Error, None] = list_api_tokens_for_user.sync(
|
|
|
|
client=client, sort_by=CreatedAtSortMode.CREATED_AT_ASCENDING
|
2023-05-04 00:58:06 -07:00
|
|
|
)
|
2023-01-27 16:22:14 -08:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(fc, ApiTokenResultsPage)
|
2023-01-27 16:22:14 -08:00
|
|
|
|
|
|
|
print(f"fc: {fc}")
|
|
|
|
|
|
|
|
|
2021-12-15 06:49:45 -08:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_get_session_async():
|
2021-12-15 06:42:39 -08:00
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 06:42:39 -08:00
|
|
|
|
|
|
|
# Get the session.
|
2023-05-08 12:58:35 -07:00
|
|
|
session: Union[User, Error, None] = await get_user_self.asyncio(client=client)
|
2021-12-15 06:56:56 -08:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(session, User)
|
2021-12-15 06:42:39 -08:00
|
|
|
|
|
|
|
print(f"Session: {session}")
|
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2021-12-15 06:58:54 -08:00
|
|
|
def test_ping():
|
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 06:58:54 -08:00
|
|
|
|
|
|
|
# Get the message.
|
2023-05-08 12:58:35 -07:00
|
|
|
message: Union[Pong, Error, None] = ping.sync(client=client)
|
2021-12-15 06:58:54 -08:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(message, Pong)
|
2021-12-15 06:58:54 -08:00
|
|
|
|
|
|
|
print(f"Message: {message}")
|
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2021-12-15 06:58:54 -08:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_ping_async():
|
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 06:58:54 -08:00
|
|
|
|
|
|
|
# Get the message.
|
2023-05-08 12:58:35 -07:00
|
|
|
message: Union[Pong, Error, None] = await ping.asyncio(client=client)
|
2021-12-15 06:58:54 -08:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(message, Pong)
|
2021-12-15 06:58:54 -08:00
|
|
|
|
|
|
|
print(f"Message: {message}")
|
2021-12-15 08:33:25 -08:00
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2021-12-15 08:33:25 -08:00
|
|
|
def test_file_convert_stl():
|
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 08:33:25 -08:00
|
|
|
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
file = open(os.path.join(dir_path, "../assets/testing.stl"), "rb")
|
|
|
|
content = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Get the fc.
|
2023-08-30 15:59:51 -07:00
|
|
|
result: Optional[Union[FileConversion, Error]] = create_file_conversion.sync(
|
2022-02-27 21:48:39 -08:00
|
|
|
client=client,
|
2022-02-27 22:30:43 -08:00
|
|
|
body=content,
|
2022-10-03 12:00:18 -07:00
|
|
|
src_format=FileImportFormat.STL,
|
2023-05-04 00:58:06 -07:00
|
|
|
output_format=FileExportFormat.OBJ,
|
|
|
|
)
|
2021-12-15 08:33:25 -08:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert isinstance(result, FileConversion)
|
2023-05-08 12:58:35 -07:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
fc: FileConversion = result
|
2021-12-15 08:33:25 -08:00
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
|
|
|
|
2022-03-06 17:46:14 -08:00
|
|
|
assert fc.id is not None
|
2022-07-05 15:38:49 -07:00
|
|
|
assert fc.status == ApiCallStatus.COMPLETED
|
2022-03-06 17:46:14 -08:00
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert not isinstance(fc.outputs, Unset)
|
|
|
|
|
|
|
|
outputs: Dict[str, Base64Data] = fc.outputs
|
2023-08-17 12:48:13 -07:00
|
|
|
# Make sure the bytes are not empty.
|
2023-08-30 15:59:51 -07:00
|
|
|
for key, value in outputs.items():
|
|
|
|
assert len(value.get_decoded()) > 0
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2022-02-27 21:48:39 -08:00
|
|
|
|
2021-12-15 08:33:25 -08:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_file_convert_stl_async():
|
|
|
|
# Create our client.
|
2022-02-27 18:39:04 -08:00
|
|
|
client = ClientFromEnv()
|
2021-12-15 08:33:25 -08:00
|
|
|
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
file = open(os.path.join(dir_path, "../assets/testing.stl"), "rb")
|
|
|
|
content = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Get the fc.
|
2023-08-30 15:59:51 -07:00
|
|
|
result: Optional[
|
|
|
|
Union[FileConversion, Error]
|
|
|
|
] = await create_file_conversion.asyncio(
|
2023-05-04 00:58:06 -07:00
|
|
|
client=client,
|
|
|
|
body=content,
|
|
|
|
src_format=FileImportFormat.STL,
|
|
|
|
output_format=FileExportFormat.OBJ,
|
|
|
|
)
|
2021-12-15 08:33:25 -08:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert isinstance(result, FileConversion)
|
2023-05-08 12:58:35 -07:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
fc: FileConversion = result
|
2021-12-15 08:33:25 -08:00
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
2022-03-06 17:46:14 -08:00
|
|
|
|
|
|
|
assert fc.id is not None
|
2023-08-17 14:13:56 -07:00
|
|
|
assert fc.status == ApiCallStatus.COMPLETED
|
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert not isinstance(fc.outputs, Unset)
|
|
|
|
|
|
|
|
outputs: Dict[str, Base64Data] = fc.outputs
|
2023-08-17 14:13:56 -07:00
|
|
|
# Make sure the bytes are not empty.
|
2023-08-30 15:59:51 -07:00
|
|
|
for key, value in outputs.items():
|
|
|
|
assert len(value.get_decoded()) > 0
|
2023-08-17 14:13:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_file_convert_obj_async():
|
|
|
|
# Create our client.
|
|
|
|
client = ClientFromEnv()
|
|
|
|
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
file = open(os.path.join(dir_path, "../assets/ORIGINALVOXEL-3.obj"), "rb")
|
|
|
|
content = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Get the fc.
|
2023-08-30 15:59:51 -07:00
|
|
|
result: Optional[
|
|
|
|
Union[FileConversion, Error]
|
|
|
|
] = await create_file_conversion.asyncio(
|
2023-08-17 14:13:56 -07:00
|
|
|
client=client,
|
|
|
|
body=content,
|
|
|
|
src_format=FileImportFormat.OBJ,
|
|
|
|
output_format=FileExportFormat.STL,
|
|
|
|
)
|
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert isinstance(result, FileConversion)
|
2023-08-17 14:13:56 -07:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
fc: FileConversion = result
|
2023-08-17 14:13:56 -07:00
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
|
|
|
|
|
|
|
assert fc.id is not None
|
2023-08-17 12:48:13 -07:00
|
|
|
assert fc.status == ApiCallStatus.COMPLETED
|
2022-03-06 17:46:14 -08:00
|
|
|
|
|
|
|
print(f"FileConversion: {fc}")
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2023-08-30 15:59:51 -07:00
|
|
|
assert not isinstance(fc.outputs, Unset)
|
|
|
|
|
|
|
|
outputs: Dict[str, Base64Data] = fc.outputs
|
2023-08-17 12:48:13 -07:00
|
|
|
# Make sure the bytes are not empty.
|
2023-08-30 15:59:51 -07:00
|
|
|
for key, value in outputs.items():
|
|
|
|
assert len(value.get_decoded()) > 0
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2022-06-14 11:38:28 +00:00
|
|
|
|
2022-06-14 21:35:20 +10:00
|
|
|
def test_file_mass():
|
|
|
|
# Create our client.
|
|
|
|
client = ClientFromEnv()
|
|
|
|
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
2022-06-14 21:57:15 +10:00
|
|
|
file = open(os.path.join(dir_path, "../assets/testing.obj"), "rb")
|
2022-06-14 21:35:20 +10:00
|
|
|
content = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Get the fc.
|
2023-05-08 12:58:35 -07:00
|
|
|
result: Union[FileMass, Error, None] = create_file_mass.sync(
|
2022-06-14 21:35:20 +10:00
|
|
|
client=client,
|
|
|
|
body=content,
|
2022-10-03 12:00:18 -07:00
|
|
|
src_format=FileImportFormat.OBJ,
|
2023-05-04 00:58:06 -07:00
|
|
|
material_density=1.0,
|
2023-07-31 12:50:30 -07:00
|
|
|
material_density_unit=UnitDensity.KG_M3,
|
|
|
|
output_unit=UnitMass.G,
|
2023-05-04 00:58:06 -07:00
|
|
|
)
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(result, FileMass)
|
|
|
|
|
|
|
|
fm: FileMass = result
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2022-06-14 21:52:17 +10:00
|
|
|
print(f"FileMass: {fm}")
|
2022-06-14 21:35:20 +10:00
|
|
|
|
|
|
|
assert fm.id is not None
|
|
|
|
assert fm.mass is not None
|
|
|
|
|
2022-06-15 10:01:21 +10:00
|
|
|
assert fm.to_dict() is not None
|
|
|
|
|
2022-07-05 15:38:49 -07:00
|
|
|
assert fm.status == ApiCallStatus.COMPLETED
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2022-06-14 11:38:28 +00:00
|
|
|
|
2022-06-14 21:35:20 +10:00
|
|
|
def test_file_volume():
|
|
|
|
# Create our client.
|
|
|
|
client = ClientFromEnv()
|
|
|
|
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
2022-06-14 21:57:15 +10:00
|
|
|
file = open(os.path.join(dir_path, "../assets/testing.obj"), "rb")
|
2022-06-14 21:35:20 +10:00
|
|
|
content = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Get the fc.
|
2023-05-08 12:58:35 -07:00
|
|
|
result: Union[FileVolume, Error, None] = create_file_volume.sync(
|
2023-07-31 12:50:30 -07:00
|
|
|
client=client,
|
|
|
|
body=content,
|
|
|
|
src_format=FileImportFormat.OBJ,
|
|
|
|
output_unit=UnitVolume.CM3,
|
2023-05-04 00:58:06 -07:00
|
|
|
)
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(result, FileVolume)
|
|
|
|
|
|
|
|
fv: FileVolume = result
|
2022-06-14 21:35:20 +10:00
|
|
|
|
2022-06-14 21:52:17 +10:00
|
|
|
print(f"FileVolume: {fv}")
|
2022-06-14 21:35:20 +10:00
|
|
|
|
|
|
|
assert fv.id is not None
|
|
|
|
assert fv.volume is not None
|
|
|
|
|
2022-06-15 10:01:21 +10:00
|
|
|
assert fv.to_dict() is not None
|
|
|
|
|
2022-07-05 15:38:49 -07:00
|
|
|
assert fv.status == ApiCallStatus.COMPLETED
|
2023-05-04 00:58:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_users():
|
|
|
|
# Create our client.
|
|
|
|
client = ClientFromEnv()
|
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
response: Union[ExtendedUserResultsPage, Error, None] = list_users_extended.sync(
|
2023-05-04 00:58:06 -07:00
|
|
|
sort_by=CreatedAtSortMode.CREATED_AT_DESCENDING, client=client, limit=10
|
|
|
|
)
|
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
assert isinstance(response, ExtendedUserResultsPage)
|
2023-05-04 00:58:06 -07:00
|
|
|
|
2023-05-08 12:58:35 -07:00
|
|
|
print(f"ExtendedUserResultsPage: {response}")
|