Skip to content

Commit

Permalink
Merge pull request #379 from Mangopay/bugfix/tests-updates
Browse files Browse the repository at this point in the history
Tests updates and fixes
  • Loading branch information
iulian03 authored Feb 5, 2025
2 parents 77cfed1 + 875cc5f commit eaf172e
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 59 deletions.
14 changes: 10 additions & 4 deletions mangopay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,16 @@ def api_value(self, value):
value = super(MoneyField, self).api_value(value)

if isinstance(value, Money):
value = {
'Currency': value.currency,
'Amount': int(value.amount)
}
if value.amount is not None:
value = {
'Currency': value.currency,
'Amount': int(value.amount)
}
else:
value = {
'Currency': value.currency,
'Amount': None
}

return value

Expand Down
2 changes: 2 additions & 0 deletions mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,8 @@ def __str__(self):


class KYC(BaseModel):
creation_date = DateTimeField(api_name='CreationDate')

class Meta:
verbose_name = 'kyc'
verbose_name_plural = 'kycs'
Expand Down
5 changes: 4 additions & 1 deletion mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class Money(object):

def __init__(self, amount="0", currency=None):
try:
self.amount = decimal.Decimal(amount)
if amount is not None:
self.amount = decimal.Decimal(amount)
else:
self.amount = None
except decimal.InvalidOperation:
raise ValueError("amount value could not be converted to "
"Decimal(): '{}'".format(amount))
Expand Down
65 changes: 37 additions & 28 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def create_new_wallet_with_money():
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down Expand Up @@ -537,16 +537,19 @@ def get_johns_card(recreate=False):
card_registration = CardRegistration(**card_params)
card_registration.save()

params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
data = {
'data': card_registration.preregistration_data,
'accessKeyRef': card_registration.access_key,
'cardNumber': '4970107111111119',
'cardExpirationDate': '1229',
'cardCvx': '123'
}
headers = {
'content-type': 'application/x-www-form-urlencoded'
}
response = APIRequest().custom_request('POST', card_registration.card_registration_url, None, None, False,
False, **params)
card_registration.registration_data = response
registration_data_response = requests.post(card_registration.card_registration_url, data=data,
headers=headers)
card_registration.registration_data = registration_data_response.text
card_registration.save()
BaseTestLive._johns_card = card_registration.card
return BaseTestLive._johns_card
Expand All @@ -561,16 +564,19 @@ def get_johns_card_3dsecure(recreate=False):
card_registration = CardRegistration(**card_params)
card_registration.save()

params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
data = {
'data': card_registration.preregistration_data,
'accessKeyRef': card_registration.access_key,
'cardNumber': '4970107111111119',
'cardExpirationDate': '1229',
'cardCvx': '123'
}
response = APIRequest().custom_request('POST', card_registration.card_registration_url, None, None, False,
False, **params)
card_registration.registration_data = response
headers = {
'content-type': 'application/x-www-form-urlencoded'
}
registration_data_response = requests.post(card_registration.card_registration_url, data=data,
headers=headers)
card_registration.registration_data = registration_data_response.text
card_registration.save()
BaseTestLive._johns_card = card_registration.card
return BaseTestLive._johns_card
Expand Down Expand Up @@ -607,16 +613,19 @@ def create_new_card_registration_for_deposit():
card_registration = CardRegistration(**card_params)
card_registration.save()

params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
data = {
'data': card_registration.preregistration_data,
'accessKeyRef': card_registration.access_key,
'cardNumber': '4970107111111119',
'cardExpirationDate': '1229',
'cardCvx': '123'
}
headers = {
'content-type': 'application/x-www-form-urlencoded'
}
response = APIRequest().custom_request('POST', card_registration.card_registration_url, None, None, False,
False, **params)
card_registration.registration_data = response
registration_data_response = requests.post(card_registration.card_registration_url, data=data,
headers=headers)
card_registration.registration_data = registration_data_response.text

