|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +def test_events_registration(nc_app): |
| 5 | + assert isinstance(nc_app.webhooks.get_list(), list) |
| 6 | + assert isinstance(nc_app.webhooks.unregister_all(), int) |
| 7 | + assert nc_app.webhooks.unregister_all() == 0 |
| 8 | + assert nc_app.webhooks.get_list() == [] |
| 9 | + webhook_info = nc_app.webhooks.register( |
| 10 | + "POST", |
| 11 | + "/some_url", |
| 12 | + "OCP\\Files\\Events\\Node\\NodeCreatedEvent", |
| 13 | + ) |
| 14 | + result = nc_app.webhooks.get_entry(webhook_info.webhook_id) |
| 15 | + assert result.webhook_id == webhook_info.webhook_id |
| 16 | + assert result.app_id == "nc_py_api" |
| 17 | + assert result.http_method == "POST" |
| 18 | + assert result.uri == "/some_url" |
| 19 | + assert result.auth_method == "none" |
| 20 | + assert result.auth_data == {} |
| 21 | + assert result.user_id_filter == "" |
| 22 | + assert result.event_filter == [] |
| 23 | + assert result.event == "OCP\\Files\\Events\\Node\\NodeCreatedEvent" |
| 24 | + result = nc_app.webhooks.update( |
| 25 | + webhook_info.webhook_id, http_method="PUT", uri="/some_url2", event="OCP\\Files\\Events\\Node\\NodeCreatedEvent" |
| 26 | + ) |
| 27 | + assert result.webhook_id == webhook_info.webhook_id |
| 28 | + nc_app.webhooks.unregister(webhook_info.webhook_id) |
| 29 | + nc_app.webhooks.unregister(webhook_info.webhook_id) # removing non-existing webhook should not fail |
| 30 | + assert nc_app.webhooks.get_entry(webhook_info.webhook_id) is None |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.asyncio(scope="session") |
| 34 | +async def test_events_registration_async(anc_app): |
| 35 | + assert isinstance(await anc_app.webhooks.get_list(), list) |
| 36 | + assert isinstance(await anc_app.webhooks.unregister_all(), int) |
| 37 | + assert await anc_app.webhooks.unregister_all() == 0 |
| 38 | + assert await anc_app.webhooks.get_list() == [] |
| 39 | + webhook_info = await anc_app.webhooks.register( |
| 40 | + "POST", |
| 41 | + "/some_url", |
| 42 | + "OCP\\Files\\Events\\Node\\NodeCreatedEvent", |
| 43 | + ) |
| 44 | + result = await anc_app.webhooks.get_entry(webhook_info.webhook_id) |
| 45 | + assert result.webhook_id == webhook_info.webhook_id |
| 46 | + assert result.app_id == "nc_py_api" |
| 47 | + assert result.http_method == "POST" |
| 48 | + assert result.uri == "/some_url" |
| 49 | + assert result.auth_method == "none" |
| 50 | + assert result.auth_data == {} |
| 51 | + assert result.user_id_filter == "" |
| 52 | + assert result.event_filter == [] |
| 53 | + assert result.event == "OCP\\Files\\Events\\Node\\NodeCreatedEvent" |
| 54 | + result = await anc_app.webhooks.update( |
| 55 | + webhook_info.webhook_id, http_method="PUT", uri="/some_url2", event="OCP\\Files\\Events\\Node\\NodeCreatedEvent" |
| 56 | + ) |
| 57 | + assert result.webhook_id == webhook_info.webhook_id |
| 58 | + await anc_app.webhooks.unregister(webhook_info.webhook_id) |
| 59 | + await anc_app.webhooks.unregister(webhook_info.webhook_id) # removing non-existing webhook should not fail |
| 60 | + assert await anc_app.webhooks.get_entry(webhook_info.webhook_id) is None |
0 commit comments