How to use the sparkpost.tornado.SparkPost function in sparkpost

To help you get started, we’ve selected a few sparkpost 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 SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_nocontent_get():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=204,
        content_type='application/json',
        body=''
    )
    sp = SparkPost('fake-key')
    response = ioloop.IOLoop().run_sync(sp.transmission.list)
    assert response is True
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_success_list():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=200,
        content_type='application/json',
        body='{"results": []}'
    )
    sp = SparkPost('fake-key')
    response = ioloop.IOLoop().run_sync(sp.transmission.list)
    assert response == []
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_brokenjson_get():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=200,
        content_type='application/json',
        body='{"results":'
    )
    with pytest.raises(SparkPostAPIException):
        sp = SparkPost('fake-key')
        ioloop.IOLoop().run_sync(sp.transmission.list)
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_fail_send():
    responses.add(
        responses.POST,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=500,
        content_type='application/json',
        body="""
        {"errors": [{"message": "You failed", "description": "More Info"}]}
        """
    )
    with pytest.raises(SparkPostAPIException):
        sp = SparkPost('fake-key')
        ioloop.IOLoop().run_sync(sp.transmission.send)
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_success_send_with_attachments():
    try:
        # Let's compare unicode for Python 2 / 3 compatibility
        test_content = six.u("Hello \nWorld\n")
        (_, temp_file_path) = tempfile.mkstemp()
        with open(temp_file_path, "w") as temp_file:
            temp_file.write(test_content)

        responses.add(
            responses.POST,
            'https://api.sparkpost.com/api/v1/transmissions',
            status=200,
            content_type='application/json',
            body='{"results": "yay"}'
        )
        sp = SparkPost('fake-key')

        attachment = {
            "name": "test.txt",
            "type": "text/plain",
            "filename": temp_file_path
        }

        def send():
            return sp.transmission.send(attachments=[attachment])
        results = ioloop.IOLoop().run_sync(send)

        request_params = json.loads(responses.calls[0].request.body)
        content = base64.b64decode(
            request_params["content"]["attachments"][0]["data"])
        # Let's compare unicode for Python 2 / 3 compatibility
        assert test_content == content.decode("ascii")
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_noresults_get():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=200,
        content_type='application/json',
        body='{"ok": false}'
    )
    sp = SparkPost('fake-key')
    response = ioloop.IOLoop().run_sync(sp.transmission.list)
    assert response == {"ok": False}
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_success_get():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions/foobar',
        status=200,
        content_type='application/json',
        body='{"results": {"transmission": {}}}'
    )
    sp = SparkPost('fake-key')

    def send():
        return sp.transmission.get('foobar')
    results = ioloop.IOLoop().run_sync(send, timeout=3)
    assert results == {}
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_fail_get():
    responses.add(
        responses.GET,
        'https://api.sparkpost.com/api/v1/transmissions/foobar',
        status=404,
        content_type='application/json',
        body="""
        {"errors": [{"message": "cant find", "description": "where you go"}]}
        """
    )
    with pytest.raises(SparkPostAPIException):
        sp = SparkPost('fake-key')

        def send():
            return sp.transmission.get('foobar')
        ioloop.IOLoop().run_sync(send, timeout=3)
github SparkPost / python-sparkpost / test / tornado / test_tornado.py View on Github external
def test_success_send():
    responses.add(
        responses.POST,
        'https://api.sparkpost.com/api/v1/transmissions',
        status=200,
        content_type='application/json',
        body='{"results": "yay"}'
    )
    sp = SparkPost('fake-key')
    results = ioloop.IOLoop().run_sync(sp.transmission.send)
    assert results == 'yay'