def test_eqaulity_check_differentiate_non_identical_payments(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment_one = moyasar.Payment.fetch(id) ss.remove_stub() modified_resource = copy.deepcopy(f.payment) modified_resource.update({"amount": "5000"}) ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=modified_resource, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment_two = moyasar.Payment.fetch(id) payment_one_values = [] payment_two_values = [] for key, val in payment_one.__dict__.items(): if key != 'source': payment_one_values.append(val) if key == 'source': for k, v in val.__dict__.items(): payment_one_values.append(v) for key, val in payment_two.__dict__.items(): if key != 'source': payment_two_values.append(val) if key == 'source': for k, v in val.__dict__.items(): payment_two_values.append(v) assert payment_one_values != payment_two_values
def test_list_should_return_list_of_payment_objects(): ss.stub_server_request("get", moyasar.Payment.list_url(), resource=f.payments, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payments = moyasar.Payment.list() assert type(payments) == list assert isinstance(payments[0], moyasar.Payment)
def test_eqaulity_check_holds_among_identical_payments_only(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment_one = moyasar.Payment.fetch(id) ss.remove_stub() ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment_two = moyasar.Payment.fetch(id) payment_one_values = [] payment_two_values = [] for key, val in payment_one.__dict__.items(): if key != 'source': payment_one_values.append(val) if key == 'source': for k, v in val.__dict__.items(): payment_one_values.append(v) for key, val in payment_two.__dict__.items(): if key != 'source': payment_two_values.append(val) if key == 'source': for k, v in val.__dict__.items(): payment_two_values.append(v) assert payment_one_values == payment_two_values
def test_find_should_return_payemnt_object_if_id_is_correct(): id = '328f5dca-91ec-435d-b13f-86052a1d0f7b' ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment = moyasar.Payment.fetch(id) assert payment.id == id
def test_find_should_return_invoice_object_if_id_is_correct(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice = moyasar.Invoice.fetch(id) assert invoice.id == id
def test_list_should_return_list_of_invoice_objects(): ss.stub_server_request("get", moyasar.Invoice.list_url(), resource=f.invoices, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoices = moyasar.Invoice.list() assert type(invoices) == list assert isinstance(invoices[0], moyasar.Invoice)
def test_create_with_amount_less_than_100_cent_should_raise_validation_errror( ): modified_resource = copy.deepcopy(f.payment) modified_resource.update({"amount": 90}) ss.stub_server_request('post', moyasar.Payment.create_url(), resource=modified_resource, status=400, error_message="Validation Failed", errors={"amount": "must be greater than 99"}) assert pytest.raises(Exception)
def test_void_should_return_payment_object_upon_success(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment = moyasar.Payment.fetch(id) ss.stub_server_request("post", f'{moyasar.api_url}/payments/{payment.id}/void', resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' voided = payment.void() assert isinstance(voided, moyasar.Payment)
def test_create_should_return_intiated_payment_for_sadad_source(): params = {"amount": 1000, "currency": "SAR", "description": "Test"} ss.stub_server_request("post", moyasar.Payment.create_url(), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment = moyasar.Payment.create(params) assert isinstance(payment, moyasar.Payment) assert payment.status == "initiated" assert int(payment.amount) == params['amount'] assert payment.currency == params['currency'] assert payment.description == params['description']
def test_cancel_should_return_invoice_object_if_id_is_correct(): # copy resource to prepare a custom version for this case cancel_resource = copy.deepcopy(f.invoice) cancel_resource.update({"status": "canceled"}) id = '1b92356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=cancel_resource, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice = moyasar.Invoice.fetch(id) ss.stub_server_request("put", f'{moyasar.api_url}/invoices/{invoice.id}/cancel', resource=cancel_resource, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' canceled = invoice.cancel() assert canceled["status"] == "canceled"
def test_create_payment_for_inovice_should_be_acceptable(): ss.stub_server_request("get", moyasar.Invoice.list_url(), resource=f.invoices, status=200) invoices = moyasar.Invoice.list() first_invoice_id = '' for key, val in invoices[0].__dict__.items(): if key == "id": first_invoice_id = val modified_resource = copy.deepcopy(f.payment) modified_resource.update({"invoice_id": first_invoice_id}) ss.stub_server_request("post", moyasar.Payment.create_url(), resource=modified_resource, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment = moyasar.Payment.create(modified_resource) assert isinstance(payment, moyasar.Payment) assert payment.invoice_id == first_invoice_id
def test_update_should_update_payment_description(): # fetch to update id = '328f5dca-91ec-435d-b13f-86052a1d0f7b' ss.stub_server_request("get", moyasar.Payment.fetch_url(id), resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' payment = moyasar.Payment.fetch(id) # update fetched payment ss.stub_server_request("put", f'{moyasar.api_url}/payments/{payment.id}', resource=f.payment, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' new_description = {"description": "Test"} updated = payment.update(new_description) # simulate updated record ss.stub_server_request("post", moyasar.Payment.create_url(), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' after_updated = moyasar.Payment.create(new_description) assert updated.status_code == 200 assert new_description["description"] == after_updated.description
def test_update_should_update_invoice_description(): # fetch to update id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice = moyasar.Invoice.fetch(id) # update fetched invoice ss.stub_server_request("put", f'{moyasar.api_url}/invoices/{invoice.id}', resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' new_description = {"description": "Test"} updated = invoice.update(new_description) # simulate updated record ss.stub_server_request("post", moyasar.Invoice.create_url(), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' after_updated = moyasar.Invoice.create(new_description) assert updated.status_code == 200 assert new_description["description"] == after_updated.description
def test_eqaulity_check_holds_among_identical_invoices_only(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice_one = moyasar.Invoice.fetch(id) ss.remove_stub() ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice_two = moyasar.Invoice.fetch(id) invoice_one_values = [] for val in invoice_one.__dict__.values(): invoice_one_values.append(val) invoice_two_values = [] for val in invoice_two.__dict__.values(): invoice_two_values.append(val) assert invoice_one_values == invoice_two_values
def test_eqaulity_check_differentiate_non_identical_invoices(): id = '1b82356d-b5fd-46f8-bde9-3680d62f289a' ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=f.invoice, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice_one = moyasar.Invoice.fetch(id) ss.remove_stub() modified_resource = copy.deepcopy(f.invoice) modified_resource.update({"amount": "5000"}) ss.stub_server_request("get", moyasar.Invoice.fetch_url(id), resource=modified_resource, status=200) moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' invoice_two = moyasar.Invoice.fetch(id) invoice_one_values = [] for val in invoice_one.__dict__.values(): invoice_one_values.append(val) invoice_two_values = [] for val in invoice_two.__dict__.values(): invoice_two_values.append(val) assert invoice_one_values != invoice_two_values
def test_request_should_return_json_object(): ss.stub_server_request(method='GET', url=moyasar.api_url + '/payments', resource=f.payments, status=200) response = moyasar.request('GET', moyasar.api_url + '/payments', None) assert isinstance(response.json(), dict)