Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions test/unit/testPartner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import unittest
from unittest.mock import MagicMock, patch

from trolley.configuration import Configuration


class TestPartnerGateway(unittest.TestCase):

@patch('trolley.partner_gateway.trolley.configuration.Configuration.client')
def test_dedicated_partner_methods_call_expected_endpoints(self, client_factory):
client = MagicMock()
client_factory.return_value = client
partner = Configuration.gateway('access', 'secret').partner
body = {'enabled': True}

partner.get_fees()
partner.get_fees('USD')
partner.update_fees(body)
partner.list_payout_methods()
partner.get_payout_method('bank-transfer')
partner.update_payout_method('bank-transfer', body)
partner.get_processing_settings()
partner.update_processing_settings(body)
partner.get_white_label_dns_records()
partner.verify_white_label_dns_records()
partner.delete_white_label_email()
partner.update_white_label_icon(body)
partner.get_white_label_settings()
partner.update_white_label_settings(body)
partner.get_widget_configuration()
partner.update_widget_configuration(body)

self.assertEqual([
unittest.mock.call('/v1/fees'),
unittest.mock.call('/v1/fees?currency=USD'),
unittest.mock.call('/v1/payout-methods'),
unittest.mock.call('/v1/payout-methods/bank-transfer'),
unittest.mock.call('/v1/processing-settings'),
unittest.mock.call('/v1/white-label/dns-records'),
unittest.mock.call('/v1/white-label'),
unittest.mock.call('/v1/iframe/config'),
], client.get.call_args_list)
self.assertEqual([
unittest.mock.call('/v1/fees', body),
unittest.mock.call('/v1/payout-methods/bank-transfer', body),
unittest.mock.call('/v1/processing-settings', body),
unittest.mock.call('/v1/white-label/icon', body),
unittest.mock.call('/v1/white-label', body),
], client.patch.call_args_list)
self.assertEqual([
unittest.mock.call('/v1/white-label/dns-records/verify', {}),
unittest.mock.call('/v1/iframe/config', body),
], client.post.call_args_list)
client.delete.assert_called_once_with('/v1/white-label/email')


if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions trolley/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from trolley.invoice_line_gateway import InvoiceLineGateway
from trolley.invoice_payment_gateway import InvoicePaymentGateway
from trolley.verification_gateway import VerificationGateway
from trolley.partner_gateway import PartnerGateway
import trolley.configuration


Expand Down Expand Up @@ -35,6 +36,7 @@ def __init__(self, config=None, **kwargs):
self.invoice_payment = InvoicePaymentGateway(self, config)
self.verification = VerificationGateway(self, config)
self.trust = self.verification
self.partner = PartnerGateway(self, config)

def request(self, method, endpoint, body=None):
return trolley.configuration.Configuration.client(self.config).request(method, endpoint, body)
67 changes: 67 additions & 0 deletions trolley/partner_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from urllib.parse import quote

import trolley.configuration


class PartnerGateway(object):
"""Trolley partner settings processor."""

def __init__(self, gateway, config):
self.gateway = gateway
self.config = gateway.config

def _client(self):
return trolley.configuration.Configuration.client(self.config)

def get_fees(self, currency=None):
endpoint = '/v1/fees'
if currency:
endpoint += '?currency={}'.format(quote(currency, safe=''))
return self._client().get(endpoint)

def update_fees(self, body):
return self._client().patch('/v1/fees', body)

def list_payout_methods(self):
return self._client().get('/v1/payout-methods')

def get_payout_method(self, payout_method):
return self._client().get(
'/v1/payout-methods/{}'.format(quote(payout_method, safe=''))
)

def update_payout_method(self, payout_method, body):
return self._client().patch(
'/v1/payout-methods/{}'.format(quote(payout_method, safe='')),
body
)

def get_processing_settings(self):
return self._client().get('/v1/processing-settings')

def update_processing_settings(self, body):
return self._client().patch('/v1/processing-settings', body)

def get_white_label_dns_records(self):
return self._client().get('/v1/white-label/dns-records')

def verify_white_label_dns_records(self):
return self._client().post('/v1/white-label/dns-records/verify', {})

def delete_white_label_email(self):
return self._client().delete('/v1/white-label/email')

def update_white_label_icon(self, body):
return self._client().patch('/v1/white-label/icon', body)

def get_white_label_settings(self):
return self._client().get('/v1/white-label')

def update_white_label_settings(self, body):
return self._client().patch('/v1/white-label', body)

def get_widget_configuration(self):
return self._client().get('/v1/iframe/config')

def update_widget_configuration(self, body=None):
return self._client().post('/v1/iframe/config', body or {})