Пример #1
0
class TestGetDisbursement(ModelBaseTest):
    @pytest.fixture
    def default_disbursement_data(self):
        tested_class = Disbursement
        class_name = "Disbursement"
        method_name = "get"
        http_method_name = "get"
        args = ()
        kwargs = {"id": "5ef1befeecb16100179e1d05"}
        params = (args, kwargs)
        url = f"/disbursements/{kwargs['id']}"
        expected_correct_result = disbursement_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_disbursement_data):
        tested_class, class_name, method_name, http_method_name, url, params, _ = default_disbursement_data
        headers = {}
        body = {}
        return (tested_class, class_name, method_name, http_method_name, url,
                params, headers, body)

    @pytest.mark.parametrize("mock_correct_response",
                             [disbursement_response()],
                             indirect=True)
    def test_return_disbursement_on_correct_params(self, mocker,
                                                   mock_correct_response,
                                                   default_disbursement_data):
        self.run_success_return_test_on_xendit_instance(
            mocker, mock_correct_response, default_disbursement_data)

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

    @pytest.mark.parametrize("mock_correct_response",
                             [disbursement_response()],
                             indirect=True)
    def test_return_disbursement_on_correct_params_and_global_xendit(
            self, mocker, mock_correct_response, default_disbursement_data):
        self.run_success_return_test_on_global_config(
            mocker, mock_correct_response, default_disbursement_data)

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

    @pytest.mark.parametrize("mock_correct_response",
                             [disbursement_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)
Пример #2
0
    def test_get_disbursement_by_id_return_correct_keys(
            self, Disbursement, disbursement_data):
        disbursement = disbursement_data

        disbursement = Disbursement.get(id=disbursement.id)
        self.assert_returned_object_has_same_key_as_sample_response(
            disbursement, disbursement_response())
Пример #3
0
 def test_create_disbursement_return_correct_keys(self, Disbursement):
     disbursement = Disbursement.create(
         external_id="demo_1475459775872",
         bank_code="BCA",
         account_holder_name="Bob Jones",
         account_number="1231242311",
         description="Reimbursement for shoes",
         amount=17000,
     )
     self.assert_returned_object_has_same_key_as_sample_response(
         disbursement, disbursement_response())
Пример #4
0
 def default_disbursement_data(self):
     tested_class = Disbursement
     class_name = "Disbursement"
     method_name = "get"
     http_method_name = "get"
     args = ()
     kwargs = {"id": "5ef1befeecb16100179e1d05"}
     params = (args, kwargs)
     url = f"/disbursements/{kwargs['id']}"
     expected_correct_result = disbursement_response()
     return (tested_class, class_name, method_name, http_method_name, url,
             params, expected_correct_result)
 def default_disbursement_data(self):
     tested_class = Disbursement
     class_name = "Disbursement"
     method_name = "create"
     http_method_name = "post"
     args = ()
     kwargs = {
         "external_id": "demo_1475459775872",
         "bank_code": "BCA",
         "account_holder_name": "Bob Jones",
         "account_number": "1231242311",
         "description": "Reimbursement for shoes",
         "amount": 17000,
     }
     params = (args, kwargs)
     url = "/disbursements"
     expected_correct_result = disbursement_response()
     return (tested_class, class_name, method_name, http_method_name, url, params, expected_correct_result)
Пример #6
0
 def test_get_disbursement_by_external_id_return_correct_keys(
         self, Disbursement):
     disbursement = Disbursement.get_by_ext_id(
         external_id="demo_1475459775872")
     self.assert_returned_object_has_same_key_as_sample_response(
         disbursement[0], disbursement_response())
Пример #7
0
 def test_get_disbursement_by_id_return_correct_keys(self, Disbursement):
     disbursement = Disbursement.get(id="5ef1befeecb16100179e1d05")
     self.assert_returned_object_has_same_key_as_sample_response(
         disbursement, disbursement_response())
class TestCreateDisbursement(ModelBaseTest):
    @pytest.fixture
    def default_disbursement_data(self):
        tested_class = Disbursement
        class_name = "Disbursement"
        method_name = "create"
        http_method_name = "post"
        args = ()
        kwargs = {
            "external_id": "demo_1475459775872",
            "bank_code": "BCA",
            "account_holder_name": "Bob Jones",
            "account_number": "1231242311",
            "description": "Reimbursement for shoes",
            "amount": 17000,
        }
        params = (args, kwargs)
        url = "/disbursements"
        expected_correct_result = disbursement_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_disbursement_data):
        tested_class, class_name, method_name, http_method_name, url, params, _ = default_disbursement_data
        headers = {}
        body = {
            "external_id": "demo_1475459775872",
            "bank_code": "BCA",
            "account_holder_name": "Bob Jones",
            "account_number": "1231242311",
            "description": "Reimbursement for shoes",
            "amount": 17000,
            "email_bcc": [],
            "email_cc": [],
            "email_to": [],
        }
        return (tested_class, class_name, method_name, http_method_name, url, params, headers, body)

    @pytest.mark.parametrize("mock_correct_response", [disbursement_response()], indirect=True)
    def test_return_disbursement_on_correct_params(
        self, mocker, mock_correct_response, default_disbursement_data
    ):
        self.run_success_return_test_on_xendit_instance(mocker, mock_correct_response, default_disbursement_data)

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

    @pytest.mark.parametrize("mock_correct_response", [disbursement_response()], indirect=True)
    def test_return_disbursement_on_correct_params_and_global_xendit(
        self, mocker, mock_correct_response, default_disbursement_data
    ):
        self.run_success_return_test_on_global_config(mocker, mock_correct_response, default_disbursement_data)

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

    @pytest.mark.parametrize("mock_correct_response", [disbursement_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)
Пример #9
0
 def test_create_disbursement_return_correct_keys(self, disbursement_data):
     disbursement = disbursement_data
     self.assert_returned_object_has_same_key_as_sample_response(
         disbursement, disbursement_response())