This repository has been archived by the owner on May 12, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ MANIFEST | |
.cache | ||
.tox/ | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import paypalrestsdk.util as util | ||
from paypalrestsdk.resource import List, Find, Delete, Create, Update, Post, Resource | ||
from paypalrestsdk.api import default as default_api | ||
|
||
class InvoiceTemplate(List, Find, Create, Delete, Update): | ||
"""InvoiceTemplate class wrapping the REST v1/invoicing/templates endpoint" | ||
Usage:: | ||
>>> templates = InvoiceTemplate.all() | ||
>>> invoice_template = InvoiceTemplate.new({}) | ||
>>> invoice.create() # return True or False | ||
""" | ||
path = "v1/invoicing/templates" | ||
|
||
def __getitem__(self, key): | ||
if key == 'id': | ||
return self.__data__['template_id'] | ||
else: | ||
return super.__getitem__(self, key) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
from util import sample_invoice_template | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
invoice_template = sample_invoice_template() | ||
if invoice_template.create(): | ||
print("Invoice Template[%s] created successfully" % (invoice_template.template_id)) | ||
else: | ||
print(invoice_template.error) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
from util import sample_invoice_template | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
invoice_template = sample_invoice_template() | ||
|
||
if invoice_template.create() and invoice_template.delete(): | ||
print("Invoice Template[%s] deleted successfully" % invoice_template.template_id) | ||
else: | ||
print(invoice_template.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
from create import sample_invoice_template | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
invoice_template = sample_invoice_template() | ||
if invoice_template.create(): | ||
found_invoice_template = InvoiceTemplate.find(invoice_template.template_id) | ||
print("Found Invoice Template[%s]" % found_invoice_template.template_id) | ||
else: | ||
print(invoice_template.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
from util import sample_invoice_template | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
for i in range(2): | ||
invoice_template = sample_invoice_template() | ||
invoice_template.create() | ||
|
||
history = InvoiceTemplate.all() | ||
|
||
print("List Invoice Templates:") | ||
for invoice_template in history.templates: | ||
print(" -> Invoice Template[%s]" % (invoice_template.template_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
from util import sample_invoice_template | ||
import random | ||
import string | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
invoice_template = sample_invoice_template() | ||
|
||
if invoice_template.create(): | ||
invoice_template.template_data.items[0].quantity = 2 | ||
if invoice_template.update(): | ||
print("Invoice Template[%s] updated sucessfully" % invoice_template.template_id) | ||
else: | ||
print("Failed to update Invoice Template" + str(invoice_template.error)) | ||
else: | ||
print("Failed to create Invoice Template") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from paypalrestsdk import InvoiceTemplate | ||
import random | ||
import string | ||
|
||
def sample_invoice_template(): | ||
return InvoiceTemplate({ | ||
"name": "Hours Template_".join([random.choice(string.letters) for i in xrange(10)]), | ||
"default": True, | ||
"unit_of_measure": "HOURS", | ||
"template_data": { | ||
"items": [{ | ||
"name": "Nutri Bullet", | ||
"quantity": 1, | ||
"unit_price": { | ||
"currency": "USD", | ||
"value": "50.00" | ||
} | ||
} | ||
], | ||
"merchant_info": { | ||
"email": "stevendcoffey-facilitator@gmail.com" | ||
}, | ||
"tax_calculated_after_discount": False, | ||
"tax_inclusive": False, | ||
"note": "Thank you for your business.", | ||
"logo_url": "https://pics.paypal.com/v1/images/redDot.jpeg" | ||
}, | ||
"settings": [ | ||
{ | ||
"field_name": "items.date", | ||
"display_preference": { | ||
"hidden": True | ||
} | ||
}, | ||
{ | ||
"field_name": "custom", | ||
"display_preference": { | ||
"hidden": True | ||
} | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from test_helper import paypal, unittest | ||
import random | ||
import string | ||
from mock import patch, ANY | ||
|
||
|
||
class TestInvoiceTemplate(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.invoice_template_attributes = { | ||
"name": "Hours Template_".join([random.choice(string.letters) for i in xrange(5)]), | ||
"default": True, | ||
"unit_of_measure": "HOURS", | ||
"template_data": { | ||
"items": [{ | ||
"name": "Nutri Bullet", | ||
"quantity": 1, | ||
"unit_price": { | ||
"currency": "USD", | ||
"value": "50.00" | ||
} | ||
} | ||
], | ||
"merchant_info": { | ||
"email": "stevendcoffey-facilitator@gmail.com" | ||
}, | ||
"tax_calculated_after_discount": False, | ||
"tax_inclusive": False, | ||
"note": "Thank you for your business.", | ||
"logo_url": "https://pics.paypal.com/v1/images/redDot.jpeg" | ||
}, | ||
"settings": [ | ||
{ | ||
"field_name": "items.date", | ||
"display_preference": { | ||
"hidden": True | ||
} | ||
}, | ||
{ | ||
"field_name": "custom", | ||
"display_preference": { | ||
"hidden": True | ||
} | ||
} | ||
] | ||
} | ||
self.invoice_template = paypal.InvoiceTemplate(self.invoice_template_attributes) | ||
self.invoice_template.template_id = 'TEMP-XYZ' | ||
|
||
def test_getitem_override_reads_id_as_template_id(self): | ||
attributes = self.invoice_template_attributes.copy() | ||
attributes["id"] = "wrong" | ||
attributes["template_id"] = "right" | ||
|
||
invoice_template = paypal.InvoiceTemplate(attributes) | ||
self.assertEqual(invoice_template["id"], "right") | ||
|
||
@patch('test_helper.paypal.Api.post', autospec=True) | ||
def test_create(self, mock): | ||
invoice_template = paypal.InvoiceTemplate(self.invoice_template_attributes) | ||
response = invoice_template.create() | ||
|
||
mock.assert_called_once_with(self.invoice_template.api, | ||
'v1/invoicing/templates', self.invoice_template_attributes, {'PayPal-Request-Id': invoice_template.request_id}, None) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.delete', autospec=True) | ||
def test_delete(self, mock): | ||
response = self.invoice_template.delete() | ||
mock.assert_called_once_with(self.invoice_template.api, | ||
'v1/invoicing/templates/' + self.invoice_template.template_id) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.put', autospec=True) | ||
def test_update(self, mock): | ||
response = self.invoice_template.update(self.invoice_template_attributes) | ||
|
||
mock.assert_called_once_with(self.invoice_template.api, | ||
'v1/invoicing/templates/' + self.invoice_template.template_id, | ||
self.invoice_template_attributes, {'PayPal-Request-Id': self.invoice_template.request_id}, None) | ||
self.assertEqual(response, True) | ||
|
||
@patch('test_helper.paypal.Api.get', autospec=True) | ||
def test_find(self, mock): | ||
invoice_template = paypal.InvoiceTemplate.find(self.invoice_template.template_id) | ||
|
||
mock.assert_called_once_with(self.invoice_template.api, | ||
'v1/invoicing/templates/' + self.invoice_template.template_id, refresh_token=None) | ||
self.assertTrue(isinstance(invoice_template, paypal.InvoiceTemplate)) | ||
|
||
@patch('test_helper.paypal.Api.get', autospec=True) | ||
def test_all(self, mock): | ||
mock.return_value = { | ||
'total_count': 1, | ||
'templates': [self.invoice_template] | ||
} | ||
history = paypal.InvoiceTemplate.all() | ||
|
||
mock.assert_called_once_with(self.invoice_template.api, | ||
'v1/invoicing/templates') | ||
self.assertEqual(history.total_count, 1) | ||
self.assertTrue(isinstance(history.templates[0], paypal.InvoiceTemplate)) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters