<gh_stars>10-100
from nose.tools import assert_equals, raises

from gocardless_pro.webhooks import parse
from gocardless_pro.errors import InvalidSignatureError

import os

fixture = open(
    os.path.join(
        os.path.dirname(__file__),
        'fixtures',
        'webhook_body.json'
    )
).read().strip()

fixture_signature = "2693754819d3e32d7e8fcb13c729631f316c6de8dc1cf634d6527f1c07276e7e"
key = "<KEY>"

def test_it_parses_the_body():
    result = parse(fixture, key, fixture_signature)
    assert_equals(len(result), 2)

    first_event = result[0]
    assert_equals(first_event.id, "EV00BD05S5VM2T")

def test_it_parses_the_body_from_bytes():
    result = parse(bytearray(fixture, 'utf-8'), key, fixture_signature)
    assert_equals(len(result), 2)

    first_event = result[0]
    assert_equals(first_event.id, "EV00BD05S5VM2T")

@raises(InvalidSignatureError)
def test_it_raises_with_invalid_signature():
    wrong_key = "anotherkey"
    parse(fixture, wrong_key, fixture_signature)

from nose.tools import assert_equals, raises

from gocardless_pro.webhooks import parse
from gocardless_pro.errors import InvalidSignatureError

import os

fixture = open(
    os.path.join(
        os.path.dirname(__file__),
        'fixtures',
        'webhook_body.json'
    )
).read().strip()

fixture_signature = "2693754819d3e32d7e8fcb13c729631f316c6de8dc1cf634d6527f1c07276e7e"
key = "<KEY>"

def test_it_parses_the_body():
    result = parse(fixture, key, fixture_signature)
    assert_equals(len(result), 2)

    first_event = result[0]
    assert_equals(first_event.id, "EV00BD05S5VM2T")

def test_it_parses_the_body_from_bytes():
    result = parse(bytearray(fixture, 'utf-8'), key, fixture_signature)
    assert_equals(len(result), 2)

    first_event = result[0]
    assert_equals(first_event.id, "EV00BD05S5VM2T")

@raises(InvalidSignatureError)
def test_it_raises_with_invalid_signature():
    wrong_key = "anotherkey"
    parse(fixture, wrong_key, fixture_signature)