Skip to content

Commit

Permalink
tests: Add tests using IP address when creating or updating webhooks (#…
Browse files Browse the repository at this point in the history
…5511)

# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

Since URLs including IP addresses are allowed values when
creating/updating webhooks, this PR only adds tests checking these
scenarios.

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->


**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: José Francisco Calvo <[email protected]>
  • Loading branch information
frascuchon and jfcalvo authored Sep 19, 2024
1 parent 38642ea commit a26f008
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ async def test_create_webhook(self, db: AsyncSession, async_client: AsyncClient,
"updated_at": webhook.updated_at.isoformat(),
}

async def test_create_webhook_with_ip_address_url(
self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict
):
response = await async_client.post(
self.url(),
headers=owner_auth_header,
json={
"url": "http://1.1.1.1/webhook",
"events": [WebhookEvent.response_created],
"description": "Test webhook",
},
)

assert response.status_code == 201

assert (await db.execute(select(func.count(Webhook.id)))).scalar() == 1
webhook = (await db.execute(select(Webhook))).scalar_one()

assert response.json()["url"] == "http://1.1.1.1/webhook"

async def test_create_webhook_as_admin(self, db: AsyncSession, async_client: AsyncClient):
admin = await AdminFactory.create()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ async def test_update_webhook_with_url(self, async_client: AsyncClient, owner_au

assert webhook.url == "https://example.com/webhook"

async def test_update_webhook_with_ip_address_url(self, async_client: AsyncClient, owner_auth_header: dict):
webhook = await WebhookFactory.create()

response = await async_client.patch(
self.url(webhook.id),
headers=owner_auth_header,
json={
"url": "https://1.1.1.1:9999/webhook",
},
)

assert response.status_code == 200
assert response.json()["url"] == "https://1.1.1.1:9999/webhook"

async def test_update_webhook_with_events(self, async_client: AsyncClient, owner_auth_header: dict):
webhook = await WebhookFactory.create()

Expand Down

0 comments on commit a26f008

Please sign in to comment.