Skip to content

Commit

Permalink
Merge pull request #360 from Mangopay/feature/enable-reports-tests
Browse files Browse the repository at this point in the history
enabled test_reports.py and addes missing fields to ReportTransactionFilters
  • Loading branch information
iulian03 authored May 31, 2024
2 parents 5ae9978 + 68d721a commit b5e106f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
18 changes: 18 additions & 0 deletions mangopay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,21 @@ def python_value(self, value):
if value is not None:
local_min_debited_funds_amount = ''
local_max_debited_funds_amount = ''
local_min_fees_amount = ''
local_max_fees_amount = ''

if 'MinDebitedFundsAmount' in value and value['MinDebitedFundsAmount']:
local_min_debited_funds_amount = int(value['MinDebitedFundsAmount'])

if 'MaxDebitedFundsAmount' in value and value['MaxDebitedFundsAmount']:
local_max_debited_funds_amount = int(value['MaxDebitedFundsAmount'])

if 'MinFeesAmount' in value and value['MinFeesAmount']:
local_min_fees_amount = int(value['MinFeesAmount'])

if 'MaxFeesAmount' in value and value['MaxFeesAmount']:
local_max_fees_amount = int(value['MaxFeesAmount'])

author_id = None
wallet_id = None
if 'AuthorId' in value:
Expand All @@ -361,6 +369,11 @@ def python_value(self, value):
min_debited_funds_currency=value['MinDebitedFundsCurrency'],
max_debited_funds_amount=local_max_debited_funds_amount,
max_debited_funds_currency=value['MaxDebitedFundsCurrency'],
result_code=value['ResultCode'],
min_fees_amount=local_min_fees_amount,
min_fees_currency=value['MinFeesCurrency'],
max_fees_amount=local_max_fees_amount,
max_fees_currency=value['MaxFeesCurrency'],
author_id=author_id, wallet_id=wallet_id
)
return value
Expand Down Expand Up @@ -390,6 +403,11 @@ def api_value(self, value):
'MinDebitedFundsCurrency': value.min_debited_funds_currency,
'MaxDebitedFundsAmount': value.max_debited_funds_amount,
'MaxDebitedFundsCurrency': value.max_debited_funds_currency,
'ResultCode': value.result_code,
'MinFeesAmount': value.min_fees_amount,
'MinFeesCurrency': value.min_fees_currency,
'MaxFeesAmount': value.max_fees_amount,
'MaxFeesCurrency': value.max_fees_currency,
'AuthorId': value.author_id,
'WalletId': value.wallet_id,
}
Expand Down
15 changes: 13 additions & 2 deletions mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def __eq__(self, other):
class ReportTransactionsFilters(object):
def __init__(self, before_date=None, after_date=None, transaction_type=None, status=None, nature=None,
min_debited_funds_amount=None, min_debited_funds_currency=None, max_debited_funds_amount=None,
max_debited_funds_currency=None, author_id=None, wallet_id=None):
max_debited_funds_currency=None, author_id=None, wallet_id=None, result_code=None,
min_fees_amount=None, min_fees_currency=None, max_fees_amount=None, max_fees_currency=None):
self.before_date = before_date
self.after_date = after_date
self.transaction_type = transaction_type
Expand All @@ -398,6 +399,11 @@ def __init__(self, before_date=None, after_date=None, transaction_type=None, sta
self.max_debited_funds_currency = max_debited_funds_currency
self.author_id = author_id
self.wallet_id = wallet_id
self.result_code = result_code
self.min_fees_amount = min_fees_amount
self.min_fees_currency = min_fees_currency
self.max_fees_amount = max_fees_amount
self.max_fees_currency = max_fees_currency

def __eq__(self, other):
if isinstance(other, ReportTransactionsFilters):
Expand All @@ -411,7 +417,12 @@ def __eq__(self, other):
(self.max_debited_funds_amount == other.max_debited_funds_amount) and
(self.max_debited_funds_currency == other.max_debited_funds_currency) and
(self.author_id == other.author_id) and
(self.wallet_id == other.wallet_id)
(self.wallet_id == other.wallet_id) and
(self.result_code == other.result_code) and
(self.min_fees_amount == other.min_fees_amount) and
(self.min_fees_currency == other.min_fees_currency) and
(self.max_fees_amount == other.max_fees_amount) and
(self.max_fees_currency == other.max_fees_currency)
)
return stat
return False
Expand Down
62 changes: 57 additions & 5 deletions tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from mangopay.resources import ReportTransactions, Report
from mangopay.utils import ReportTransactionsFilters
from tests.test_base import BaseTestLive
import unittest


