Skip to content

Commit

Permalink
Improve webhook coverage (#613)
Browse files Browse the repository at this point in the history
* Outline webhook tests

* Rearrange tests and drop webhook fixture

* Add request body check on webhook update test

* Finalize webhooks tests

* Main tests, version bump and CHANGELOG.md

* Clean up

* Test rename

* Apply hooks

* Clean up

---------

Co-authored-by: Andres Hernandez <[email protected]>
  • Loading branch information
javidq and andher1802 authored May 29, 2024
1 parent 5c81c4d commit ded969d
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 171 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ You can check your current version with the following command:
```

For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
## 1.0.4a4

**May 29, 2024**

- Delegated webhook repr to its info
- Improved test coverage for webhooks
- Dropped unneeded shared and global fixtures for webhook tests


## 1.0.4a3

Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"tests.fixtures.fixtures_order",
"tests.fixtures.fixtures_storage",
"tests.fixtures.fixtures_tasking",
"tests.fixtures.fixtures_webhook",
]


Expand Down
15 changes: 0 additions & 15 deletions tests/fixtures/fixtures_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
ASSET_ORDER_ID = "22d0b8e9-b649-4971-8adc-1a5eac1fa6f3"
STAC_COLLECTION_ID = "e459db4c-3b9d-4aa1-8931-5df2517b49ba"

WEBHOOK_ID = "123"

URL_STAC_CATALOG = "https://api.up42.com/v2/assets/stac/"
URL_STAC_SEARCH = "https://api.up42.com/v2/assets/stac/search"

Expand Down Expand Up @@ -256,16 +254,3 @@
"number": 0,
"empty": False,
}

JSON_WEBHOOK = {
"data": {
"url": "https://test-info-webhook.com",
"name": "test_info_webhook",
"active": False,
"events": ["job.status"],
"id": WEBHOOK_ID,
"secret": "",
"createdAt": "2022-06-20T04:05:31.755744Z",
"updatedAt": "2022-06-20T04:05:31.755744Z",
}
}
80 changes: 0 additions & 80 deletions tests/fixtures/fixtures_webhook.py

This file was deleted.

48 changes: 27 additions & 21 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,36 @@ def workspace(self, auth_mock):
workspace_mock.id = constants.WORKSPACE_ID
yield

def test_get_webhook_events(self, requests_mock):
url_webhook_events = f"{constants.API_HOST}/webhooks/events"
events = ["some-event"]
requests_mock.get(
url=url_webhook_events,
json={
"data": events,
"error": {},
},
)
@mock.patch("up42.webhooks.Webhooks")
def test_should_get_webhook_events(self, webhooks: mock.MagicMock, auth_mock):
events = mock.MagicMock()
webhooks().get_webhook_events.return_value = events
assert base.get_webhook_events() == events
webhooks.assert_called_with(auth=auth_mock, workspace_id=constants.WORKSPACE_ID)

@mock.patch("up42.webhooks.Webhooks")
@pytest.mark.parametrize("return_json", [False, True])
def test_get_webhooks(self, webhooks_mock, return_json):
webhooks = base.get_webhooks(return_json=return_json)
expected = webhooks_mock.get_webhooks(return_json=return_json)
if return_json:
assert webhooks == expected
else:
for hook, expected_hook in zip(webhooks, expected):
assert hook.webhook_id == expected_hook.webhook_id
assert hook._info == expected_hook._info # pylint: disable=protected-access

def test_get_credits_balance(self, requests_mock):
def test_should_get_webhooks(self, webhooks: mock.MagicMock, auth_mock, return_json):
hooks = mock.MagicMock()
webhooks().get_webhooks.return_value = hooks
assert base.get_webhooks(return_json=return_json) == hooks
webhooks.assert_called_with(auth=auth_mock, workspace_id=constants.WORKSPACE_ID)
webhooks.return_value.get_webhooks.assert_called_with(return_json=return_json)

@mock.patch("up42.webhooks.Webhooks")
def test_should_create_webhook(self, webhooks: mock.MagicMock, auth_mock):
name = "name"
url = "url"
events = ["event"]
active = True
secret = "secret"
webhook = mock.MagicMock()
webhooks().create_webhook.return_value = webhook
assert webhook == base.create_webhook(name, url, events, active, secret)
webhooks.assert_called_with(auth=auth_mock, workspace_id=constants.WORKSPACE_ID)
webhooks().create_webhook.assert_called_with(name=name, url=url, events=events, active=active, secret=secret)

def test_should_get_credits_balance(self, requests_mock):
balance_url = f"{constants.API_HOST}/accounts/me/credits/balance"
balance = {"balance": 10693}
requests_mock.get(
Expand Down
Loading

0 comments on commit ded969d

Please sign in to comment.