コード例 #1
0
def test_process_event(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event.json'), 'rt').read())

    event = Event()
    event.parse_event(apigw_event)

    assert event.event == apigw_event
    assert event.method == 'POST'
    assert event.body['data_stuff'] == 'down is the new up'
    assert event.params['foo'] == 'bar'
    assert event.path == '/the/cool/path'
コード例 #2
0
def test_set_body_encoded(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    event.set_body()
    print(event.body)
    assert event.body['data_stuff'] == "down is the new up"
コード例 #3
0
def test_set_body_no_event():
    event = Event()
    with pytest.raises(AwAwsMissingRequirement,
                       match=r'use event.set_event()'
                       ):
        event.set_body()
コード例 #4
0
def test_set_body_no_body(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_3.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    event.set_body()
    assert event.body is None
コード例 #5
0
def test_set_body_dencoded_error(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_4.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    with pytest.raises(Exception, match=r'Error decoding'):
        event.set_body()
コード例 #6
0
def test_init():
    event = Event()
    assert type(event) == Event
    assert event.method == 'ANY'
    assert event.params is None
    assert event.body is None
コード例 #7
0
def test_set_http_method_error_2(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_3.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    with pytest.raises(AwAwsInvalidHttpMethod, match='Not a valid http method: BLARGH'):
        event.set_http_method()
コード例 #8
0
def test_set_http_method_error_1(datadir):
    event = Event()
    with pytest.raises(AwAwsMissingRequirement, match='Event not set'):
        event.set_http_method()
コード例 #9
0
def test_set_http_method(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    event.set_http_method()
    assert event.method == 'POST'
コード例 #10
0
def test_set_event(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    assert event.event['path'] == '/the/cool/path'
コード例 #11
0
def test_process_event_fail(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_err.json'), 'rt').read())

    event = Event()
    with pytest.raises(Exception):
        event.parse_event(apigw_event)
コード例 #12
0
def test_set_path_missing(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_no_path.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    event.set_path_params()
    assert event.path is None
コード例 #13
0
def test_set_path_params_error(datadir):
    event = Event()
    with pytest.raises(AwAwsMissingRequirement, match='Event not set'):
        event.set_path_params()
コード例 #14
0
def test_set_qstring_params_no_qsring(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event_4.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    check = event.set_qstring_params()
    assert check is None
コード例 #15
0
def test_set_qstring_params(datadir):
    apigw_event = json.loads(open(datadir.join('apigw_event.json'), 'rt').read())
    event = Event()
    event.set_event(apigw_event)
    event.set_qstring_params()
    assert event.params['foo'] == 'bar'