예제 #1
0
 def default_direct_debit_payment_data(self):
     tested_class = DirectDebit
     class_name = "DirectDebit"
     method_name = "create_payment"
     http_method_name = "post"
     basket = DirectDebit.helper_create_basket(
         reference_id="mock-basket-123",
         name="Mock item",
         market="ID",
         type="Mock type")
     args = ()
     kwargs = {
         "reference_id": "mock-direct-debit-ref-123",
         "payment_method_id": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
         "currency": "IDR",
         "amount": "60000",
         "callback_url": "http://webhook.site/",
         "idempotency_key": "idemp_key",
         "basket": basket,
     }
     params = (args, kwargs)
     url = "/direct_debits"
     expected_correct_result = payment_response()
     return (tested_class, class_name, method_name, http_method_name, url,
             params, expected_correct_result)
예제 #2
0
    def test_get_payment_status_return_correct_keys(self, DirectDebit,
                                                    payment_data):
        payment = payment_data

        payment = DirectDebit.get_payment_status(direct_debit_id=payment.id)

        self.assert_returned_object_has_same_key_as_sample_response(
            payment, payment_response())
예제 #3
0
    def test_validate_payment_otp_return_correct_keys(self, DirectDebit,
                                                      payment_data):
        payment = payment_data

        validated_payment = DirectDebit.validate_payment_otp(
            direct_debit_id=payment.id,
            otp_code="222000",
        )

        self.assert_returned_object_has_same_key_as_sample_response(
            validated_payment, payment_response())
 def default_direct_debit_payment_data(self):
     tested_class = DirectDebit
     class_name = "DirectDebit"
     method_name = "get_payment_status"
     http_method_name = "get"
     args = ()
     kwargs = {
         "direct_debit_id": "mock-direct-debit-ref-123",
     }
     params = (args, kwargs)
     url = f"/direct_debits/{kwargs['direct_debit_id']}/"
     expected_correct_result = payment_response()
     return (tested_class, class_name, method_name, http_method_name, url,
             params, expected_correct_result)
예제 #5
0
 def default_direct_debit_payment_data(self):
     tested_class = DirectDebit
     class_name = "DirectDebit"
     method_name = "validate_payment_otp"
     http_method_name = "post"
     args = ()
     kwargs = {
         "direct_debit_id": "mock-direct-debit-ref-123",
         "otp_code": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
         "x_idempotency_key": "idemp_key",
     }
     params = (args, kwargs)
     url = f"/direct_debits/{kwargs['direct_debit_id']}/validate_otp/"
     expected_correct_result = payment_response()
     return (tested_class, class_name, method_name, http_method_name, url,
             params, expected_correct_result)
