Ejemplo n.º 1
0
def test_fail_create_brand():
    responses.add(responses.POST,
                  'https://api.courier.com/brands',
                  status=400,
                  content_type='application/json',
                  body='{"message": "An error occured"}')

    c = Courier(auth_token='123456789ABCDF')

    with pytest.raises(CourierAPIException):
        c.create_brand(name="my brand", settings={})
Ejemplo n.º 2
0
def test_success_create_brand():
    responses.add(responses.POST,
                  'https://api.courier.com/brands',
                  status=200,
                  content_type='application/json',
                  body='{"id": "1234", "name": "my brand"}')

    c = Courier(auth_token='123456789ABCDF')
    r = c.create_brand(name="my brand", settings={})

    assert r == {"id": "1234", "name": "my brand"}
Ejemplo n.º 3
0
def test_success_create_brand_idempotent():
    responses.add(responses.POST,
                  'https://api.courier.com/brands',
                  status=200,
                  content_type='application/json',
                  body='{"id": "1234", "name": "my brand"}')

    c = Courier(auth_token='123456789ABCDF')
    r = c.create_brand(name="my brand",
                       settings={},
                       idempotency_key="1234ABCD")

    assert responses.calls[0].request.headers.get(
        'Idempotency-Key') == '1234ABCD'
    assert r == {"id": "1234", "name": "my brand"}
Ejemplo n.º 4
0
def test_success_create_brand_with_options():
    responses.add(responses.POST,
                  'https://api.courier.com/brands',
                  status=200,
                  content_type='application/json',
                  body='{"id": "1234", "name": "my brand"}')

    c = Courier(auth_token='123456789ABCDF')
    r = c.create_brand(name="my brand",
                       settings={},
                       id='1234',
                       snippets={
                           'format': 'handlebars',
                           'name': 'test',
                           'value': '{{test}}'
                       })

    assert r == {"id": "1234", "name": "my brand"}
Ejemplo n.º 5
0
def test_success_create_brand_idempotent():
    responses.add(responses.POST,
                  'https://api.courier.com/brands',
                  status=200,
                  content_type='application/json',
                  body='{"id": "1234", "name": "my brand"}')

    c = Courier(auth_token='123456789ABCDF')
    expiration_date = (datetime.now() + timedelta(days=7)).isoformat()
    r = c.create_brand(name="my brand",
                       settings={},
                       idempotency_key="1234ABCD",
                       idempotency_expiration=expiration_date)

    assert responses.calls[0].request.headers.get(
        'Idempotency-Key') == '1234ABCD'
    assert responses.calls[0].request.headers.get(
        'x-idempotency-expiration') == expiration_date
    assert r == {"id": "1234", "name": "my brand"}