Begin implementing per-requisition configuration
This commit is contained in:
32
core/tests/helpers.py
Normal file
32
core/tests/helpers.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import logging
|
||||
|
||||
from core.clients.aggregator import AggregatorClient
|
||||
from core.models import Aggregator, Platform, User
|
||||
|
||||
|
||||
class AggregatorPlatformMixin:
|
||||
def setUp(self):
|
||||
logging.disable(logging.CRITICAL)
|
||||
self.user = User.objects.create_user(
|
||||
username="testuser", email="test@example.com", password="test"
|
||||
)
|
||||
self.aggregator = Aggregator.objects.create(
|
||||
user=self.user,
|
||||
name="Test",
|
||||
service="nordigen",
|
||||
secret_id="a",
|
||||
secret_key="a",
|
||||
)
|
||||
|
||||
self.agg_client = AggregatorClient()
|
||||
self.agg_client.instance = self.aggregator
|
||||
|
||||
self.platform = Platform.objects.create(
|
||||
user=self.user,
|
||||
name="Test",
|
||||
service="agora",
|
||||
token="a",
|
||||
password="a",
|
||||
otp_token="a",
|
||||
username="myuser",
|
||||
)
|
||||
106
core/tests/test_platform.py
Normal file
106
core/tests/test_platform.py
Normal file
@@ -0,0 +1,106 @@
|
||||
from django.test import TransactionTestCase
|
||||
|
||||
from core.clients.platforms.agora import AgoraClient
|
||||
from core.models import Ad, Asset, Provider
|
||||
from core.tests.helpers import AggregatorPlatformMixin
|
||||
|
||||
|
||||
class TestPlatform(AggregatorPlatformMixin, TransactionTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.aggregator.account_info = {
|
||||
"MONZO_MONZGB2L": [
|
||||
{
|
||||
"resourceId": "ssss",
|
||||
"currency": "GBP",
|
||||
"ownerName": "JSNOW LIMITED",
|
||||
"cashAccountType": "CACC",
|
||||
"status": "enabled",
|
||||
"maskedPan": None,
|
||||
"details": "Private Limited Company",
|
||||
"bban": "ssss",
|
||||
"name": None,
|
||||
"product": None,
|
||||
"bic": None,
|
||||
"recipient": "TODO",
|
||||
"account_id": "s-s-s-s-s",
|
||||
"aggregator_id": str(self.aggregator.id),
|
||||
"requisition_id": "3ba3e65d-f44c-4c4e-9e28-08cc080830f6",
|
||||
"account_number": {"sort_code": "04-00-04", "number": "00000002"},
|
||||
},
|
||||
{
|
||||
"resourceId": "ssss",
|
||||
"currency": "GBP",
|
||||
"ownerName": "John Snow Smith",
|
||||
"cashAccountType": "CACC",
|
||||
"status": "enabled",
|
||||
"maskedPan": None,
|
||||
"details": "Personal Account",
|
||||
"bban": "ssss",
|
||||
"name": None,
|
||||
"product": None,
|
||||
"bic": None,
|
||||
"recipient": "TODO",
|
||||
"account_id": "s-s-s-s-s",
|
||||
"aggregator_id": str(self.aggregator.id),
|
||||
"requisition_id": "3ba3e65d-f44c-4c4e-9e28-08cc080830f6",
|
||||
"account_number": {"sort_code": "04-00-04", "number": "00000001"},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
self.aggregator.save()
|
||||
|
||||
self.plat_client = AgoraClient(self.platform)
|
||||
|
||||
asset = Asset.objects.create(
|
||||
code="XMR",
|
||||
name="Monero",
|
||||
)
|
||||
|
||||
provider = Provider.objects.create(
|
||||
code="REVOLUT",
|
||||
name="Revolut",
|
||||
)
|
||||
|
||||
self.ad = Ad.objects.create(
|
||||
user=self.user,
|
||||
name="Test",
|
||||
text="Ad text",
|
||||
payment_details="Payment details",
|
||||
payment_details_real="Payment details real",
|
||||
payment_method_details="Payment method details",
|
||||
dist_list="",
|
||||
asset_list=[asset],
|
||||
provider_list=[provider],
|
||||
platforms=[self.platform],
|
||||
aggregators=[self.aggregator],
|
||||
send_reference=True,
|
||||
visible=True,
|
||||
enabled=True,
|
||||
)
|
||||
|
||||
def test_get_valid_account_details(self):
|
||||
result = self.plat_client.get_valid_account_details(self.ad)
|
||||
|
||||
def test_get_matching_account_details(self):
|
||||
result = self.plat_client.get_matching_account_details("GBP", self.ad)
|
||||
|
||||
def test_format_payment_details(self):
|
||||
account_info = self.plat_client.get_matching_account_details("GBP", self.ad)
|
||||
result = self.plat_client.format_payment_details(
|
||||
"GBP",
|
||||
account_info,
|
||||
self.ad,
|
||||
real=False,
|
||||
)
|
||||
|
||||
def test_format_payment_details_real(self):
|
||||
account_info = self.plat_client.get_matching_account_details("GBP", self.ad)
|
||||
result = self.plat_client.format_payment_details(
|
||||
"GBP",
|
||||
account_info,
|
||||
self.ad,
|
||||
real=True,
|
||||
)
|
||||
@@ -1,38 +1,14 @@
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import TransactionTestCase
|
||||
|
||||
from core.clients.aggregator import AggregatorClient
|
||||
from core.models import Aggregator, Platform, Trade, Transaction, User
|
||||
from core.models import Trade, Transaction
|
||||
from core.tests.helpers import AggregatorPlatformMixin
|
||||
|
||||
|
||||
class TestTransactions(TransactionTestCase):
|
||||
class TestTransactions(AggregatorPlatformMixin, TransactionTestCase):
|
||||
def setUp(self):
|
||||
logging.disable(logging.CRITICAL)
|
||||
self.user = User.objects.create_user(
|
||||
username="testuser", email="test@example.com", password="test"
|
||||
)
|
||||
self.aggregator = Aggregator.objects.create(
|
||||
user=self.user,
|
||||
name="Test",
|
||||
service="nordigen",
|
||||
secret_id="a",
|
||||
secret_key="a",
|
||||
)
|
||||
|
||||
self.agg_client = AggregatorClient()
|
||||
self.agg_client.instance = self.aggregator
|
||||
|
||||
self.platform = Platform.objects.create(
|
||||
user=self.user,
|
||||
name="Test",
|
||||
service="agora",
|
||||
token="a",
|
||||
password="a",
|
||||
otp_token="a",
|
||||
username="myuser",
|
||||
)
|
||||
super().setUp()
|
||||
self.transaction = Transaction.objects.create(
|
||||
aggregator=self.aggregator,
|
||||
account_id="my account id",
|
||||
|
||||
Reference in New Issue
Block a user