How to use the numerapi.utils.post_with_err_handling function in numerapi

To help you get started, we’ve selected a few numerapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uuazed / numerapi / tests / test_utils.py View on Github external
def test_post_with_err_handling(caplog):
    # unreachable
    responses.add(responses.POST, "https://someurl1", status=404)
    utils.post_with_err_handling("https://someurl1", None, None)
    assert 'Http Error' in caplog.text
    caplog.clear()

    # invalid resonse type
    responses.add(responses.POST, "https://someurl2")
    utils.post_with_err_handling("https://someurl2", None, None)
    assert 'Did not receive a valid JSON' in caplog.text
    caplog.clear()

    # timeout
    responses.add(responses.POST, "https://someurl3",
                  body=requests.exceptions.Timeout())
    utils.post_with_err_handling("https://someurl3", None, None)
    assert 'Timeout Error' in caplog.text
    caplog.clear()
github uuazed / numerapi / tests / test_utils.py View on Github external
def test_post_with_err_handling(caplog):
    # unreachable
    responses.add(responses.POST, "https://someurl1", status=404)
    utils.post_with_err_handling("https://someurl1", None, None)
    assert 'Http Error' in caplog.text
    caplog.clear()

    # invalid resonse type
    responses.add(responses.POST, "https://someurl2")
    utils.post_with_err_handling("https://someurl2", None, None)
    assert 'Did not receive a valid JSON' in caplog.text
    caplog.clear()

    # timeout
    responses.add(responses.POST, "https://someurl3",
                  body=requests.exceptions.Timeout())
    utils.post_with_err_handling("https://someurl3", None, None)
    assert 'Timeout Error' in caplog.text
    caplog.clear()
github uuazed / numerapi / tests / test_utils.py View on Github external
# unreachable
    responses.add(responses.POST, "https://someurl1", status=404)
    utils.post_with_err_handling("https://someurl1", None, None)
    assert 'Http Error' in caplog.text
    caplog.clear()

    # invalid resonse type
    responses.add(responses.POST, "https://someurl2")
    utils.post_with_err_handling("https://someurl2", None, None)
    assert 'Did not receive a valid JSON' in caplog.text
    caplog.clear()

    # timeout
    responses.add(responses.POST, "https://someurl3",
                  body=requests.exceptions.Timeout())
    utils.post_with_err_handling("https://someurl3", None, None)
    assert 'Timeout Error' in caplog.text
    caplog.clear()
github uuazed / numerapi / numerapi / numerapi.py View on Github external
>>> NumerAPI().raw_query(query, args)
            {'data': {'rounds': [{'number': 104}]}}
        """
        body = {'query': query,
                'variables': variables}
        headers = {'Content-type': 'application/json',
                   'Accept': 'application/json'}
        if authorization:
            if self.token:
                public_id, secret_key = self.token
                headers['Authorization'] = \
                    'Token {}${}'.format(public_id, secret_key)
            else:
                raise ValueError("API keys required for this action.")

        result = utils.post_with_err_handling(
            API_TOURNAMENT_URL, body, headers)

        if result and "errors" in result:
            err = self._handle_call_error(result['errors'])
            # fail!
            raise ValueError(err)
        return result