Skip to content

Commit

Permalink
Adicionando testes para o resource bills
Browse files Browse the repository at this point in the history
  • Loading branch information
allisson committed Apr 21, 2017
1 parent 0f69345 commit 3042bfb
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 20 deletions.
36 changes: 36 additions & 0 deletions resources/cassettes/test_bill_create.yaml
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"customer_id": 2481258, "code": "my-first-bill", "installments": 1, "payment_method_code":
"credit_card", "bill_items": [{"product_code": "product-1", "amount": 100.0}],
"payment_profile": {"id": 2284520}}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['206']
Content-Type: [application/json]
User-Agent: [python-requests/2.13.0]
method: POST
uri: https://app.vindi.com.br/api/v1/bills
response:
body: {string: "{\"bill\":{\"id\":7064381,\"code\":\"my-first-bill\",\"amount\":\"100.0\",\"installments\":1,\"status\":\"pending\",\"seen_at\":null,\"billing_at\":null,\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"url\":\"https://app.vindi.com.br/customer/bills/7064381?token=db96ea6a-561f-44ab-a040-b0909c739564\",\"created_at\":\"2017-04-21T09:18:55.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"bill_items\":[{\"id\":8362517,\"amount\":\"100.0\",\"quantity\":null,\"pricing_range_id\":null,\"description\":null,\"pricing_schema\":null,\"product\":{\"id\":82534,\"name\":\"Product
1\",\"code\":\"product-1\"},\"product_item\":null,\"discount\":null}],\"charges\":[{\"id\":6803582,\"amount\":\"100.0\",\"status\":\"pending\",\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"paid_at\":null,\"installments\":1,\"attempt_count\":0,\"next_attempt\":null,\"print_url\":null,\"created_at\":\"2017-04-21T09:18:56.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"last_transaction\":null,\"payment_method\":{\"id\":17293,\"public_name\":\"Cart\xE3o
de cr\xE9dito\",\"name\":\"Cart\xE3o de cr\xE9dito\",\"code\":\"credit_card\",\"type\":\"PaymentMethod::CreditCard\"}}],\"customer\":{\"id\":2481258,\"name\":\"John
Doe\",\"email\":\"john@doe.com\",\"code\":null},\"period\":null,\"subscription\":null,\"metadata\":{},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}}}"}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Connection: [keep-alive]
Content-Length: ['1561']
Content-Type: [application/json; charset=UTF-8]
Date: ['Fri, 21 Apr 2017 12:18:56 GMT']
ETag: [W/"4c7430bea9c7892cad07e10dbefd87cc"]
Rate-Limit-Limit: ['120']
Rate-Limit-Remaining: ['119']
Rate-Limit-Reset: ['1492777195']
Server: [nginx]
Vindi-Merchant-Id: ['5963']
X-Request-Id: [885764eb-c2f6-444d-b1ba-fbf217f9ec45]
X-Runtime: ['0.296408']
status: {code: 201, message: Created}
version: 1
34 changes: 34 additions & 0 deletions resources/cassettes/test_bill_destroy.yaml
@@ -0,0 +1,34 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['0']
Content-Type: [application/json]
User-Agent: [python-requests/2.13.0]
method: DELETE
uri: https://app.vindi.com.br/api/v1/bills/7071692
response:
body: {string: "{\"bill\":{\"id\":7071692,\"code\":\"my-third-bill\",\"amount\":\"0.0\",\"installments\":1,\"status\":\"canceled\",\"seen_at\":null,\"billing_at\":\"2017-04-21T00:00:00.000-03:00\",\"due_at\":\"2017-04-21T23:59:59.000-03:00\",\"url\":\"https://app.vindi.com.br/customer/bills/7071692?token=4acee607-f2b6-433a-8134-67be26553f97\",\"created_at\":\"2017-04-21T11:08:49.000-03:00\",\"updated_at\":\"2017-04-21T11:49:06.666-03:00\",\"bill_items\":[{\"id\":8371854,\"amount\":\"100.0\",\"quantity\":null,\"pricing_range_id\":null,\"description\":null,\"pricing_schema\":null,\"product\":{\"id\":82534,\"name\":\"Product
1\",\"code\":\"product-1\"},\"product_item\":null,\"discount\":null}],\"charges\":[{\"id\":6810651,\"amount\":\"100.0\",\"status\":\"canceled\",\"due_at\":\"2017-04-21T23:59:59.000-03:00\",\"paid_at\":null,\"installments\":1,\"attempt_count\":0,\"next_attempt\":null,\"print_url\":null,\"created_at\":\"2017-04-21T11:08:49.000-03:00\",\"updated_at\":\"2017-04-21T11:49:06.000-03:00\",\"last_transaction\":null,\"payment_method\":{\"id\":17293,\"public_name\":\"Cart\xE3o
de cr\xE9dito\",\"name\":\"Cart\xE3o de cr\xE9dito\",\"code\":\"credit_card\",\"type\":\"PaymentMethod::CreditCard\"}}],\"customer\":{\"id\":2481258,\"name\":\"John
Doe\",\"email\":\"john@doe.com\",\"code\":null},\"period\":null,\"subscription\":null,\"metadata\":{},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}}}"}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Connection: [keep-alive]
Content-Length: ['1588']
Content-Type: [application/json; charset=UTF-8]
Date: ['Fri, 21 Apr 2017 14:49:06 GMT']
ETag: [W/"cd9afb6ea9fb00294280b967826cc5bd"]
Rate-Limit-Limit: ['120']
Rate-Limit-Remaining: ['118']
Rate-Limit-Reset: ['1492786149']
Server: [nginx]
Vindi-Merchant-Id: ['5963']
X-Request-Id: [fbe252be-cb20-4f66-b0bb-baf2ef04f1ac]
X-Runtime: ['0.112778']
status: {code: 200, message: OK}
version: 1
35 changes: 35 additions & 0 deletions resources/cassettes/test_bill_list.yaml
@@ -0,0 +1,35 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Type: [application/json]
User-Agent: [python-requests/2.13.0]
method: GET
uri: https://app.vindi.com.br/api/v1/bills
response:
body: {string: "{\"bills\":[{\"id\":7064381,\"code\":\"my-first-bill\",\"amount\":\"100.0\",\"installments\":1,\"status\":\"pending\",\"seen_at\":null,\"billing_at\":null,\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"url\":\"https://app.vindi.com.br/customer/bills/7064381?token=db96ea6a-561f-44ab-a040-b0909c739564\",\"created_at\":\"2017-04-21T09:18:55.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"bill_items\":[{\"id\":8362517,\"amount\":\"100.0\",\"quantity\":null,\"pricing_range_id\":null,\"description\":null,\"pricing_schema\":null,\"product\":{\"id\":82534,\"name\":\"Product
1\",\"code\":\"product-1\"},\"product_item\":null,\"discount\":null}],\"charges\":[{\"id\":6803582,\"amount\":\"100.0\",\"status\":\"pending\",\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"paid_at\":null,\"installments\":1,\"attempt_count\":0,\"next_attempt\":null,\"print_url\":null,\"created_at\":\"2017-04-21T09:18:56.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"last_transaction\":null,\"payment_method\":{\"id\":17293,\"public_name\":\"Cart\xE3o
de cr\xE9dito\",\"name\":\"Cart\xE3o de cr\xE9dito\",\"code\":\"credit_card\",\"type\":\"PaymentMethod::CreditCard\"}}],\"customer\":{\"id\":2481258,\"name\":\"John
Doe\",\"email\":\"john@doe.com\",\"code\":null},\"period\":null,\"subscription\":null,\"metadata\":{},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}}]}"}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Connection: [keep-alive]
Content-Length: ['1564']
Content-Type: [application/json; charset=UTF-8]
Date: ['Fri, 21 Apr 2017 12:21:51 GMT']
ETag: [W/"bdd79778039b209ced3f464578a4a527"]
Per-Page: ['25']
Rate-Limit-Limit: ['120']
Rate-Limit-Remaining: ['119']
Rate-Limit-Reset: ['1492777371']
Server: [nginx]
Total: ['1']
Vindi-Merchant-Id: ['5963']
X-Request-Id: [5e28c6d7-9dd1-42ec-87e9-308a00a6ccc2]
X-Runtime: ['0.040105']
status: {code: 200, message: OK}
version: 1
33 changes: 33 additions & 0 deletions resources/cassettes/test_bill_retrieve.yaml
@@ -0,0 +1,33 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Type: [application/json]
User-Agent: [python-requests/2.13.0]
method: GET
uri: https://app.vindi.com.br/api/v1/bills/7064381
response:
body: {string: "{\"bill\":{\"id\":7064381,\"code\":\"my-first-bill\",\"amount\":\"100.0\",\"installments\":1,\"status\":\"pending\",\"seen_at\":null,\"billing_at\":null,\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"url\":\"https://app.vindi.com.br/customer/bills/7064381?token=db96ea6a-561f-44ab-a040-b0909c739564\",\"created_at\":\"2017-04-21T09:18:55.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"bill_items\":[{\"id\":8362517,\"amount\":\"100.0\",\"quantity\":null,\"pricing_range_id\":null,\"description\":null,\"pricing_schema\":null,\"product\":{\"id\":82534,\"name\":\"Product
1\",\"code\":\"product-1\"},\"product_item\":null,\"discount\":null}],\"charges\":[{\"id\":6803582,\"amount\":\"100.0\",\"status\":\"pending\",\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"paid_at\":null,\"installments\":1,\"attempt_count\":0,\"next_attempt\":null,\"print_url\":null,\"created_at\":\"2017-04-21T09:18:56.000-03:00\",\"updated_at\":\"2017-04-21T09:18:56.000-03:00\",\"last_transaction\":null,\"payment_method\":{\"id\":17293,\"public_name\":\"Cart\xE3o
de cr\xE9dito\",\"name\":\"Cart\xE3o de cr\xE9dito\",\"code\":\"credit_card\",\"type\":\"PaymentMethod::CreditCard\"}}],\"customer\":{\"id\":2481258,\"name\":\"John
Doe\",\"email\":\"john@doe.com\",\"code\":null},\"period\":null,\"subscription\":null,\"metadata\":{},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}}}"}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Connection: [keep-alive]
Content-Length: ['1561']
Content-Type: [application/json; charset=UTF-8]
Date: ['Fri, 21 Apr 2017 12:23:05 GMT']
ETag: [W/"4c7430bea9c7892cad07e10dbefd87cc"]
Rate-Limit-Limit: ['120']
Rate-Limit-Remaining: ['119']
Rate-Limit-Reset: ['1492777445']
Server: [nginx]
Vindi-Merchant-Id: ['5963']
X-Request-Id: [cdbd7ba3-40f3-4937-97d5-549074eac0bd]
X-Runtime: ['0.040206']
status: {code: 200, message: OK}
version: 1
36 changes: 36 additions & 0 deletions resources/cassettes/test_bill_update.yaml
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"code": "first-bill"}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['22']
Content-Type: [application/json]
User-Agent: [python-requests/2.13.0]
method: PUT
uri: https://app.vindi.com.br/api/v1/bills/7064381
response:
body: {string: "{\"bill\":{\"id\":7064381,\"code\":\"first-bill\",\"amount\":\"100.0\",\"installments\":1,\"status\":\"paid\",\"seen_at\":\"2017-04-21T09:25:17.000-03:00\",\"billing_at\":null,\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"url\":\"https://app.vindi.com.br/customer/bills/7064381?token=db96ea6a-561f-44ab-a040-b0909c739564\",\"created_at\":\"2017-04-21T09:18:55.000-03:00\",\"updated_at\":\"2017-04-21T11:44:02.492-03:00\",\"bill_items\":[{\"id\":8362517,\"amount\":\"100.0\",\"quantity\":null,\"pricing_range_id\":null,\"description\":null,\"pricing_schema\":null,\"product\":{\"id\":82534,\"name\":\"Product
1\",\"code\":\"product-1\"},\"product_item\":null,\"discount\":null}],\"charges\":[{\"id\":6803582,\"amount\":\"100.0\",\"status\":\"paid\",\"due_at\":\"2017-04-24T23:59:59.000-03:00\",\"paid_at\":\"2017-04-21T10:40:52.000-03:00\",\"installments\":1,\"attempt_count\":1,\"next_attempt\":null,\"print_url\":null,\"created_at\":\"2017-04-21T09:18:56.000-03:00\",\"updated_at\":\"2017-04-21T10:40:52.000-03:00\",\"last_transaction\":{\"id\":10384095,\"transaction_type\":\"charge\",\"status\":\"success\",\"amount\":\"100.0\",\"installments\":1,\"gateway_message\":\"Transacao
aprovada\",\"gateway_response_code\":\"\",\"gateway_authorization\":\"2C2B04FE23B6958DF90E72AADEA3AD87\",\"gateway_transaction_id\":\"dacbe4d7-591c-4949-ae6e-5932aa2501be\",\"gateway_response_fields\":{\"test_auth\":\"cfa315f873c37a4cfca1\"},\"fraud_detector_score\":null,\"fraud_detector_status\":null,\"fraud_detector_id\":null,\"created_at\":\"2017-04-21T10:40:52.000-03:00\",\"gateway\":{\"id\":10371,\"connector\":\"test\"},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}},\"payment_method\":{\"id\":17293,\"public_name\":\"Cart\xE3o
de cr\xE9dito\",\"name\":\"Cart\xE3o de cr\xE9dito\",\"code\":\"credit_card\",\"type\":\"PaymentMethod::CreditCard\"}}],\"customer\":{\"id\":2481258,\"name\":\"John
Doe\",\"email\":\"john@doe.com\",\"code\":null},\"period\":null,\"subscription\":null,\"metadata\":{},\"payment_profile\":{\"id\":2284520,\"holder_name\":\"JOHN
DOE\",\"registry_code\":null,\"bank_branch\":null,\"bank_account\":null,\"card_expiration\":\"2020-12-31T23:59:59.000-02:00\",\"card_number_first_six\":\"555555\",\"card_number_last_four\":\"5557\",\"token\":\"ba3cf5f2-143f-44df-b09e-0bc69dfb7a96\",\"created_at\":\"2017-04-20T08:59:01.000-03:00\",\"payment_company\":{\"id\":1,\"name\":\"MasterCard\",\"code\":\"mastercard\"}}}}"}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Connection: [keep-alive]
Content-Length: ['2510']
Content-Type: [application/json; charset=UTF-8]
Date: ['Fri, 21 Apr 2017 14:44:02 GMT']
ETag: [W/"6a48b84d304c981e175ebf9f46aedcc9"]
Rate-Limit-Limit: ['120']
Rate-Limit-Remaining: ['119']
Rate-Limit-Reset: ['1492785902']
Server: [nginx]
Vindi-Merchant-Id: ['5963']
X-Request-Id: [092d54bc-c315-4ee3-a0b0-7eb239f08202]
X-Runtime: ['0.099385']
status: {code: 200, message: OK}
version: 1
18 changes: 18 additions & 0 deletions tests/conftest.py
Expand Up @@ -87,3 +87,21 @@ def payment_profile_data():
'payment_company_code': 'mastercard',
'customer_id': 2481258
}


