-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from starkbank/feature/institution
Add Institution resource to allow SPI and TED participant query
- Loading branch information
Showing
8 changed files
with
110 additions
and
1 deletion.
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
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
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 @@ | ||
from .__institution import query |
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,40 @@ | ||
from ..utils import rest | ||
from ..utils.resource import SubResource | ||
|
||
|
||
class Institution(SubResource): | ||
"""# Institution object | ||
A Institution is used to get information on the institutions that are recognized by the Brazilian Central Bank. | ||
Besides the display name and full name, they also include the STR code (used for TEDs) and the SPI Code | ||
(used for Pix) for the institutions. Either of these codes may be empty if the institution is not registered on | ||
that Central Bank service. | ||
## Attributes: | ||
- display_name [string]: short version of the institution name that should be displayed to end users. ex: "Stark Bank" | ||
- name [string]: full version of the institution name. ex: "Stark Bank S.A." | ||
- spi_code [string]: SPI code used to identify the institution on Pix transactions. ex: "20018183" | ||
- str_code [string]: STR code used to identify the institution on TED transactions. ex: "123" | ||
""" | ||
|
||
def __init__(self, display_name, name, spi_code, str_code): | ||
self.display_name = display_name | ||
self.name = name | ||
self.spi_code = spi_code | ||
self.str_code = str_code | ||
|
||
|
||
_resource = {"class": Institution, "name": "Institution"} | ||
|
||
|
||
def query(limit=None, search=None, spi_codes=None, str_codes=None, user=None): | ||
"""# Retrieve Bacen Institutions | ||
Receive a list of Institution objects that are recognized by the Brazilian Central bank for Pix and TED transactions | ||
## Parameters (optional): | ||
- limit [integer, default None]: maximum number of objects to be retrieved. Unlimited if None. ex: 35 | ||
- search [string, default None]: part of the institution name to be searched. ex: "stark" | ||
- spi_codes [list of strings, default None]: list of SPI (Pix) codes to be searched. ex: ["20018183"] | ||
- str_codes [list of strings, default None]: list of STR (TED) codes to be searched. ex: ["260"] | ||
- user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call | ||
## Return: | ||
- list of Institution objects with updated attributes | ||
""" | ||
return rest.get_page(resource=_resource, search=search, spi_codes=spi_codes, str_codes=str_codes, limit=limit, user=user)[0] |
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,26 @@ | ||
import starkbank | ||
from unittest import TestCase, main | ||
from tests.utils.user import exampleProject | ||
|
||
|
||
starkbank.user = exampleProject | ||
|
||
|
||
class TestInstitutionQuery(TestCase): | ||
|
||
def test_success(self): | ||
institutions = starkbank.institution.query() | ||
for institution in institutions[:5]: | ||
self.assertIsInstance(institution.display_name, str) | ||
self.assertIsInstance(institution.name, str) | ||
self.assertIsInstance(institution.str_code, str) | ||
self.assertIsInstance(institution.spi_code, str) | ||
print(institution) | ||
|
||
self.assertEqual(len(starkbank.institution.query(search="stark")), 1) | ||
self.assertEqual(len(starkbank.institution.query(spi_codes="20018183")), 1) | ||
self.assertEqual(len(starkbank.institution.query(str_codes="341")), 1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,26 @@ | ||
import starkbank | ||
from unittest import TestCase, main | ||
from tests.utils.user import exampleProject | ||
|
||
|
||
starkbank.user = exampleProject | ||
|
||
|
||
class TestInstitutionQuery(TestCase): | ||
|
||
def test_success(self): | ||
institutions = starkbank.institution.query() | ||
for institution in institutions[:5]: | ||
self.assertIsInstance(institution.display_name, str) | ||
self.assertIsInstance(institution.name, str) | ||
self.assertIsInstance(institution.str_code, str) | ||
self.assertIsInstance(institution.spi_code, str) | ||
print(institution) | ||
|
||
self.assertEqual(len(starkbank.institution.query(search="stark")), 1) | ||
self.assertEqual(len(starkbank.institution.query(spi_codes="20018183")), 1) | ||
self.assertEqual(len(starkbank.institution.query(str_codes="341")), 1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |