From 13fb206df4723e5557066b6cbed53dabf6736e02 Mon Sep 17 00:00:00 2001 From: Hunt Xu Date: Fri, 6 Jul 2018 15:57:01 +0800 Subject: [PATCH] Remove default function_version in webhook resource def Or the function_version of a webhook would be changed to the default value when updating the webhook without providing the function_version parameter. That's an unexpected result. Story: 2002898 Task: 22862 Change-Id: I63ec211a8771a55d2b04caed1f66a405849cb201 Signed-off-by: Hunt Xu --- qinling/api/controllers/v1/resources.py | 2 +- .../tests/unit/api/controllers/v1/test_webhook.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qinling/api/controllers/v1/resources.py b/qinling/api/controllers/v1/resources.py index 3c41a1bd..1e5be6a2 100644 --- a/qinling/api/controllers/v1/resources.py +++ b/qinling/api/controllers/v1/resources.py @@ -353,7 +353,7 @@ class ScaleInfo(Resource): class Webhook(Resource): id = types.uuid function_id = types.uuid - function_version = wsme.wsattr(int, default=0) + function_version = wsme.wsattr(int) description = wtypes.text project_id = wsme.wsattr(wtypes.text, readonly=True) created_at = wsme.wsattr(wtypes.text, readonly=True) diff --git a/qinling/tests/unit/api/controllers/v1/test_webhook.py b/qinling/tests/unit/api/controllers/v1/test_webhook.py index f39b48e7..60d0f603 100644 --- a/qinling/tests/unit/api/controllers/v1/test_webhook.py +++ b/qinling/tests/unit/api/controllers/v1/test_webhook.py @@ -93,3 +93,18 @@ class TestWebhookController(base.APITest): self.assertEqual(200, resp.status_int) self.assertEqual(1, resp.json.get("function_version")) + + def test_put_without_version(self): + db_api.increase_function_version(self.func_id, 0) + webhook = self.create_webhook(self.func_id, function_version=1) + + self.assertEqual(1, webhook.function_version) + + resp = self.app.put_json( + '/v1/webhooks/%s' % webhook.id, + {'description': 'updated description'} + ) + + self.assertEqual(200, resp.status_int) + self.assertEqual(1, resp.json.get("function_version")) + self.assertEqual('updated description', resp.json.get("description"))