Skip to content
Merged
Changes from all commits
Commits
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
48 changes: 34 additions & 14 deletions examples/manual_test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Intended as a simple end-to-end test for assurance when making changes, where there are
gaps in test suite coverage.

Doesn't yet use `get_person(user)` or any `send_`, `update_` methods."""
Doesn't yet use `get_person(user)` or any `send_`, `update_` methods.
"""

import asyncio
import tempfile
Expand All @@ -19,39 +20,44 @@


async def main() -> None:

# SPOND
s = spond.Spond(username=username, password=password)

# GROUPS
# Profile
print("\nGetting profile...")
profile = await s.get_profile()
print(_profile_summary(profile))

# Groups
print("\nGetting all groups...")
groups = await s.get_groups()
print(f"{len(groups)} groups:")
for i, group in enumerate(groups):
print(f"[{i}] {_group_summary(group)}")

# EVENTS

# Events
print(f"\nGetting up to {MAX_EVENTS} events...")
events = await s.get_events(max_events=MAX_EVENTS)
print(f"{len(events)} events:")
for i, event in enumerate(events):
print(f"[{i}] {_event_summary(event)}")

# CHATS (MESSAGES)

# Chats (messages)
print(f"\nGetting up to {MAX_CHATS} chats...")
chats = await s.get_messages(max_chats=MAX_CHATS)
print(f"{len(chats)} chats:")
for i, chat in enumerate(chats):
print(f"[{i}] {_chat_summary(chat)}")

# ATTENDANCE EXPORT

# Attendance export
print("\nGetting attendance report for the first event...")
e = events[0]
data = await s.get_event_attendance_xlsx(e["id"])
with tempfile.NamedTemporaryFile(
mode="wb", suffix=".xlsx", delete=False
mode="wb",
suffix=".xlsx",
delete=False,
) as temp_file:
temp_file.write(data)
print(f"Check out {temp_file.name}")
Expand All @@ -61,15 +67,27 @@ async def main() -> None:
# SPOND CLUB
sc = club.SpondClub(username=username, password=password)
print(f"\nGetting up to {MAX_TRANSACTIONS} transactions...")

# Transactions
transactions = await sc.get_transactions(
club_id=club_id, max_items=MAX_TRANSACTIONS
club_id=club_id,
max_items=MAX_TRANSACTIONS,
)
print(f"{len(transactions)} transactions:")
for i, t in enumerate(transactions):
print(f"[{i}] {_transaction_summary(t)}")

await sc.clientsession.close()


def _profile_summary(profile: JSONDict) -> str:
return (
f"id='{profile['id']}', "
f"firstName='{profile['firstName']}, "
f"lastName='{profile['lastName']}'"
)


def _group_summary(group: JSONDict) -> str:
return f"id='{group['id']}', name='{group['name']}'"

Expand Down Expand Up @@ -100,14 +118,16 @@ def _transaction_summary(transaction: JSONDict) -> str:
)


def _abbreviate(text, length) -> str:
def _abbreviate(text: str, length: int) -> str:
"""Abbreviate long text, normalising line endings to escape characters."""
escaped_text = repr(text)
if len(text) > length:
return f"{escaped_text[:length]}[…]"

return escaped_text


loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())
Loading