def test_wrong_content_type():
    req = get_request()
    req['headers']['Content-Type'] = 'text/plain'

    resp = create_urls.api_handler(req, None)

    assert resp['statusCode'] == 415
def test_wrong_method():
    req = get_request()
    req['httpMethod'] = 'GET'

    resp = create_urls.api_handler(req, None)

    assert resp['statusCode'] == 405
def test_invalid_event():
    req = get_request()

    req['body'] = json.dumps({'token': 1})

    resp = create_urls.api_handler(req, None)

    assert resp['statusCode'] == 400

    body = json.loads(resp['body'])
    assert body['error'] == 'InvalidJSON'
def test_invalid_json():
    req = get_request()

    req['body'] = '{"foo"'

    resp = create_urls.api_handler(req, None)

    assert resp['statusCode'] == 400

    body = json.loads(resp['body'])
    assert body['error'] == 'InvalidJSON'
def test_basic_request():
    req = get_request()

    req['body'] = json.dumps(
        get_event(actions=[
            get_success('foo', {'spam': 'eggs'}),
            get_failure('bar'),
            get_heartbeat('baz')
        ]))

    resp = create_urls.api_handler(req, None)
    assert resp['statusCode'] == 200

    body = json.loads(resp['body'])
    assert 'urls' in body
    assert len(body['urls']) == 3
def test_empty_body():
    req = get_request()

    resp = create_urls.api_handler(req, None)

    assert resp['statusCode'] == 400