Demo entry 6770294



Submitted by anonymous on Nov 12, 2018 at 18:42
Language: Python. Code size: 1.4 kB.

import behave
import httplib
import json

def request(method, uri, data=None):
        body = json.dumps(data) if data else None
        conn = httplib.HTTPConnection("localhost:8000")
        conn.request(method, uri, body=body, headers={'Content-Type': 'application/json'})
        server_response = conn.getresponse()
        response_dict = {
            'status_code': server_response.status,
            response_dict['data'] = json.loads(response_dict['body'])
        except ValueError:

    except Exception as e:
        assert False, "Can't interact with Schedule Sender API: {error}".format(error=e.message or str(e))

    return response_dict

@behave.given('a Schedule Sender API')
def step_impl(_):
    response = request('GET', '/talks/')
    assert response.get('status_code') == 200, "Schedule Sender API is available"

@behave.when(u'a Client POSTs a request to non-existing URI')
def step_impl(context):
    response = request('POST', '/non-existing/', {"phone_number": "+1234567890"})
    context.response = response

@behave.then('the API responds with Not Found')
def step_impl(context):
    assert context.response['status_code'] == 404, "Expected status code returned"

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).