return CardRegistration(**card_registration.save())

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_cardValidation(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_getCardValidation(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down
16 changes: 8 additions & 8 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def test_get_instant_conversion(self):

def test_create_conversion_quote(self):
conversion_quote = ConversionQuote()
conversion_quote.credited_funds = Money(currency='USD')
conversion_quote.credited_funds = Money(currency='USD', amount=None)
conversion_quote.debited_funds = Money(currency='GBP', amount=100)
conversion_quote.duration = 90
conversion_quote.duration = 300
conversion_quote.tag = "Created using the Mangopay Python SDK"

created_conversion_quote = conversion_quote.create_conversion_quote()
Expand All @@ -100,9 +100,9 @@ def test_create_conversion_quote(self):

def test_get_conversion_quote(self):
conversion_quote = ConversionQuote()
conversion_quote.credited_funds = Money(currency='USD')
conversion_quote.credited_funds = Money(currency='USD', amount=None)
conversion_quote.debited_funds = Money(currency='GBP', amount=100)
conversion_quote.duration = 90
conversion_quote.duration = 300
conversion_quote.tag = "Created using the Mangopay Python SDK"

created_conversion_quote = conversion_quote.create_conversion_quote()
Expand All @@ -125,9 +125,9 @@ def test_create_quoted_conversion(self):
debited_wallet = BaseTestLive.create_new_wallet_with_money()

conversion_quote = ConversionQuote()
conversion_quote.credited_funds = Money(currency='GBP')
conversion_quote.credited_funds = Money(currency='GBP', amount=None)
conversion_quote.debited_funds = Money(currency='EUR', amount=50)
conversion_quote.duration = 90
conversion_quote.duration = 300
conversion_quote.tag = "Created using the Mangopay Python SDK"
created_conversion_quote = conversion_quote.create_conversion_quote()

Expand All @@ -154,9 +154,9 @@ def test_get_quoted_conversion(self):
debited_wallet = BaseTestLive.create_new_wallet_with_money()

conversion_quote = ConversionQuote()
conversion_quote.credited_funds = Money(currency='GBP')
conversion_quote.credited_funds = Money(currency='GBP', amount=None)
conversion_quote.debited_funds = Money(currency='EUR', amount=50)
conversion_quote.duration = 90
conversion_quote.duration = 300
conversion_quote.tag = "Created using the Mangopay Python SDK"
created_conversion_quote = conversion_quote.create_conversion_quote()

Expand Down
19 changes: 13 additions & 6 deletions tests/test_kyc_document.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
from mangopay.resources import Document
from mangopay.utils import timestamp_from_datetime
from tests.test_base import BaseTestLive


class KYCDocumentTestLive(BaseTestLive):

def test_GetKycDocuments(self):
documents = Document.all()
johns_document = BaseTestLive.get_johns_kyc_document()
documents = Document.all(BeforeDate=timestamp_from_datetime(johns_document.creation_date) + 1000,
AfterDate=timestamp_from_datetime(johns_document.creation_date) - 1000)

self.assertTrue(documents)
self.assertTrue(len(documents.data) > 0)

result = Document.all(page=1, per_page=2, Sort='CreationDate:ASC')
result = Document.all(page=1, per_page=2, Sort='CreationDate:ASC',
BeforeDate=timestamp_from_datetime(johns_document.creation_date) + 1000,
AfterDate=timestamp_from_datetime(johns_document.creation_date) - 1000)

self.assertTrue(result)
self.assertTrue(len(result.data) > 0)

result2 = Document.all(page=1, per_page=2, Sort='CreationDate:DESC')
result2 = Document.all(page=1, per_page=2, Sort='CreationDate:DESC',
BeforeDate=timestamp_from_datetime(johns_document.creation_date) + 1000,
AfterDate=timestamp_from_datetime(johns_document.creation_date) - 1000)

self.assertTrue(result2)
self.assertTrue(len(result.data) > 0)
self.assertFalse(result.data[0].id == result2.data[0].id)

def test_GetKycDocument(self):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,6 @@ def test_GooglePay_GetPaymentMethodMetadata(self):
self.assertIsNotNone(result_metadata['issuer_country_code'])
self.assertIsNotNone(result_metadata['issuing_bank'])

@unittest.skip("can't be tested yet")
def test_card_preauthorized_deposit_payin(self):
deposit = self.create_new_deposit()

Expand Down Expand Up @@ -1644,7 +1643,7 @@ def test_create_partial_refund_for_payin(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_preauthorizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def test_PreAuthorizations_CreateWithAvs(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down Expand Up @@ -731,7 +731,7 @@ def test_PreAuthorizations_CreateDirect(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down Expand Up @@ -804,7 +804,7 @@ def test_PreAuthorizations_CheckCardInfo(self):
data = {
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'cardExpirationDate': '1229',
'accessKeyRef': card_registration.access_key,
'data': card_registration.preregistration_data
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import re
import unittest

import requests
import responses
Expand Down Expand Up @@ -722,6 +723,7 @@ def test_User_GetPreAuthorizationss(self):
self.assertIsNotNone(get_preauthorizations_page.data)
self.assertIsInstance(get_preauthorizations_page.data, list)

@unittest.skip("endpoint has been removed")
def test_User_get_block_status(self):
user = BaseTestLive.get_john()
block_status = user.get_block_status()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

from datetime import datetime
import pytz

from tests.test_base import BaseTest
import pytz

from mangopay.utils import Address, Money, timestamp_from_datetime
from tests.test_base import BaseTest


class UtilsTest(BaseTest):
Expand All @@ -14,8 +14,8 @@ def test_timestamp_from_datetime_timezone_unaware(self):
"""
The timestamp should be correctly calculated on a timezone unaware datetime.
"""
unaware_datetime = datetime(2016, 1, 1, 10, 0, 0, 0)
self.assertEqual(timestamp_from_datetime(unaware_datetime), 1451642400)
unaware_datetime = datetime(2025, 1, 1, 10, 0, 0)
self.assertEqual(timestamp_from_datetime(unaware_datetime), 1735725600)

def test_timestamp_from_datetime_timezone_aware(self):
"""
Expand Down
6 changes: 5 additions & 1 deletion tests/test_virtual_account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

from mangopay.resources import VirtualAccount, \
VirtualAccountAvailability
from tests.test_base import BaseTestLive
Expand Down Expand Up @@ -25,7 +27,7 @@ def test_get_all_virtual_accounts(self):
fetched = VirtualAccount.all(**{'wallet_id': wallet.id})

self.assertIsNotNone(fetched)
self.assertEqual(1, len(fetched))
self.assertTrue(len(fetched) > 0)

def test_deactivate_virtual_account(self):
virtual_account = BaseTestLive.create_new_virtual_account()
Expand All @@ -38,6 +40,8 @@ def test_deactivate_virtual_account(self):
self.assertEqual(virtual_account.id, deactivated.id)
self.assertEqual(deactivated.status, "CLOSED")

# TODO
@unittest.skip('API issue. To be re-enable once it is fixed')
def test_get_availabilities(self):
availabilities = VirtualAccountAvailability.all()
self.assertIsNotNone(availabilities)
Expand Down

0 comments on commit eaf172e

Please sign in to comment.