Package: xero-db-connector
Xero Database ConnectorConnects Xero to a database to transfer information to and fro.InstallationThis project requiresPython 3+.Download this project and use it (copy it in your project, etc).Install it frompip.$ pip install xero-db-connectorUsageTo use this connector you'll need Xero credentials - specifically the keyfile and consumer key.Here's example usage.fromxero_db_connector.extractimportXeroExtractConnectorfromxero_db_connector.loadimportXeroLoadConnectorimportsqlite3importloggingimportosfromxeroimportXerofromxero.authimportPrivateCredentialsdefxero_connect():XERO_PRIVATE_KEYFILE=os.environ.get('XERO_PRIVATE_KEYFILE',None)XERO_CONSUMER_KEY=os.environ.get('XERO_CONSUMER_KEY',None)ifXERO_PRIVATE_KEYFILEisNone:raiseException('XERO_PRIVATE_KEYFILE is not set')ifXERO_CONSUMER_KEYisNone:raiseException('XERO_CONSUMER_KEY is not set')withopen(XERO_PRIVATE_KEYFILE)askeyfile:rsa_key=keyfile.read()credentials=PrivateCredentials(XERO_CONSUMER_KEY,rsa_key)# used to connect to xeroreturnXero(credentials)dbconn=sqlite3.connect('/tmp/xero.db',detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)xero=xero_connect()x=XeroExtractConnector(xero=xero,dbconn=dbconn)x.create_tables()y=XeroLoadConnector(xero=xero,dbconn=dbconn)y.create_tables()x.extract_contacts()x.extract_tracking_categories()x.extract_accounts()# do some transformations and populated invoice tables xero_load_invoices and xero_load_invoice_lineitemsforinvoice_idiny.load_invoices_generator():xero_invoice_id=y.get_xero_invoice_id(invoice_id=invoice_id)print(f'posted invoice{invoice_id}for which xero returned{xero_invoice_id}')ContributeTo contribute to this project follow the stepsFork and clone the repository.Runpip install -r requirements.txtSetup pylint precommit hookCreate a file.git/hooks/pre-commitCopy and paste the following lines in the file -#!/usr/bin/env bashgit-pylint-commit-hookMake necessary changesRun unit tests to ensure everything is fineUnit TestsTo run unit tests, run pytest in the following manner:python -m pytest test/unitYou should see something like this:================================================================== test session starts ==================================================================
platform darwin -- Python 3.7.4, pytest-5.2.2, py-1.8.0, pluggy-0.13.0
rootdir: /Users/siva/src/xero-db-connector, inifile: pytest.ini
plugins: mock-1.11.2, cov-2.8.1
collected 3 items                                                                                                                                       

test/unit/test_mocks.py::test_xero_mock_setup PASSED                                                                                              [ 33%]
test/unit/test_mocks.py::test_dbconn_mock_setup PASSED                                                                                            [ 66%]
test/unit/test_mocks.py::test_xec_mock_setup PASSED                                                                                               [100%]

=================================================================== 3 passed in 0.10s ===================================================================Integration TestsTo run unit tests, you will need a mechanism to connect to a real Xero account. Specifically, you'll need a keyfile and a consumer key, both of which can be obtained from the xero developer portal. Set the following environment variables before running the integration tests:export XERO_PRIVATE_KEYFILE=<path_to_keyfile>
export XERO_CONSUMER_KEY=<string>

python -m pytest test/integrationCode coverageTo get code coverage report, run this command:python-mpytest--cov=xero_db_connector<snippedoutput>NameStmtsMissCover---------------------------------------------------xero_db_connector/__init__.py00100%xero_db_connector/extract.py1060100%xero_db_connector/load.py520100%---------------------------------------------------TOTAL1580100%To get an html report, run this command:python-mpytest--cov=xero_db_connector--cov-reporthtml:cov_htmlWe want to maintain code coverage of more than 95% for this project at all times.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details