class ReportsTestLive(BaseTestLive):
@unittest.skip("reason for skipping")
def test_ReportCreate(self):
report = ReportTransactions()
report.report_type = 'transactions'
Expand All @@ -16,7 +14,6 @@ def test_ReportCreate(self):
self.assertIsNotNone(result)
self.assertTrue(result['id'])

@unittest.skip("reason for skipping")
def test_ReportFilteredCreate(self):
report = ReportTransactions()
report.report_type = 'transactions'
Expand All @@ -33,14 +30,69 @@ def test_ReportFilteredCreate(self):
self.assertEqual(report.filters.author_id, result['filters'].author_id)
self.assertEqual(report.filters.wallet_id, result['filters'].wallet_id)

@unittest.skip("reason for skipping")
def test_ReportFilteredCreate_SpecificUseCase(self):
report = ReportTransactions()
report.report_type = 'transactions'
report.tag = 'Created using Mangopay Python SDK'
report.download_format = 'CSV'
report.callback_url = 'https://mangopay.com/docs/please-ignore'
report.preview = False
report.filters = ReportTransactionsFilters(
before_date=1714435201,
after_date=1714348799,
status=['SUCCEEDED'],
nature=['REGULAR'],
wallet_id=None,
author_id=None,
min_debited_funds_amount=0,
min_debited_funds_currency='EUR',
max_debited_funds_amount=1000000,
max_debited_funds_currency='EUR'
)
report.columns = [
'Id',
'Tag',
'CreationDate',
'ExecutionDate',
'AuthorId',
'CreditedUserId',
'DebitedFundsAmount',
'DebitedFundsCurrency',
'CreditedFundsAmount',
'CreditedFundsCurrency',
'FeesAmount',
'FeesCurrency',
'Status',
'ResultCode',
'ResultMessage',
'Type',
'Nature',
'CreditedWalletId',
'DebitedWalletId'
]
report.sort = 'CreationDate: DESC'
result = report.save()

self.assertIsNotNone(result)
self.assertIsNotNone(result['filters'])

self.assertEqual(report.filters.before_date, result['filters'].before_date)
self.assertEqual(report.filters.after_date, result['filters'].after_date)
self.assertEqual(report.filters.status, result['filters'].status)
self.assertEqual(report.filters.nature, result['filters'].nature)
self.assertEqual(report.filters.min_debited_funds_amount, result['filters'].min_debited_funds_amount)
self.assertEqual(report.filters.min_debited_funds_currency, result['filters'].min_debited_funds_currency)
self.assertEqual(report.filters.max_debited_funds_amount, result['filters'].max_debited_funds_amount)
self.assertEqual(report.filters.max_debited_funds_currency, result['filters'].max_debited_funds_currency)
self.assertIsNone(result['filters'].wallet_id)
self.assertIsNone(result['filters'].author_id)

def test_ReportGet(self):
report = BaseTestLive.get_johns_report()
result = Report.get(report.id)

self.assertEqual(report.id, result.id)

@unittest.skip("reason for skipping")
def test_Reports_All(self):
time.sleep(3)
report = BaseTestLive.get_johns_report(recreate=True)
Expand Down

0 comments on commit b5e106f

Please sign in to comment.