예제 #6
0
class TestCreatePayment(ModelBaseTest):
    @pytest.fixture
    def default_direct_debit_payment_data(self):
        tested_class = DirectDebit
        class_name = "DirectDebit"
        method_name = "create_payment"
        http_method_name = "post"
        basket = DirectDebit.helper_create_basket(
            reference_id="mock-basket-123",
            name="Mock item",
            market="ID",
            type="Mock type")
        args = ()
        kwargs = {
            "reference_id": "mock-direct-debit-ref-123",
            "payment_method_id": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
            "currency": "IDR",
            "amount": "60000",
            "callback_url": "http://webhook.site/",
            "idempotency_key": "idemp_key",
            "basket": basket,
        }
        params = (args, kwargs)
        url = "/direct_debits"
        expected_correct_result = payment_response()
        return (tested_class, class_name, method_name, http_method_name, url,
                params, expected_correct_result)

    @pytest.fixture
    def api_requestor_request_data(self, default_direct_debit_payment_data):
        tested_class, class_name, method_name, http_method_name, url, params, _ = default_direct_debit_payment_data
        headers = {"Idempotency-key": "idemp_key"}
        body = {
            "reference_id": "mock-direct-debit-ref-123",
            "payment_method_id": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
            "currency": "IDR",
            "amount": "60000",
            "callback_url": "http://webhook.site/",
            "basket": {
                "reference_id": "mock-basket-123",
                "name": "Mock item",
                "market": "ID",
                "type": "Mock type",
            }
        }
        return (tested_class, class_name, method_name, http_method_name, url,
                params, headers, body)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_xendit_instance(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_xendit_instance(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params_and_global_xendit(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_global_config(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error_and_global_xendit(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_global_config(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_send_correct_request_to_api_requestor(self, mocker,
                                                   mock_correct_response,
                                                   api_requestor_request_data):
        self.run_send_correct_request_to_api_requestor(
            mocker, mock_correct_response, api_requestor_request_data)
class TestGetPaymentStatus(ModelBaseTest):
    @pytest.fixture
    def default_direct_debit_payment_data(self):
        tested_class = DirectDebit
        class_name = "DirectDebit"
        method_name = "get_payment_status"
        http_method_name = "get"
        args = ()
        kwargs = {
            "direct_debit_id": "mock-direct-debit-ref-123",
        }
        params = (args, kwargs)
        url = f"/direct_debits/{kwargs['direct_debit_id']}/"
        expected_correct_result = payment_response()
        return (tested_class, class_name, method_name, http_method_name, url,
                params, expected_correct_result)

    @pytest.fixture
    def api_requestor_request_data(self, default_direct_debit_payment_data):
        tested_class, class_name, method_name, http_method_name, url, params, _ = default_direct_debit_payment_data
        headers = {}
        body = {}
        return (tested_class, class_name, method_name, http_method_name, url,
                params, headers, body)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_xendit_instance(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_xendit_instance(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params_and_global_xendit(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_global_config(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error_and_global_xendit(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_global_config(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_send_correct_request_to_api_requestor(self, mocker,
                                                   mock_correct_response,
                                                   api_requestor_request_data):
        self.run_send_correct_request_to_api_requestor(
            mocker, mock_correct_response, api_requestor_request_data)
예제 #8
0
 def test_create_payment_return_correct_keys(self, payment_data):
     payment = payment_data
     self.assert_returned_object_has_same_key_as_sample_response(
         payment, payment_response())
예제 #9
0
class TestValidatePaymentOTP(ModelBaseTest):
    @pytest.fixture
    def default_direct_debit_payment_data(self):
        tested_class = DirectDebit
        class_name = "DirectDebit"
        method_name = "validate_payment_otp"
        http_method_name = "post"
        args = ()
        kwargs = {
            "direct_debit_id": "mock-direct-debit-ref-123",
            "otp_code": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
            "x_idempotency_key": "idemp_key",
        }
        params = (args, kwargs)
        url = f"/direct_debits/{kwargs['direct_debit_id']}/validate_otp/"
        expected_correct_result = payment_response()
        return (tested_class, class_name, method_name, http_method_name, url,
                params, expected_correct_result)

    @pytest.fixture
    def api_requestor_request_data(self, default_direct_debit_payment_data):
        tested_class, class_name, method_name, http_method_name, url, params, _ = default_direct_debit_payment_data
        headers = {"X-IDEMPOTENCY-KEY": "idemp_key"}
        body = {
            "otp_code": "pm-b6116aea-8c23-42d0-a1e6-33227b52fccd",
        }
        return (tested_class, class_name, method_name, http_method_name, url,
                params, headers, body)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_xendit_instance(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_xendit_instance(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_return_direct_debit_payment_on_correct_params_and_global_xendit(
            self, mocker, mock_correct_response,
            default_direct_debit_payment_data):
        self.run_success_return_test_on_global_config(
            mocker, mock_correct_response, default_direct_debit_payment_data)

    def test_raise_xendit_error_on_response_error_and_global_xendit(
            self, mocker, mock_error_request_response,
            default_direct_debit_payment_data):
        self.run_raises_error_test_on_global_config(
            mocker, mock_error_request_response,
            default_direct_debit_payment_data)

    @pytest.mark.parametrize("mock_correct_response", [payment_response()],
                             indirect=True)
    def test_send_correct_request_to_api_requestor(self, mocker,
                                                   mock_correct_response,
                                                   api_requestor_request_data):
        self.run_send_correct_request_to_api_requestor(
            mocker, mock_correct_response, api_requestor_request_data)