Enhance documentation, implement Twilio OTP delivery, and update payment gateway methods. Updated AGENTS.md and README.md for clarity on ExecPlans and architecture. Added Twilio as a dependency and implemented capture/refund methods in MoyasarGateway. Improved frontend routing with react-router-dom and added authentication context. Updated styles and localization files for better user experience.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Tests for Moyasar capture and refund gateway methods."""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.payments.services.gateway import MoyasarGateway, PaymentGatewayError
|
||||
|
||||
|
||||
@patch("apps.payments.services.gateway.requests.post")
|
||||
def test_moyasar_capture_calls_api(mock_post):
|
||||
mock_post.return_value = Mock(status_code=200, content=b"{}", json=lambda: {"id": "pay_1", "status": "captured"})
|
||||
|
||||
with patch.dict("os.environ", {
|
||||
"MOYASAR_SECRET_KEY": "sk_test",
|
||||
"MOYASAR_PUBLISHABLE_KEY": "pk_test",
|
||||
}):
|
||||
gateway = MoyasarGateway()
|
||||
gateway.capture_payment("pay_1")
|
||||
|
||||
mock_post.assert_called_once()
|
||||
call_args = mock_post.call_args
|
||||
assert "pay_1/capture" in call_args[0][0]
|
||||
assert call_args[1]["auth"] == ("sk_test", "")
|
||||
|
||||
|
||||
@patch("apps.payments.services.gateway.requests.post")
|
||||
def test_moyasar_refund_calls_api(mock_post):
|
||||
mock_post.return_value = Mock(status_code=200, content=b"{}", json=lambda: {"id": "pay_1", "status": "refunded"})
|
||||
|
||||
with patch.dict("os.environ", {
|
||||
"MOYASAR_SECRET_KEY": "sk_test",
|
||||
"MOYASAR_PUBLISHABLE_KEY": "pk_test",
|
||||
}):
|
||||
gateway = MoyasarGateway()
|
||||
gateway.refund_payment("pay_1")
|
||||
|
||||
mock_post.assert_called_once()
|
||||
call_args = mock_post.call_args
|
||||
assert "pay_1/refund" in call_args[0][0]
|
||||
|
||||
|
||||
@patch("apps.payments.services.gateway.requests.post")
|
||||
def test_moyasar_capture_raises_on_error(mock_post):
|
||||
mock_post.return_value = Mock(status_code=400, content=b'{"message":"Invalid"}', json=lambda: {"message": "Invalid"})
|
||||
|
||||
with patch.dict("os.environ", {
|
||||
"MOYASAR_SECRET_KEY": "sk_test",
|
||||
"MOYASAR_PUBLISHABLE_KEY": "pk_test",
|
||||
}):
|
||||
gateway = MoyasarGateway()
|
||||
with pytest.raises(PaymentGatewayError) as exc_info:
|
||||
gateway.capture_payment("pay_1")
|
||||
assert exc_info.value.status_code == 400
|
||||
Reference in New Issue
Block a user