2022-06-17 13:25:47 -08:00
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
2021-09-09 08:51:29 -08:00
|
|
|
import pytest
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
from tests.utils import api_routes, assert_derserialize, jsonify
|
2021-09-09 08:51:29 -08:00
|
|
|
from tests.utils.fixture_schemas import TestUser
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def webhook_data():
|
2022-06-17 13:25:47 -08:00
|
|
|
return {
|
|
|
|
"enabled": True,
|
|
|
|
"name": "Test-Name",
|
|
|
|
"url": "https://my-fake-url.com",
|
|
|
|
"time": "00:00",
|
|
|
|
"scheduledTime": datetime.now(),
|
|
|
|
}
|
2021-09-09 08:51:29 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
2021-09-12 11:05:09 -08:00
|
|
|
assert response.status_code == 201
|
2021-09-09 08:51:29 -08:00
|
|
|
|
|
|
|
|
2021-09-19 15:31:34 -08:00
|
|
|
def test_read_webhook(api_client: TestClient, unique_user: TestUser, webhook_data):
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
2022-06-17 13:25:47 -08:00
|
|
|
item_id = response.json()["id"]
|
2022-02-20 14:17:51 -09:00
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
2022-06-17 13:25:47 -08:00
|
|
|
webhook = assert_derserialize(response, 200)
|
2021-09-09 08:51:29 -08:00
|
|
|
|
2022-06-17 13:25:47 -08:00
|
|
|
assert webhook["id"] == item_id
|
2021-09-09 08:51:29 -08:00
|
|
|
assert webhook["name"] == webhook_data["name"]
|
|
|
|
assert webhook["url"] == webhook_data["url"]
|
2022-06-17 13:25:47 -08:00
|
|
|
assert webhook["scheduledTime"] == str(webhook_data["scheduledTime"].astimezone(timezone.utc).time())
|
2021-09-09 08:51:29 -08:00
|
|
|
assert webhook["enabled"] == webhook_data["enabled"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
2022-06-17 13:25:47 -08:00
|
|
|
item_dict = assert_derserialize(response, 201)
|
|
|
|
item_id = item_dict["id"]
|
2022-02-20 14:17:51 -09:00
|
|
|
|
2021-09-09 08:51:29 -08:00
|
|
|
webhook_data["name"] = "My New Name"
|
|
|
|
webhook_data["url"] = "https://my-new-fake-url.com"
|
|
|
|
webhook_data["enabled"] = False
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.put(
|
|
|
|
api_routes.groups_webhooks_item_id(item_id), json=jsonify(webhook_data), headers=unique_user.token
|
|
|
|
)
|
2022-06-17 13:25:47 -08:00
|
|
|
updated_webhook = assert_derserialize(response, 200)
|
2021-09-09 08:51:29 -08:00
|
|
|
|
|
|
|
assert updated_webhook["name"] == webhook_data["name"]
|
|
|
|
assert updated_webhook["url"] == webhook_data["url"]
|
|
|
|
assert updated_webhook["enabled"] == webhook_data["enabled"]
|
|
|
|
|
|
|
|
|
2022-02-20 14:17:51 -09:00
|
|
|
def test_delete_webhook(api_client: TestClient, webhook_data, unique_user: TestUser):
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.post(api_routes.groups_webhooks, json=jsonify(webhook_data), headers=unique_user.token)
|
2022-06-17 13:25:47 -08:00
|
|
|
item_dict = assert_derserialize(response, 201)
|
|
|
|
item_id = item_dict["id"]
|
2021-09-09 08:51:29 -08:00
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.delete(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
2021-09-09 08:51:29 -08:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
response = api_client.get(api_routes.groups_webhooks_item_id(item_id), headers=unique_user.token)
|
2021-09-09 08:51:29 -08:00
|
|
|
assert response.status_code == 404
|