-
Notifications
You must be signed in to change notification settings - Fork 68
[SDK-400] Validate url, secret, and topic list on webhook creation. #1281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4940b7
1afa212
a3c3bd3
050e82d
679e47e
b74f91c
2263de9
1745a07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,39 @@ def test_webhook_create_update(project, rand_gen): | |
| "Topics must be List[Webhook.Topic]. Found `invalid..`" | ||
|
|
||
| webhook.delete() | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These, in my opinion, should be considered unit-tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of tests in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I moved them to unit.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second Klaus comments, after that can approve
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be fixed now and checks are passing, can I get an approval? |
||
| def test_webhook_create_with_no_secret(project, rand_gen): | ||
| client = project.client | ||
| secret = "" | ||
| url = "https:/" + rand_gen(str) | ||
| topics = [] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "Secret must be a non-empty string." | ||
|
|
||
|
|
||
| def test_webhook_create_with_no_topics(project, rand_gen): | ||
| client = project.client | ||
| secret = rand_gen(str) | ||
| url = "https:/" + rand_gen(str) | ||
| topics = [] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "Topics must be a non-empty list." | ||
|
|
||
|
|
||
| def test_webhook_create_with_no_url(project, rand_gen): | ||
| client = project.client | ||
| secret = rand_gen(str) | ||
| url = "" | ||
| topics = [Webhook.LABEL_CREATED, Webhook.LABEL_DELETED] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "URL must be a non-empty string." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from unittest.mock import MagicMock | ||
| import pytest | ||
|
|
||
| from labelbox import Webhook | ||
|
|
||
|
|
||
| def test_webhook_create_with_no_secret(rand_gen): | ||
| client = MagicMock() | ||
| project = MagicMock() | ||
| secret = "" | ||
| url = "https:/" + rand_gen(str) | ||
| topics = [] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "Secret must be a non-empty string." | ||
|
|
||
|
|
||
| def test_webhook_create_with_no_topics(rand_gen): | ||
| client = MagicMock() | ||
| project = MagicMock() | ||
| secret = rand_gen(str) | ||
| url = "https:/" + rand_gen(str) | ||
| topics = [] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "Topics must be a non-empty list." | ||
|
|
||
|
|
||
| def test_webhook_create_with_no_url(rand_gen): | ||
| client = MagicMock() | ||
| project = MagicMock() | ||
| secret = rand_gen(str) | ||
| url = "" | ||
| topics = [Webhook.Topic.LABEL_CREATED, Webhook.Topic.LABEL_DELETED] | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| Webhook.create(client, topics, url, secret, project) | ||
| assert str(exc_info.value) == \ | ||
| "URL must be a non-empty string." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little out of scope, but this docs link is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!