コード例 #1
0
ファイル: tests.py プロジェクト: jjkester/moneybird-python
class APIConnectionTest(TestCase):
    """
    Tests whether a connection to the API can be made.
    """
    def setUp(self):
        self.auth = TokenAuthentication(TEST_TOKEN)
        self.api = MoneyBird(self.auth)

    def test_get_administrations(self):
        result = self.api.get('administrations')
        self.assertIsNotNone(result, "The result is empty.")
        self.assertGreaterEqual(len(result), 1, "The result does not contain any data.")

    def test_contacts_roundtrip(self):
        # Get administration ID
        adm_id = self.api.get('administrations')[0]['id']

        # Build a contact
        contact = {
            'company_name': 'MoneyBird API',
            'firstname': 'John',
            'lastname': 'Doe',
        }

        # Create the contact in the administration
        post_result = self.api.post('contacts', {'contact': contact}, administration_id=adm_id)

        self.assertEqual(post_result['company_name'], 'MoneyBird API', "The contact has not been created properly.")
        self.assertEqual(post_result['firstname'], 'John', "The contact has not been created properly.")
        self.assertEqual(post_result['lastname'], 'Doe', "The contact has not been created properly.")
        self.assertIsNotNone(post_result['id'], "The contact has not been created properly.")

        # Set the id of the contact for further use.
        contact_id = post_result['id']

        contact = {
            'firstname': 'No',
            'lastname': 'One',
        }

        # Update the contact in the administration
        patch_result = self.api.patch('contacts/%s' % contact_id, {'contact': contact}, administration_id=adm_id)

        self.assertEqual(patch_result['company_name'], 'MoneyBird API', "The contact has not been updated properly.")
        self.assertEqual(patch_result['firstname'], 'No', "The contact has not been updated properly.")
        self.assertEqual(patch_result['lastname'], 'One', "The contact has not been updated properly.")

        # Delete the contact from the administration
        delete_result = self.api.delete('contacts/%s' % contact_id, administration_id=adm_id)

        self.assertEqual(delete_result['id'], contact_id, "The contact has not been deleted properly.")

        # Check deletion
        try:
            self.api.get('contacts/%s' % contact_id, administration_id=adm_id)
        except self.api.NotFound:
            pass
        else:
            self.fail("The contact has not been deleted properly.")
コード例 #2
0
from moneybird import MoneyBird, TokenAuthentication
import logging

logger = logging.getLogger('moneybird')
moneybird = MoneyBird(
    TokenAuthentication(
        'fc249145ec8fd04e167e3e2c80ad04123e883267219925ac5847abb6a027d03d'))
moneybird.get('administrations')

administrations = moneybird.get('administrations')

for administration in administrations:
    id = administration['id']
    contacts = moneybird.get('contacts', administration_id=id)

    # Print invoices per contact
    for contact in contacts:
        print(contact['company_name'])

        for invoice in moneybird.get('sales_invoices?filter=contact_id:%s' %
                                     contact['id'],
                                     administration_id=id):
            print('  ', invoice['invoice_id'])

contacts = moneybird.get('contacts', administration_id=id)
print(contacts)
コード例 #3
0
class APIConnectionTest(TestCase):
    """
    Tests whether a connection to the API can be made.
    """
    def setUp(self):
        self.auth = TokenAuthentication(TEST_TOKEN)
        self.api = MoneyBird(self.auth)

    def test_get_administrations(self):
        result = self.api.get('administrations')
        self.assertIsNotNone(result, "The result is empty.")
        self.assertGreaterEqual(len(result), 1,
                                "The result does not contain any data.")

    def test_contacts_roundtrip(self):
        # Get administration ID
        adm_id = self.api.get('administrations')[0]['id']

        # Build a contact
        contact = {
            'company_name': 'MoneyBird API',
            'firstname': 'John',
            'lastname': 'Doe',
        }

        # Create the contact in the administration
        post_result = self.api.post('contacts', {'contact': contact},
                                    administration_id=adm_id)

        self.assertEqual(post_result['company_name'], 'MoneyBird API',
                         "The contact has not been created properly.")
        self.assertEqual(post_result['firstname'], 'John',
                         "The contact has not been created properly.")
        self.assertEqual(post_result['lastname'], 'Doe',
                         "The contact has not been created properly.")
        self.assertIsNotNone(post_result['id'],
                             "The contact has not been created properly.")

        # Set the id of the contact for further use.
        contact_id = post_result['id']

        contact = {
            'firstname': 'No',
            'lastname': 'One',
        }

        # Update the contact in the administration
        patch_result = self.api.patch('contacts/%s' % contact_id,
                                      {'contact': contact},
                                      administration_id=adm_id)

        self.assertEqual(patch_result['company_name'], 'MoneyBird API',
                         "The contact has not been updated properly.")
        self.assertEqual(patch_result['firstname'], 'No',
                         "The contact has not been updated properly.")
        self.assertEqual(patch_result['lastname'], 'One',
                         "The contact has not been updated properly.")

        # Delete the contact from the administration
        delete_result = self.api.delete('contacts/%s' % contact_id,
                                        administration_id=adm_id)

        self.assertEqual(delete_result['id'], contact_id,
                         "The contact has not been deleted properly.")

        # Check deletion
        try:
            self.api.get('contacts/%s' % contact_id, administration_id=adm_id)
        except self.api.NotFound:
            pass
        else:
            self.fail("The contact has not been deleted properly.")