コード例 #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
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.")