Skip to content
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

Create tests for webhooks #3952

Closed
jeremystretch opened this issue Jan 17, 2020 · 2 comments
Closed

Create tests for webhooks #3952

jeremystretch opened this issue Jan 17, 2020 · 2 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user

Comments

@jeremystretch
Copy link
Member

Proposed Changes

Create new unit tests for:

  1. Create/updating/deleting webhooks
  2. Placing webhook events in the queue
  3. Transmitting webhooks

Justification

We have a huge gap in our test coverage around webhooks currently, leading to bugs such as #3951.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user labels Jan 17, 2020
@jeremystretch jeremystretch self-assigned this Jan 17, 2020
@jeremystretch
Copy link
Member Author

I've added tests for the enqueuing process in c6eb40d, but I'm not sure how to go about testing the RQ worker process. @lampwins any ideas?

@hSaria
Copy link
Contributor

hSaria commented Jan 17, 2020

unittest.mock.patch the requests.send and checking it is called with the expected arguments is an option (I was testing with requests.post, but you get the idea).

>>> from unittest.mock import patch
>>> import requests
>>>
>>> def send():
...     requests.post('http://localhost')
... 
>>> @patch('requests.post')
... def test_send(mock_post):
...     send()
...     mock_post.assert_called_with('http://localhost')
... 
>>> test_send()
>>> 
>>> def send():
...     requests.post('http://not_localhost')
... 
>>> test_send()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py", line 1255, in patched
    return func(*args, **keywargs)
  File "<stdin>", line 4, in test_send
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py", line 873, in assert_called_with
    raise AssertionError(_error_message()) from cause
AssertionError: Expected call: post('http://localhost')
Actual call: post('http://not_localhost')
>>> 

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

No branches or pull requests

2 participants