Skip to content

Commit

Permalink
Version 0.2.7
Browse files Browse the repository at this point in the history
- Added Simple Tests
- Patched some methods (Nothing major)
  • Loading branch information
WilliamOtieno committed Jan 2, 2022
1 parent 4e03df9 commit f35b37b
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 5 deletions.
8 changes: 4 additions & 4 deletions python_flutterwave/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
token = ""


def initiate_payment(tx_ref: str, amount: float, currency: str, redirect_url: str, payment_options: str,
customer_email: str, customer_phone_number: Optional[str], customer_name: str,
title: Optional[str],
description: Optional[str]) -> str:
def initiate_payment(tx_ref: str, amount: float, currency: Optional[str], redirect_url: str, customer_name: str,
payment_options: Optional[str], title: Optional[str], customer_email: str,
customer_phone_number: Optional[str], description: Optional[str]) -> str:
"""This is used to initiate standard payments. It takes in the arguments and returns the url to redirect users for
payments """
payment_url = "https://api.flutterwave.com/v3/payments"
Expand Down Expand Up @@ -38,6 +37,7 @@ def initiate_payment(tx_ref: str, amount: float, currency: str, redirect_url: st
return link


# pragma: no cover
def get_payment_details(trans_id: str) -> dict:
"""
Takes the transaction_id from the request and returns the status info in json.
Expand Down
1 change: 1 addition & 0 deletions python_flutterwave/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

52 changes: 52 additions & 0 deletions python_flutterwave/tests/test_initiate_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import random
import string

from python_flutterwave import payment
import unittest


class TestStandardPayment(unittest.TestCase):

def setUp(self) -> None:
self.token = "YOUR_SECRET_KEY"
self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}"
self.amount = 10.0
self.currency = 'KES'
self.redirect_url = "https://example.com/"
self.payment_options = "mpesa"
self.customer_email = "[email protected]"
self.customer_phone_number = "1234567890"
self.customer_name = "John Doe"
self.title = "Test Payment"
self.description = "Just pay me..."
payment.token = self.token
self.link = payment.initiate_payment(tx_ref=self.tx_ref, amount=self.amount, redirect_url=self.redirect_url,
payment_options=self.payment_options, customer_email=self.customer_email,
customer_phone_number=self.customer_phone_number,
customer_name=self.customer_name, title=self.title,
description=self.description, currency=self.currency)

def tearDown(self) -> None:
pass

def test_argument_types(self):
self.assertIsInstance(self.token, str)
self.assertIsInstance(self.tx_ref, str)
self.assertIsInstance(self.amount, float)
self.assertIsInstance(self.currency, str)
self.assertIsInstance(self.redirect_url, str)
self.assertIsInstance(self.payment_options, str)
self.assertIsInstance(self.customer_email, str)
self.assertIsInstance(self.customer_phone_number, str)
self.assertIsInstance(self.customer_name, str)
self.assertIsInstance(self.title, str)
self.assertIsInstance(self.description, str)

def test_mandatory_args(self):
self.assertIsNot(self.token, "")
self.assertIsNot(self.amount, "")
self.assertIsNot(self.customer_email, "")

def test_return_obj(self):
self.assertIsInstance(self.link, str)
self.assertIsNotNone(self.link)
45 changes: 45 additions & 0 deletions python_flutterwave/tests/test_initiate_ussd_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
import random
import string

from python_flutterwave import payment


class TestInitiateUSSDPayment(unittest.TestCase):

def setUp(self) -> None:
self.token = "YOUR_SECRET_KEY"
self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}"
self.amount = 10.0
self.account_bank = "044"
self.email = "[email protected]"
self.phone_number = "1234567890"
self.full_name = "John Doe"
payment.token = self.token
self.details = payment.initiate_ussd_payment(tx_ref=self.tx_ref, amount=self.amount,
email=self.email, phone_number=self.phone_number,
full_name=self.full_name, account_bank=self.account_bank)

def tearDown(self) -> None:
pass

def test_argument_types(self):
self.assertIsInstance(self.token, str)
self.assertIsInstance(self.tx_ref, str)
self.assertIsInstance(self.amount, float)
self.assertIsInstance(self.account_bank, str)

def test_mandatory_args(self):
self.assertIsNot(self.token, "")
self.assertIsNot(self.amount, "")
self.assertIsNot(self.email, "")
self.assertIsNot(self.account_bank, "")
self.assertIsNot(self.phone_number, "")

def test_return_obj(self):
self.assertIsInstance(self.details, dict)
self.assertIsNotNone(self.details)
self.assertIn("status", self.details.keys())
self.assertIn("message", self.details.keys())
self.assertIn("data", self.details.keys())
self.assertIn("meta", self.details.keys())
42 changes: 42 additions & 0 deletions python_flutterwave/tests/test_trigger_mpesa_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import random
import string
import unittest

from python_flutterwave import payment


class TestTriggerMpesaPayment(unittest.TestCase):

def setUp(self) -> None:
self.token = "YOUR_SECRET_KEY"
self.tx_ref = f"{''.join(random.choice(string.ascii_letters) for i in range(10))}"
self.amount = 10.0
self.currency = 'KES'
self.email = "[email protected]"
self.phone_number = "1234567890"
self.full_name = "John Doe"
payment.token = self.token
self.details = payment.trigger_mpesa_payment(tx_ref=self.tx_ref, amount=self.amount, currency=self.currency,
email=self.email, phone_number=self.phone_number,
full_name=self.full_name)

def tearDown(self) -> None:
pass

def test_argument_types(self):
self.assertIsInstance(self.token, str)
self.assertIsInstance(self.tx_ref, str)
self.assertIsInstance(self.amount, float)
self.assertIsInstance(self.currency, str)

def test_mandatory_args(self):
self.assertIsNot(self.token, "")
self.assertIsNot(self.amount, "")
self.assertIsNot(self.email, "")

def test_return_obj(self):
self.assertIsInstance(self.details, dict)
self.assertIsNotNone(self.details)
self.assertIn("status", self.details.keys())
self.assertIn("message", self.details.keys())
self.assertIn("data", self.details.keys())
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = python-flutterwave
version = 0.2.6
version = 0.2.7
author = William Otieno
author_email = [email protected]
description = Python Wrapper for interacting with the Flutterwave Payments API
Expand Down

0 comments on commit f35b37b

Please sign in to comment.