Ejemplo n.º 1
0
    def test_handle_connection_error(self):
        payment_data = {"description": "test"}
        complaint_params = {"test": "test"}

        with patch("payments.utils.requests") as requests_mock, \
             patch("payments.logging.push_payment_message") as push_payment_message:

            requests_mock.get.side_effect = requests.exceptions.ConnectionError()

            process_payment_complaint_data.retry = Mock(side_effect=Retry)
            with self.assertRaises(Retry):
                process_payment_complaint_data(
                    complaint_params=complaint_params,
                    payment_data=payment_data,
                )

            self.assertEqual(
                push_payment_message.mock_calls,
                [
                    call(payment_data, PAYMENTS_GET_COMPLAINT_EXCEPTION, ANY),
                ]
            )

        process_payment_complaint_data.retry.assert_called_once_with(
            countdown=DEFAULT_RETRY_AFTER,
            exc=requests_mock.get.side_effect
        )
Ejemplo n.º 2
0
    def test_handle_404_response(self):
        payment_data = {"description": "test"}
        complaint_params = {"test": "test"}
        cookies = {"TEST_COOKIE": "TEST_COOKIE_VALUE"}

        process_payment_complaint_data.retry = Mock(
            side_effect=Retry
        )

        with patch("payments.utils.requests") as requests_mock, \
             patch("payments.logging.push_payment_message") as push_payment_message:

            requests_mock.get.return_value = Mock(
                status_code=404,
                cookies=Mock(get_dict=Mock(return_value=cookies)),
                headers={}
            )

            with self.assertRaises(Retry):
                process_payment_complaint_data(
                    complaint_params=complaint_params,
                    payment_data=payment_data,
                )

            self.assertEqual(
                push_payment_message.mock_calls,
                [
                    call(payment_data, PAYMENTS_GET_COMPLAINT_CODE_ERROR, ANY),
                ]
            )

        process_payment_complaint_data.retry.assert_called_once_with(
            countdown=DEFAULT_RETRY_AFTER
        )
Ejemplo n.º 3
0
    def test_handle_200_response_invalid_value_currency(self, process_payment_complaint_patch):
        payment_data = {
            "description": "test",
            "amount": "2000",
            "currency": "USD"
        }
        complaint_params = {
            "tender_id": "test_tender_id",
            "complaint_id": "test_complaint_id"
        }
        cookies = {"TEST_COOKIE": "TEST_COOKIE_VALUE"}

        with patch("payments.utils.requests") as requests_mock, \
             patch("payments.logging.push_payment_message") as push_payment_message:

            requests_mock.get.return_value = Mock(
                status_code=200,
                cookies=Mock(get_dict=Mock(return_value=cookies)),
                json=Mock(return_value={
                    "data": {
                        "id": "test_complaint_id",
                        "status": "draft",
                        "value": {
                            "amount": 2000.0,
                            "currency": "UAH"
                        }
                    },
                })
            )

            process_payment_complaint_data(
                complaint_params=complaint_params,
                payment_data=payment_data,
            )

            self.assertEqual(
                push_payment_message.mock_calls,
                [
                    call(payment_data, PAYMENTS_GET_COMPLAINT_SUCCESS, ANY),
                    call(payment_data, PAYMENTS_INVALID_CURRENCY, ANY),
                ]
            )

        process_payment_complaint_patch.apply_async.assert_called_once_with(
            kwargs=dict(
                payment_data=payment_data,
                complaint_params=complaint_params,
                patch_data={"status": STATUS_COMPLAINT_MISTAKEN},
                cookies=cookies
            )
        )