Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Oct 15, 2024
1 parent fe194fd commit 60ecc26
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/hope_api_auth/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Key: {obj.key}
Grants: {obj.grants}
Expires: {expire}
Business Areas: {areas}
Regards
Expand Down
4 changes: 2 additions & 2 deletions src/hope_payment_gateway/apps/fsp/moneygram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import phonenumbers
import requests
from phonenumbers import NumberParseException
from urllib3.connectionpool import HTTPSConnectionPool
from urllib3.exceptions import PoolError

from hope_payment_gateway.apps.core.models import Singleton
from hope_payment_gateway.apps.gateway.flows import PaymentRecordFlow
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_token(self):

try:
response = requests.get(url, headers=headers)
except HTTPSConnectionPool:
except PoolError:
self.token = None
self.token_response = None
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, wsdl_filename) -> None:
self.client.set_ns_prefix("xrsi", "http://www.westernunion.com/schema/xrsi")

def response_context(self, service_name, payload, wsdl_name=None, port=None):
response = ""
response = dict()
error = ""
format = "string"
try:
Expand Down Expand Up @@ -63,7 +63,7 @@ def response_context(self, service_name, payload, wsdl_name=None, port=None):
code = 400
logger.exception(exc)
except Exception as exc:
title = f"{exc.message} [{exc.code}]"
title = type(exc).__name__
code = 400
error = str(exc)
logger.exception(exc)
Expand Down
31 changes: 16 additions & 15 deletions src/hope_payment_gateway/apps/fsp/western_union/endpoints/das.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,19 @@ def das_delivery_services(destination_country, destination_currency, create_corr
client = WesternUnionClient("DAS_Service_H2HService.wsdl")
response = client.response_context("DAS_Service", payload, "DAS_Service_H2H", f"SOAP_HTTP_Port_{wu_env}")

context = response["content"]["MTML"]["REPLY"]["DATA_CONTEXT"]["RECORDSET"]
if create_corridors and context:
for ds in context["GETDELIVERYSERVICES"]:
if ds["SVC_CODE"] == "800":
Corridor.objects.get_or_create(
destination_country=destination_country,
destination_currency=destination_currency,
defaults={
"description": f"{destination_country}: {destination_currency}",
"template_code": ds["TEMPLT"],
},
)
if "content" in response and "MTML" in response["content"]:
context = response["content"]["MTML"]["REPLY"]["DATA_CONTEXT"]["RECORDSET"]
if create_corridors and context:
for ds in context["GETDELIVERYSERVICES"]:
if ds["SVC_CODE"] == "800":
Corridor.objects.get_or_create(
destination_country=destination_country,
destination_currency=destination_currency,
defaults={
"description": f"{destination_country}: {destination_currency}",
"template_code": ds["TEMPLT"],
},
)

return response

Expand All @@ -139,7 +140,7 @@ def das_delivery_option_template(destination_country, destination_currency, temp
client = WesternUnionClient("DAS_Service_H2HService.wsdl")
context = client.response_context("DAS_Service", payload, "DAS_Service_H2H", f"SOAP_HTTP_Port_{wu_env}")

if "content" in context:
if "content" in context and "MTML" in context["content"]:
rows = context["content"]["MTML"]["REPLY"]["DATA_CONTEXT"]["RECORDSET"]
template = {}
structure = []
Expand Down Expand Up @@ -170,7 +171,7 @@ def das_delivery_option_template(destination_country, destination_currency, temp
else:
base[structure[-1]] = [base[structure[-1]], code]
if service_provider_code:
sp, created = ServiceProviderCode.objects.get_or_create(
ServiceProviderCode.objects.get_or_create(
code=code,
description=description,
country=destination_country,
Expand All @@ -193,4 +194,4 @@ def das_delivery_option_template(destination_country, destination_currency, temp
service_provider_code = False
obj.template = template
obj.save()
return context
return context
38 changes: 29 additions & 9 deletions tests/factories/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@
from factory import fuzzy
from strategy_field.utils import fqn

from hope_api_auth.models import APIToken, Grant
from hope_api_auth.models import APILogEntry, APIToken, Grant
from hope_payment_gateway.apps.fsp.western_union.handlers import WesternUnionHandler
from hope_payment_gateway.apps.fsp.western_union.models import Corridor, ServiceProviderCode
from hope_payment_gateway.apps.gateway.models import (
DeliveryMechanism,
ExportTemplate,
FinancialServiceProvider,
FinancialServiceProviderConfig,
PaymentInstruction,
PaymentRecord,
)
from hope_payment_gateway.apps.gateway.registry import DefaultProcessor

from . import AutoRegisterModelFactory
from .user import SystemFactory, UserFactory


class CorridorFactory(factory.django.DjangoModelFactory):
class CorridorFactory(AutoRegisterModelFactory):
class Meta:
model = Corridor


class ServiceProviderCodeFactory(factory.django.DjangoModelFactory):
class ServiceProviderCodeFactory(AutoRegisterModelFactory):
class Meta:
model = ServiceProviderCode


class DeliveryMechanismFactory(factory.django.DjangoModelFactory):
class DeliveryMechanismFactory(AutoRegisterModelFactory):
code = fuzzy.FuzzyText()
name = fuzzy.FuzzyText()

class Meta:
model = DeliveryMechanism


class FinancialServiceProviderFactory(factory.django.DjangoModelFactory):
class FinancialServiceProviderFactory(AutoRegisterModelFactory):
remote_id = fuzzy.FuzzyText()
name = fuzzy.FuzzyText()
vendor_number = fuzzy.FuzzyText()
Expand All @@ -46,7 +49,7 @@ class Meta:
model = FinancialServiceProvider


class FinancialServiceProviderConfigFactory(factory.django.DjangoModelFactory):
class FinancialServiceProviderConfigFactory(AutoRegisterModelFactory):
key = fuzzy.FuzzyText()
label = fuzzy.FuzzyText()
fsp = factory.SubFactory(FinancialServiceProviderFactory)
Expand All @@ -56,7 +59,7 @@ class Meta:
model = FinancialServiceProviderConfig


class PaymentInstructionFactory(factory.django.DjangoModelFactory):
class PaymentInstructionFactory(AutoRegisterModelFactory):
fsp = factory.SubFactory(FinancialServiceProviderFactory)
system = factory.SubFactory(SystemFactory)
remote_id = fuzzy.FuzzyText()
Expand All @@ -65,7 +68,7 @@ class Meta:
model = PaymentInstruction


class PaymentRecordFactory(factory.django.DjangoModelFactory):
class PaymentRecordFactory(AutoRegisterModelFactory):
remote_id = fuzzy.FuzzyText()
record_code = fuzzy.FuzzyText()
parent = factory.SubFactory(PaymentInstructionFactory)
Expand All @@ -74,7 +77,7 @@ class Meta:
model = PaymentRecord


class APITokenFactory(factory.django.DjangoModelFactory):
class APITokenFactory(AutoRegisterModelFactory):
user = factory.SubFactory(UserFactory)
allowed_ips = ""
grants = [Grant.API_READ_ONLY]
Expand All @@ -84,3 +87,20 @@ class APITokenFactory(factory.django.DjangoModelFactory):
class Meta:
model = APIToken
django_get_or_create = ("user",)


class APILogEntryFactory(AutoRegisterModelFactory):
token = factory.SubFactory(APITokenFactory)
status_code = fuzzy.FuzzyDecimal(200, 599)

class Meta:
model = APILogEntry


class ExportTemplateFactory(AutoRegisterModelFactory):
fsp = factory.SubFactory(FinancialServiceProviderFactory)
delivery_mechanism = factory.SubFactory(DeliveryMechanismFactory)
strategy = fqn(WesternUnionHandler)

class Meta:
model = ExportTemplate
5 changes: 5 additions & 0 deletions tests/test_admin_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ def extend(self, __iterable) -> None:
"authtoken",
"social_django",
"depot",
"power_query",
"django_celery_beat",
"advanced_filters",
r"core\.User",
]
)

GLOBAL_EXCLUDED_BUTTONS = RegexList(
[
r"social.SocialProviderAdmin:test",
r"western_union.CorridorAdmin:request",
]
)

Expand Down

0 comments on commit 60ecc26

Please sign in to comment.