chore(): small improvements
This commit is contained in:
@@ -138,6 +138,8 @@ def create_rule(
|
||||
event_type=payload.event_type,
|
||||
channel=ch,
|
||||
experiment=experiment,
|
||||
rate_limit_window_seconds=payload.rate_limit_window_seconds,
|
||||
rate_limit_max_notifications=payload.rate_limit_max_notifications,
|
||||
)
|
||||
r = NotificationRule.objects.select_related("channel", "experiment").get(
|
||||
pk=r.pk
|
||||
|
||||
@@ -42,11 +42,15 @@ class RuleCreateIn(Schema):
|
||||
event_type: NotificationEventType
|
||||
channel_id: UUID
|
||||
experiment_id: UUID | None = None
|
||||
rate_limit_window_seconds: int = 60
|
||||
rate_limit_max_notifications: int = 1
|
||||
|
||||
|
||||
class RuleUpdateIn(Schema):
|
||||
event_type: NotificationEventType | None = None
|
||||
is_active: bool | None = None
|
||||
rate_limit_window_seconds: int | None = None
|
||||
rate_limit_max_notifications: int | None = None
|
||||
|
||||
|
||||
class ChannelBriefOut(Schema):
|
||||
@@ -70,6 +74,8 @@ class RuleOut(ModelSchema):
|
||||
NotificationRule.id.field.name,
|
||||
NotificationRule.event_type.field.name,
|
||||
NotificationRule.is_active.field.name,
|
||||
NotificationRule.rate_limit_window_seconds.field.name,
|
||||
NotificationRule.rate_limit_max_notifications.field.name,
|
||||
NotificationRule.created_at.field.name,
|
||||
NotificationRule.updated_at.field.name,
|
||||
)
|
||||
@@ -92,6 +98,8 @@ class RuleOut(ModelSchema):
|
||||
),
|
||||
experiment=experiment_brief,
|
||||
is_active=r.is_active,
|
||||
rate_limit_window_seconds=r.rate_limit_window_seconds,
|
||||
rate_limit_max_notifications=r.rate_limit_max_notifications,
|
||||
created_at=r.created_at,
|
||||
updated_at=r.updated_at,
|
||||
)
|
||||
|
||||
@@ -148,6 +148,18 @@ class RuleAPITest(TestCase):
|
||||
)
|
||||
self.assertEqual(data["channel"]["id"], str(self.channel.pk))
|
||||
self.assertIsNone(data["experiment"])
|
||||
self.assertEqual(data["rate_limit_window_seconds"], 60)
|
||||
self.assertEqual(data["rate_limit_max_notifications"], 1)
|
||||
|
||||
def test_create_rule_with_custom_rate_limit(self) -> None:
|
||||
resp = self._create_rule(
|
||||
rate_limit_window_seconds=120,
|
||||
rate_limit_max_notifications=3,
|
||||
)
|
||||
self.assertEqual(resp.status_code, 201)
|
||||
data = resp.json()
|
||||
self.assertEqual(data["rate_limit_window_seconds"], 120)
|
||||
self.assertEqual(data["rate_limit_max_notifications"], 3)
|
||||
|
||||
def test_create_rule_nonexistent_channel(self) -> None:
|
||||
resp = self._create_rule(channel_id=str(uuid.uuid4()))
|
||||
@@ -167,12 +179,20 @@ class RuleAPITest(TestCase):
|
||||
rule_id = create_resp.json()["id"]
|
||||
resp = self.client.patch(
|
||||
reverse("api-1:update_rule", args=[rule_id]),
|
||||
data=json.dumps({"is_active": False}),
|
||||
data=json.dumps(
|
||||
{
|
||||
"is_active": False,
|
||||
"rate_limit_window_seconds": 300,
|
||||
"rate_limit_max_notifications": 5,
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
HTTP_AUTHORIZATION=self.auth,
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertFalse(resp.json()["is_active"])
|
||||
self.assertEqual(resp.json()["rate_limit_window_seconds"], 300)
|
||||
self.assertEqual(resp.json()["rate_limit_max_notifications"], 5)
|
||||
|
||||
def test_update_rule_not_found(self) -> None:
|
||||
resp = self.client.patch(
|
||||
|
||||
Reference in New Issue
Block a user