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

Fix failing tests #27

Closed
kumaresan-plivo opened this issue Oct 27, 2016 · 2 comments
Closed

Fix failing tests #27

kumaresan-plivo opened this issue Oct 27, 2016 · 2 comments
Assignees

Comments

@kumaresan-plivo
Copy link

  1. Fix failing travis CI builds due to --use-mirrors
  2. Tests currently need real Auth credentials to work. Come up with infrastructure to do this or use mock tests.
@wojcikstefan
Copy link

wojcikstefan commented Oct 27, 2016

We've been successfully testing our requests to Plivo and mocking Plivo responses with https://github.com/patrys/httmock. A sample code looks like this:

def test_delete_phone_number(self):
    requests_list = []  # track all the requests made to plivo

    @urlmatch(netloc='api\.plivo\.com')
    def response_content(url, request):
        requests_list.append((request.method, url.geturl()))
        return { 'status_code': 204, 'content': '' }

    with HTTMock(response_content):
        resp = self.delete('/api/v1/phone_number/{}/'.format(pn.pk), api_key=test_api_key)
        response_success(resp)

    # Assert that we only made a single DELETE request to Plivo
    self.assertEqual(requests_list, [
        ('DELETE', 'https://api.plivo.com/v1/Account/TEST_PLIVO_AUTH_ID/Number/16503334444/')
    ])

You can also have a more sophisticated logic of what to respond with depending on the request data/url and you can put asserts inside of response_content. Hope this is helpful.

@kumaresan-plivo
Copy link
Author

Thanks @wojcikstefan, sounds like a good fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants