or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

Notification Parser

Build a notification parser that can deserialize notification data from JSON into Python objects, where notifications can be of different types (email, SMS, or push notifications).

Requirements

Your implementation should:

  1. Define three notification classes:

    • EmailNotification with fields: recipient (str), subject (str), body (str)
    • SMSNotification with fields: phone_number (str), message (str)
    • PushNotification with fields: device_id (str), title (str), message (str), badge_count (optional int)
  2. Implement a parse_notification(data: dict) -> Union[EmailNotification, SMSNotification, PushNotification] function that:

    • Takes a dictionary representing notification data
    • Returns the appropriate notification object based on the data structure
    • Handles cases where the input could match any of the three notification types
  3. Implement a parse_notification_batch(data: list) -> list function that:

    • Takes a list of dictionaries, each representing a notification
    • Returns a list of notification objects (mixed types)
    • Each item in the list could be any of the three notification types
  4. Handle optional fields gracefully (like badge_count in push notifications)

@generates

API

from typing import Union, Optional
from dataclasses import dataclass

@dataclass
class EmailNotification:
    recipient: str
    subject: str
    body: str

@dataclass
class SMSNotification:
    phone_number: str
    message: str

@dataclass
class PushNotification:
    device_id: str
    title: str
    message: str
    badge_count: Optional[int] = None

def parse_notification(data: dict) -> Union[EmailNotification, SMSNotification, PushNotification]:
    """Parse a single notification from dictionary data."""
    pass

def parse_notification_batch(data: list) -> list:
    """Parse a batch of notifications from list of dictionaries."""
    pass

Test Cases

  • Parsing an email notification with all required fields returns an EmailNotification object @test
  • Parsing an SMS notification with all required fields returns an SMSNotification object @test
  • Parsing a push notification with badge_count returns a PushNotification with the badge_count set @test
  • Parsing a push notification without badge_count returns a PushNotification with badge_count as None @test
  • Parsing a batch of mixed notification types returns a list containing the correct notification objects @test

Dependencies { .dependencies }

jsons { .dependency }

Provides JSON serialization and deserialization support with type handling.