| 1 |
from __future__ import absolute_import, division, print_function |
| 2 |
|
| 3 |
import stripe |
| 4 |
|
| 5 |
|
| 6 |
TEST_RESOURCE_ID = "qt_123" |
| 7 |
|
| 8 |
|
| 9 |
class TestQuote(object): |
| 10 |
def test_is_listable(self, http_client_mock, stripe_mock_stripe_client): |
| 11 |
resources = stripe_mock_stripe_client.quotes.list() |
| 12 |
http_client_mock.assert_requested("get", path="/v1/quotes") |
| 13 |
assert isinstance(resources.data, list) |
| 14 |
assert isinstance(resources.data[0], stripe.Quote) |
| 15 |
|
| 16 |
def test_is_retrievable(self, http_client_mock, stripe_mock_stripe_client): |
| 17 |
resource = stripe_mock_stripe_client.quotes.retrieve(TEST_RESOURCE_ID) |
| 18 |
http_client_mock.assert_requested( |
| 19 |
"get", path="/v1/quotes/%s" % TEST_RESOURCE_ID |
| 20 |
) |
| 21 |
assert isinstance(resource, stripe.Quote) |
| 22 |
|
| 23 |
def test_is_creatable(self, http_client_mock, stripe_mock_stripe_client): |
| 24 |
resource = stripe_mock_stripe_client.quotes.create( |
| 25 |
params={"customer": "cus_123"} |
| 26 |
) |
| 27 |
http_client_mock.assert_requested( |
| 28 |
"post", path="/v1/quotes", post_data="customer=cus_123" |
| 29 |
) |
| 30 |
assert isinstance(resource, stripe.Quote) |
| 31 |
|
| 32 |
def test_is_updateable(self, http_client_mock, stripe_mock_stripe_client): |
| 33 |
resource = stripe_mock_stripe_client.quotes.update( |
| 34 |
TEST_RESOURCE_ID, params={"metadata": {"key": "value"}} |
| 35 |
) |
| 36 |
http_client_mock.assert_requested( |
| 37 |
"post", |
| 38 |
path="/v1/quotes/%s" % TEST_RESOURCE_ID, |
| 39 |
post_data="metadata[key]=value", |
| 40 |
) |
| 41 |
assert isinstance(resource, stripe.Quote) |
| 42 |
|
| 43 |
def test_can_finalize_quote( |
| 44 |
self, http_client_mock, stripe_mock_stripe_client |
| 45 |
): |
| 46 |
resource = stripe_mock_stripe_client.quotes.retrieve(TEST_RESOURCE_ID) |
| 47 |
resource = resource.finalize_quote() |
| 48 |
http_client_mock.assert_requested( |
| 49 |
"post", path="/v1/quotes/%s/finalize" % TEST_RESOURCE_ID |
| 50 |
) |
| 51 |
assert isinstance(resource, stripe.Quote) |
| 52 |
|
| 53 |
def test_can_finalize_quote_classmethod( |
| 54 |
self, http_client_mock, stripe_mock_stripe_client |
| 55 |
): |
| 56 |
resource = stripe_mock_stripe_client.quotes.finalize_quote( |
| 57 |
TEST_RESOURCE_ID |
| 58 |
) |
| 59 |
http_client_mock.assert_requested( |
| 60 |
"post", path="/v1/quotes/%s/finalize" % TEST_RESOURCE_ID |
| 61 |
) |
| 62 |
assert isinstance(resource, stripe.Quote) |
| 63 |
|
| 64 |
def test_can_cancel(self, http_client_mock, stripe_mock_stripe_client): |
| 65 |
resource = stripe_mock_stripe_client.quotes.cancel(TEST_RESOURCE_ID) |
| 66 |
http_client_mock.assert_requested( |
| 67 |
"post", path="/v1/quotes/%s/cancel" % TEST_RESOURCE_ID |
| 68 |
) |
| 69 |
assert isinstance(resource, stripe.Quote) |
| 70 |
|
| 71 |
def test_can_accept(self, http_client_mock, stripe_mock_stripe_client): |
| 72 |
resource = stripe_mock_stripe_client.quotes.accept(TEST_RESOURCE_ID) |
| 73 |
http_client_mock.assert_requested( |
| 74 |
"post", path="/v1/quotes/%s/accept" % TEST_RESOURCE_ID |
| 75 |
) |
| 76 |
assert isinstance(resource, stripe.Quote) |
| 77 |
|
| 78 |
def test_can_list_line_items( |
| 79 |
self, http_client_mock, stripe_mock_stripe_client |
| 80 |
): |
| 81 |
resources = stripe_mock_stripe_client.quotes.line_items.list( |
| 82 |
TEST_RESOURCE_ID |
| 83 |
) |
| 84 |
http_client_mock.assert_requested( |
| 85 |
"get", path="/v1/quotes/%s/line_items" % TEST_RESOURCE_ID |
| 86 |
) |
| 87 |
assert isinstance(resources.data, list) |
| 88 |
assert isinstance(resources.data[0], stripe.LineItem) |
| 89 |
|
| 90 |
def test_can_list_computed_upfront_line_items( |
| 91 |
self, http_client_mock, stripe_mock_stripe_client |
| 92 |
): |
| 93 |
resources = ( |
| 94 |
stripe_mock_stripe_client.quotes.computed_upfront_line_items.list( |
| 95 |
TEST_RESOURCE_ID |
| 96 |
) |
| 97 |
) |
| 98 |
http_client_mock.assert_requested( |
| 99 |
"get", |
| 100 |
path="/v1/quotes/%s/computed_upfront_line_items" |
| 101 |
% TEST_RESOURCE_ID, |
| 102 |
) |
| 103 |
assert isinstance(resources.data, list) |
| 104 |
assert isinstance(resources.data[0], stripe.LineItem) |
| 105 |
|
| 106 |
def test_can_pdf( |
| 107 |
self, |
| 108 |
file_stripe_mock_stripe_client, |
| 109 |
http_client_mock, |
| 110 |
): |
| 111 |
stream = file_stripe_mock_stripe_client.quotes.pdf(TEST_RESOURCE_ID) |
| 112 |
http_client_mock.assert_requested( |
| 113 |
"get", |
| 114 |
api_base=stripe.upload_api_base, |
| 115 |
path="/v1/quotes/%s/pdf" % TEST_RESOURCE_ID, |
| 116 |
) |
| 117 |
content = stream.io.read() |
| 118 |
assert content == b"Stripe binary response" |