Skip to content

Commit 477c654

Browse files
Merge pull request #5 from pazguille/feature-coupons
Added Coupons resource.
2 parents 15407f4 + 88a4a78 commit 477c654

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ You can also work with all the other resources authenticated with a secret API K
9292
* `Queue <https://developers.getmango.com/en/api/queue/?platform=python>`_
9393
* `Installments <https://developers.getmango.com/en/api/installments/?platform=python>`_
9494
* `Promotions <https://developers.getmango.com/en/api/promotions/?platform=python>`_
95+
* `Coupons <https://developers.getmango.com/en/api/coupons/?platform=python>`_
9596

9697

9798
Tests

pymango/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from resources import Queue
99
from resources import Installment as Installments
1010
from resources import Promotion as Promotions
11+
from resources import Coupon as Coupons
1112

1213
api_key = ""
1314
version = 1

pymango/resources.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ class Installment(ListableResource, Resource):
144144
class Promotion(GetableResource, ListableResource, Resource):
145145
"""Mango Promotion resource"""
146146
name = "promotions"
147+
148+
149+
class Coupon(GetableResource, ListableResource, ResourceCreatable, ResourceUpdatable, Resource):
150+
"""Mango Coupon resource"""
151+
name = "coupons"

pymango/tests/tests_resources.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,43 @@ def test_promotions_get_item():
255255
ok_(promotion)
256256
eq_(promotion_uid, promotion.get("uid"))
257257
eq_("active", promotion.get("status"))
258+
259+
260+
#
261+
# Coupons
262+
#
263+
def test_coupons_create():
264+
"""Should create a coupon"""
265+
amount = 2000
266+
type = "pagofacil"
267+
first_due_date = "2018-07-17"
268+
second_due_date = "2018-07-22"
269+
surcharge = 1500
270+
coupon = mango.Coupons.create(amount=amount, type=type, first_due_date=first_due_date, second_due_date=second_due_date, surcharge=surcharge)
271+
ok_(coupon)
272+
ok_(coupon.get("uid"))
273+
eq_(amount, coupon.get("amount"))
274+
eq_(type, coupon.get("type"))
275+
eq_(first_due_date, coupon.get("first_due_date"))
276+
eq_(second_due_date, coupon.get("second_due_date"))
277+
eq_(surcharge, coupon.get("surcharge"))
278+
eq_(False, coupon.get("paid"))
279+
280+
281+
def test_coupons_list():
282+
"""Should return a list of coupons"""
283+
eq_(list, type(mango.Coupons.list()))
284+
285+
286+
def test_coupons_get():
287+
"""Should get a coupon"""
288+
coupon_uid = mango.Coupons.list()[0].get("uid")
289+
coupon = mango.Coupons.get(coupon_uid)
290+
ok_(coupon)
291+
ok_(coupon.get("uid"))
292+
293+
294+
def test_coupons_update():
295+
"""Should update coupon paid"""
296+
coupon_uid = mango.Coupons.get(mango.Coupons.list()[0].get("uid")).get("uid")
297+
ok_(mango.Coupons.update(coupon_uid, paid=True))

0 commit comments

Comments
 (0)