-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Simulator API Support #74
Open
davidgrayston-paddle
wants to merge
13
commits into
main
Choose a base branch
from
feat/simulator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
30f8cdb
feat: Add simulator support
davidgrayston-paddle 2df3478
test: Add test coverage for simulation runs
davidgrayston-paddle f82869c
test: Add coverage for simulation events
davidgrayston-paddle 1920ebe
test: Add coverage for simulation entity payloads
davidgrayston-paddle 4e344e4
fix: Only convert JSON properties to snake case when necessary
davidgrayston-paddle 2eb4b81
docs: Update deprecation comments
davidgrayston-paddle 0bb4ea3
docs: Update changelog
davidgrayston-paddle efcb6c1
feat: Introduce simulation payload entity type with optional properties
davidgrayston-paddle bba8edf
test: Add coverage for partial simulation payloads
davidgrayston-paddle 0ccff21
test: Assert event type is resolved to correct entity
davidgrayston-paddle 4130df3
feat: Add simulation types client
davidgrayston-paddle 718f68e
docs: Update changelog
davidgrayston-paddle b87e24c
fix: Add type to simulation adjustment payload
davidgrayston-paddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
paddle_billing/Entities/Collections/SimulationCollection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from paddle_billing.Entities.Collections.Collection import Collection | ||
from paddle_billing.Entities.Collections.Paginator import Paginator | ||
from paddle_billing.Entities.Simulation import Simulation | ||
|
||
|
||
class SimulationCollection(Collection[Simulation]): | ||
@classmethod | ||
def from_list(cls, items_data: list, paginator: Paginator | None = None) -> SimulationCollection: | ||
items: list[Simulation] = [Simulation.from_dict(item) for item in items_data] | ||
|
||
return SimulationCollection(items, paginator) |
13 changes: 13 additions & 0 deletions
13
paddle_billing/Entities/Collections/SimulationRunCollection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from paddle_billing.Entities.Collections.Collection import Collection | ||
from paddle_billing.Entities.Collections.Paginator import Paginator | ||
from paddle_billing.Entities.SimulationRun import SimulationRun | ||
|
||
|
||
class SimulationRunCollection(Collection[SimulationRun]): | ||
@classmethod | ||
def from_list(cls, items_data: list, paginator: Paginator | None = None) -> SimulationRunCollection: | ||
items: list[SimulationRun] = [SimulationRun.from_dict(item) for item in items_data] | ||
|
||
return SimulationRunCollection(items, paginator) |
13 changes: 13 additions & 0 deletions
13
paddle_billing/Entities/Collections/SimulationRunEventCollection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from paddle_billing.Entities.Collections.Collection import Collection | ||
from paddle_billing.Entities.Collections.Paginator import Paginator | ||
from paddle_billing.Entities.SimulationRunEvent import SimulationRunEvent | ||
|
||
|
||
class SimulationRunEventCollection(Collection[SimulationRunEvent]): | ||
@classmethod | ||
def from_list(cls, items_data: list, paginator: Paginator | None = None) -> SimulationRunEventCollection: | ||
items: list[SimulationRunEvent] = [SimulationRunEvent.from_dict(item) for item in items_data] | ||
|
||
return SimulationRunEventCollection(items, paginator) |
13 changes: 13 additions & 0 deletions
13
paddle_billing/Entities/Collections/SimulationTypeCollection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from paddle_billing.Entities.Collections.Collection import Collection | ||
from paddle_billing.Entities.Collections.Paginator import Paginator | ||
from paddle_billing.Entities.SimulationType import SimulationType | ||
|
||
|
||
class SimulationTypeCollection(Collection[SimulationType]): | ||
@classmethod | ||
def from_list(cls, items_data: list, paginator: Paginator | None = None) -> SimulationTypeCollection: | ||
items: list[SimulationType] = [SimulationType.from_dict(item) for item in items_data] | ||
|
||
return SimulationTypeCollection(items, paginator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
from paddle_billing.Entities.Events import EventTypeName | ||
from paddle_billing.Entities.Simulations import SimulationScenarioType, SimulationStatus | ||
|
||
from paddle_billing.Notifications.Entities.Simulations.SimulationEntity import SimulationEntity | ||
from paddle_billing.Notifications.Entities.UndefinedEntity import UndefinedEntity | ||
|
||
|
||
@dataclass | ||
class Simulation(Entity, ABC): | ||
id: str | ||
status: SimulationStatus | ||
notification_setting_id: str | ||
name: str | ||
type: EventTypeName | SimulationScenarioType | ||
payload: SimulationEntity | UndefinedEntity | None | ||
last_run_at: datetime | None | ||
created_at: datetime | ||
updated_at: datetime | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> Simulation: | ||
type = EventTypeName(data["type"]) | ||
if not type.is_known(): | ||
type = SimulationScenarioType(data["type"]) | ||
|
||
return Simulation( | ||
id=data["id"], | ||
status=SimulationStatus(data["status"]), | ||
notification_setting_id=data["notification_setting_id"], | ||
name=data["name"], | ||
type=type, | ||
payload=( | ||
SimulationEntity.from_dict_for_event_type(data["payload"], type.value) | ||
if isinstance(type, EventTypeName) and data.get("payload") | ||
else None | ||
), | ||
last_run_at=datetime.fromisoformat(data["last_run_at"]) if data.get("last_run_at") else None, | ||
created_at=datetime.fromisoformat(data["created_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
from paddle_billing.Entities.Events import EventTypeName | ||
from paddle_billing.Entities.Simulations import SimulationScenarioType | ||
from paddle_billing.Entities.SimulationRuns import SimulationRunStatus | ||
from paddle_billing.Entities.SimulationRunEvent import SimulationRunEvent | ||
|
||
|
||
@dataclass | ||
class SimulationRun(Entity, ABC): | ||
id: str | ||
status: SimulationRunStatus | ||
type: EventTypeName | SimulationScenarioType | ||
created_at: datetime | ||
updated_at: datetime | ||
events: list[SimulationRunEvent] | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> SimulationRun: | ||
type = EventTypeName(data["type"]) | ||
if not type.is_known(): | ||
type = SimulationScenarioType(data["type"]) | ||
|
||
return SimulationRun( | ||
id=data["id"], | ||
status=SimulationRunStatus(data["status"]), | ||
type=type, | ||
created_at=datetime.fromisoformat(data["created_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
events=[SimulationRunEvent.from_dict(event) for event in data.get("events", [])], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
from paddle_billing.Entities.Events import EventTypeName | ||
from paddle_billing.Entities.SimulationRunEvents import ( | ||
SimulationRunEventStatus, | ||
SimulationRunEventRequest, | ||
SimulationRunEventResponse, | ||
) | ||
|
||
from paddle_billing.Notifications.Entities.Entity import Entity as NotificationEntity | ||
from paddle_billing.Notifications.Entities.UndefinedEntity import UndefinedEntity | ||
|
||
|
||
@dataclass | ||
class SimulationRunEvent(Entity, ABC): | ||
id: str | ||
status: SimulationRunEventStatus | ||
event_type: EventTypeName | ||
payload: NotificationEntity | UndefinedEntity | ||
request: SimulationRunEventRequest | None | ||
response: SimulationRunEventResponse | None | ||
created_at: datetime | ||
updated_at: datetime | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> SimulationRunEvent: | ||
return SimulationRunEvent( | ||
id=data["id"], | ||
status=SimulationRunEventStatus(data["status"]), | ||
event_type=EventTypeName(data["event_type"]), | ||
payload=NotificationEntity.from_dict_for_event_type(data["payload"], data["event_type"]), | ||
request=SimulationRunEventRequest.from_dict(data["request"]) if data.get("request") else None, | ||
response=SimulationRunEventResponse.from_dict(data["response"]) if data.get("response") else None, | ||
created_at=datetime.fromisoformat(data["created_at"]), | ||
updated_at=datetime.fromisoformat(data["updated_at"]), | ||
) |
15 changes: 15 additions & 0 deletions
15
paddle_billing/Entities/SimulationRunEvents/SimulationRunEventRequest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
|
||
|
||
@dataclass | ||
class SimulationRunEventRequest(Entity): | ||
body: str | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> SimulationRunEventRequest: | ||
return SimulationRunEventRequest( | ||
body=data["body"], | ||
) |
17 changes: 17 additions & 0 deletions
17
paddle_billing/Entities/SimulationRunEvents/SimulationRunEventResponse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
|
||
|
||
@dataclass | ||
class SimulationRunEventResponse(Entity): | ||
body: str | ||
status_code: int | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> SimulationRunEventResponse: | ||
return SimulationRunEventResponse( | ||
body=data["body"], | ||
status_code=data["status_code"], | ||
) |
8 changes: 8 additions & 0 deletions
8
paddle_billing/Entities/SimulationRunEvents/SimulationRunEventStatus.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SimulationRunEventStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Aborted: "SimulationRunEventStatus" = "aborted" | ||
Failed: "SimulationRunEventStatus" = "failed" | ||
Success: "SimulationRunEventStatus" = "success" | ||
Pending: "SimulationRunEventStatus" = "pending" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from paddle_billing.Entities.SimulationRunEvents.SimulationRunEventRequest import SimulationRunEventRequest | ||
from paddle_billing.Entities.SimulationRunEvents.SimulationRunEventResponse import SimulationRunEventResponse | ||
from paddle_billing.Entities.SimulationRunEvents.SimulationRunEventStatus import SimulationRunEventStatus |
7 changes: 7 additions & 0 deletions
7
paddle_billing/Entities/SimulationRuns/SimulationRunStatus.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SimulationRunStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Canceled: "SimulationRunStatus" = "canceled" | ||
Completed: "SimulationRunStatus" = "completed" | ||
Pending: "SimulationRunStatus" = "pending" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from paddle_billing.Entities.SimulationRuns.SimulationRunStatus import SimulationRunStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import annotations | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
|
||
from paddle_billing.Entities.Entity import Entity | ||
from paddle_billing.Entities.Events import EventTypeName | ||
from paddle_billing.Entities.Simulations import SimulationKind | ||
|
||
|
||
@dataclass | ||
class SimulationType(Entity, ABC): | ||
name: str | ||
label: str | ||
description: str | ||
group: str | ||
type: SimulationKind | ||
events: list[EventTypeName] | ||
|
||
@staticmethod | ||
def from_dict(data: dict) -> SimulationType: | ||
return SimulationType( | ||
name=data["name"], | ||
label=data["label"], | ||
description=data["description"], | ||
group=data["group"], | ||
type=SimulationKind(data["type"]), | ||
events=[EventTypeName(event) for event in data.get("events", [])], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SimulationKind(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Scenario: "SimulationKind" = "scenario" | ||
SingleEvent: "SimulationKind" = "single_event" |
9 changes: 9 additions & 0 deletions
9
paddle_billing/Entities/Simulations/SimulationScenarioType.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SimulationScenarioType(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
SubscriptionCreation: "SimulationScenarioType" = "subscription_creation" | ||
SubscriptionRenewal: "SimulationScenarioType" = "subscription_renewal" | ||
SubscriptionPause: "SimulationScenarioType" = "subscription_pause" | ||
SubscriptionResume: "SimulationScenarioType" = "subscription_resume" | ||
SubscriptionCancellation: "SimulationScenarioType" = "subscription_cancellation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta | ||
|
||
|
||
class SimulationStatus(PaddleStrEnum, metaclass=PaddleStrEnumMeta): | ||
Active: "SimulationStatus" = "active" | ||
Archived: "SimulationStatus" = "archived" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from paddle_billing.Entities.Simulations.SimulationKind import SimulationKind | ||
from paddle_billing.Entities.Simulations.SimulationScenarioType import SimulationScenarioType | ||
from paddle_billing.Entities.Simulations.SimulationStatus import SimulationStatus |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PayloadEncoder
was becoming more complex, so have moved out intopaddle_billing.Json