@pytest.fixture
def bill_data():
return {
'id': 7064381,
'customer_id': 2481258,
'code': 'my-first-bill',
'installments': 1,
'payment_method_code': 'credit_card',
'bill_items': [{
'product_code': 'product-1',
'amount': 100.00
}],
'payment_profile': {
'id': 2284520
}
}
1 change: 1 addition & 0 deletions tests/test_api.py
Expand Up @@ -6,3 +6,4 @@ def test_get_api_instance():
assert api.api_root_url == 'https://app.vindi.com.br/api/v1/'
assert api.headers['Authorization'] == 'Basic Og=='
assert api.headers['Content-Type'] == 'application/json'
assert api.json_encode_body
42 changes: 42 additions & 0 deletions tests/test_api_resources.py
Expand Up @@ -141,3 +141,45 @@ def test_payment_profiles_destroy(api, payment_profile_data):
assert response.status_code == status.HTTP_200_OK
assert response.body['payment_profile']['id'] == payment_profile_data['id']
assert response.body['payment_profile']['status'] == 'inactive'


@vcr.use_cassette()
def test_bill_create(api, bill_data):
body = bill_data
response = api.bills.create(body=body)
assert response.status_code == status.HTTP_201_CREATED
assert response.body['bill']['id'] == bill_data['id']


@vcr.use_cassette()
def test_bill_list(api):
response = api.bills.list()
assert response.status_code == status.HTTP_200_OK
assert 'bills' in response.body


@vcr.use_cassette()
def test_bill_retrieve(api, bill_data):
response = api.bills.retrieve(bill_data['id'])
assert response.status_code == status.HTTP_200_OK
assert response.body['bill']['id'] == bill_data['id']


@vcr.use_cassette()
def test_bill_update(api, bill_data):
body = {
'code': 'first-bill'
}
response = api.bills.update(bill_data['id'], body=body)
assert response.status_code == status.HTTP_200_OK
assert response.body['bill']['id'] == bill_data['id']
assert response.body['bill']['code'] == body['code']


@vcr.use_cassette()
def test_bill_destroy(api, bill_data):
id = 7071692
response = api.bills.destroy(id)
assert response.status_code == status.HTTP_200_OK
assert response.body['bill']['id'] == id
assert response.body['bill']['status'] == 'canceled'

0 comments on commit 3042bfb

Please sign in to comment.