示例#1
0
文件: manager.py 项目: reachfh/pyxero
    def test_serializer(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_invoice_input = {
            'Date': datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            'Reference': 'ABAS 123',
            'LineItems': [
                {'Description': 'Example description only'},
                {
                    'UnitAmount': '0.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 2',
                    'TaxType': 'OUTPUT'
                },
                {
                    'UnitAmount': '231.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 3',
                    'TaxType': 'OUTPUT'
                },
            ],
            'Status': 'DRAFT',
            'Type': 'ACCREC',
            'DueDate': datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            'LineAmountTypes': 'Exclusive',
            'Contact': {'Name': 'Basket Case'}
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)

        expected_xml = """
示例#2
0
    def test_serializer_nested_singular(self):
        credentials = Mock(base_url="")
        manager = Manager("contacts", credentials)

        example_invoice_input = {
            "Date": datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            "Reference": "ABAS 123",
            "LineItems": [{"Description": "Example description only"}],
            "Status": "DRAFT",
            "Type": "ACCREC",
            "DueDate": datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            "LineAmountTypes": "Exclusive",
            "Contact": {"Name": "Basket Case"},
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)

        expected_xml = """
            <Status>DRAFT</Status>
            <Contact><Name>Basket Case</Name></Contact>
            <Reference>ABAS 123</Reference>
            <Date>2015-06-06T16:25:02</Date>
            <LineAmountTypes>Exclusive</LineAmountTypes>
            <LineItems>
              <LineItem>
                <Description>Example description only</Description>
              </LineItem>
            </LineItems>
            <Type>ACCREC</Type>
            <DueDate>2015-07-06T16:25:02</DueDate>
        """

        self.assertXMLEqual(
            resultant_xml, expected_xml,
        )
示例#3
0
    def test_serializer_phones_addresses(self):
        credentials = Mock(base_url="")
        manager = Manager("contacts", credentials)

        example_contact_input = {
            "ContactID": "565acaa9-e7f3-4fbf-80c3-16b081ddae10",
            "ContactStatus": "ACTIVE",
            "Name": "Southside Office Supplies",
            "Addresses": [{"AddressType": "POBOX"}, {"AddressType": "STREET"}],
            "Phones": [
                {"PhoneType": "DDI"},
                {"PhoneType": "DEFAULT"},
                {"PhoneType": "FAX"},
                {"PhoneType": "MOBILE"},
            ],
            "UpdatedDateUTC": datetime.datetime(2015, 9, 18, 5, 6, 56, 893),
            "IsSupplier": False,
            "IsCustomer": False,
            "HasAttachments": False,
        }
        resultant_xml = manager._prepare_data_for_save(example_contact_input)
        resultant_xml = "<Contact>%s</Contact>" % resultant_xml

        expected_xml = """
        <Contact>
          <ContactID>565acaa9-e7f3-4fbf-80c3-16b081ddae10</ContactID>
          <Name>Southside Office Supplies</Name>
          <HasAttachments>false</HasAttachments>
          <Phones>
            <Phone>
              <PhoneType>DDI</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>DEFAULT</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>FAX</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>MOBILE</PhoneType>
            </Phone>
          </Phones>
          <IsCustomer>false</IsCustomer>
          <Addresses>
            <Address>
              <AddressType>POBOX</AddressType>
            </Address>
            <Address>
              <AddressType>STREET</AddressType>
            </Address>
          </Addresses>
          <IsSupplier>false</IsSupplier>
          <ContactStatus>ACTIVE</ContactStatus>
        </Contact>
        """

        self.assertXMLEqual(
            resultant_xml, expected_xml, "Resultant XML does not match expected."
        )
示例#4
0
文件: manager.py 项目: ngendah/pyxero
    def test_serializer_nested_singular(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_invoice_input = {
            'Date': datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            'Reference': 'ABAS 123',
            'LineItems': [
                {
                    'Description': 'Example description only'
                },
            ],
            'Status': 'DRAFT',
            'Type': 'ACCREC',
            'DueDate': datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            'LineAmountTypes': 'Exclusive',
            'Contact': {
                'Name': 'Basket Case'
            }
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)

        expected_xml = """
            <Status>DRAFT</Status>
            <Contact><Name>Basket Case</Name></Contact>
            <Reference>ABAS 123</Reference>
            <Date>2015-06-06T16:25:02</Date>
            <LineAmountTypes>Exclusive</LineAmountTypes>
            <LineItems>
              <LineItem>
                <Description>Example description only</Description>
              </LineItem>
            </LineItems>
            <Type>ACCREC</Type>
            <DueDate>2015-07-06T16:25:02</DueDate>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
        )
示例#5
0
    def test_serializer_nested_singular(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_invoice_input = {
            'Date': datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            'Reference': 'ABAS 123',
            'LineItems': [
                {'Description': 'Example description only'},
            ],
            'Status': 'DRAFT',
            'Type': 'ACCREC',
            'DueDate': datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            'LineAmountTypes': 'Exclusive',
            'Contact': {'Name': 'Basket Case'}
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)

        expected_xml = """
            <Status>DRAFT</Status>
            <Contact><Name>Basket Case</Name></Contact>
            <Reference>ABAS 123</Reference>
            <Date>2015-06-06 16:25:02.711109</Date>
            <LineAmountTypes>Exclusive</LineAmountTypes>
            <LineItems>
              <LineItem>
                <Description>Example description only</Description>
              </LineItem>
            </LineItems>
            <Type>ACCREC</Type>
            <DueDate>2015-07-06 16:25:02.711136</DueDate>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
        )
示例#6
0
    def test_serializer(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_invoice_input = {
            'Date': datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            'Reference': 'ABAS 123',
            'LineItems': [
                {'Description': 'Example description only'},
                {
                    'UnitAmount': '0.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 2',
                    'TaxType': 'OUTPUT'
                },
                {
                    'UnitAmount': '231.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 3',
                    'TaxType': 'OUTPUT'
                },
            ],
            'Status': 'DRAFT',
            'Type': 'ACCREC',
            'DueDate': datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            'LineAmountTypes': 'Exclusive',
            'Contact': {'Name': 'Basket Case'}
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)
        resultant_xml = '<Invoice>%s</Invoice>' % resultant_xml

        expected_xml = """
        <Invoice>
          <Status>DRAFT</Status>
          <Contact>
            <Name>Basket Case</Name>
          </Contact>
          <Reference>ABAS 123</Reference>
          <Date>2015-06-06 16:25:02.711109</Date>
          <LineAmountTypes>Exclusive</LineAmountTypes>
          <LineItems>
            <LineItem>
              <Description>Example description only</Description>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>0.0000</UnitAmount>
              <Description>Example line item 2</Description>
              <Quantity>1</Quantity>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>231.0000</UnitAmount>
              <Description>Example line item 3</Description>
              <Quantity>1</Quantity>
            </LineItem>
          </LineItems>
          <Type>ACCREC</Type>
          <DueDate>2015-07-06 16:25:02.711136</DueDate>
        </Invoice>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
        )
示例#7
0
    def test_serializer_phones_addresses(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_contact_input = {
            'ContactID': '565acaa9-e7f3-4fbf-80c3-16b081ddae10',
            'ContactStatus': 'ACTIVE',
            'Name': 'Southside Office Supplies',
            'Addresses': [
                {
                    'AddressType': 'POBOX',
                },
                {
                    'AddressType': 'STREET',
                },
            ],
            'Phones': [
                {
                    'PhoneType': 'DDI',
                },
                {
                    'PhoneType': 'DEFAULT',
                },
                {
                    'PhoneType': 'FAX',
                },
                {
                    'PhoneType': 'MOBILE',
                },
            ],
            'UpdatedDateUTC': datetime.datetime(2015, 9, 18, 5, 6, 56, 893),
            'IsSupplier': False,
            'IsCustomer': False,
            'HasAttachments': False,
        }
        resultant_xml = manager._prepare_data_for_save(example_contact_input)
        resultant_xml = '<Contact>%s</Contact>' % resultant_xml

        expected_xml = """
        <Contact>
          <ContactID>565acaa9-e7f3-4fbf-80c3-16b081ddae10</ContactID>
          <Name>Southside Office Supplies</Name>
          <HasAttachments>false</HasAttachments>
          <Phones>
            <Phone>
              <PhoneType>DDI</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>DEFAULT</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>FAX</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>MOBILE</PhoneType>
            </Phone>
          </Phones>
          <IsCustomer>false</IsCustomer>
          <Addresses>
            <Address>
              <AddressType>POBOX</AddressType>
            </Address>
            <Address>
              <AddressType>STREET</AddressType>
            </Address>
          </Addresses>
          <IsSupplier>false</IsSupplier>
          <ContactStatus>ACTIVE</ContactStatus>
        </Contact>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
            "Resultant XML does not match expected."
        )
示例#8
0
    def test_serializer(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_invoice_input = {
            'Date':
            datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            'Reference':
            'ABAS 123',
            'LineItems': [
                {
                    'Description': 'Example description only'
                },
                {
                    'UnitAmount': '0.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 2',
                    'TaxType': 'OUTPUT'
                },
                {
                    'UnitAmount': '231.0000',
                    'Quantity': 1,
                    'AccountCode': '200',
                    'Description': 'Example line item 3',
                    'TaxType': 'OUTPUT'
                },
            ],
            'Status':
            'DRAFT',
            'Type':
            'ACCREC',
            'DueDate':
            datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            'LineAmountTypes':
            'Exclusive',
            'Contact': {
                'Name': 'Basket Case'
            }
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)
        resultant_xml = '<Invoice>%s</Invoice>' % resultant_xml
        # Normalise the whitespace before comparing, otherwise the test fails
        resultant_xml = parseString(resultant_xml).toprettyxml()

        expected_xml = """<?xml version="1.0" ?>
        <Invoice>
          <Status>DRAFT</Status>
          <Contact>
            <Name>Basket Case</Name>
          </Contact>
          <Reference>ABAS 123</Reference>
          <Date>2015-06-06 16:25:02.711109</Date>
          <LineAmountTypes>Exclusive</LineAmountTypes>
          <LineItems>
            <LineItem>
              <Description>Example description only</Description>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>0.0000</UnitAmount>
              <Description>Example line item 2</Description>
              <Quantity>1</Quantity>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>231.0000</UnitAmount>
              <Description>Example line item 3</Description>
              <Quantity>1</Quantity>
            </LineItem>
          </LineItems>
          <Type>ACCREC</Type>
          <DueDate>2015-07-06 16:25:02.711136</DueDate>
        </Invoice>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
        )
示例#9
0
    def test_serializer_phones_addresses(self):
        credentials = Mock(base_url="")
        manager = Manager('contacts', credentials)

        example_contact_input = {
            'ContactID':
            '565acaa9-e7f3-4fbf-80c3-16b081ddae10',
            'ContactStatus':
            'ACTIVE',
            'Name':
            'Southside Office Supplies',
            'Addresses': [
                {
                    'AddressType': 'POBOX',
                },
                {
                    'AddressType': 'STREET',
                },
            ],
            'Phones': [
                {
                    'PhoneType': 'DDI',
                },
                {
                    'PhoneType': 'DEFAULT',
                },
                {
                    'PhoneType': 'FAX',
                },
                {
                    'PhoneType': 'MOBILE',
                },
            ],
            'UpdatedDateUTC':
            datetime.datetime(2015, 9, 18, 5, 6, 56, 893),
            'IsSupplier':
            False,
            'IsCustomer':
            False,
            'HasAttachments':
            False,
        }
        resultant_xml = manager._prepare_data_for_save(example_contact_input)
        resultant_xml = '<Contact>%s</Contact>' % resultant_xml
        # Normalise the whitespace before comparing, otherwise the test fails
        resultant_xml = parseString(resultant_xml).toprettyxml()

        expected_xml = """<?xml version="1.0" ?>
        <Contact>
          <ContactID>565acaa9-e7f3-4fbf-80c3-16b081ddae10</ContactID>
          <Name>Southside Office Supplies</Name>
          <HasAttachments>false</HasAttachments>
          <Phones>
            <Phone>
              <PhoneType>DDI</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>DEFAULT</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>FAX</PhoneType>
            </Phone>
            <Phone>
              <PhoneType>MOBILE</PhoneType>
            </Phone>
          </Phones>
          <IsCustomer>false</IsCustomer>
          <Addresses>
            <Address>
              <AddressType>POBOX</AddressType>
            </Address>
            <Address>
              <AddressType>STREET</AddressType>
            </Address>
          </Addresses>
          <IsSupplier>false</IsSupplier>
          <ContactStatus>ACTIVE</ContactStatus>
        </Contact>
        """

        self.assertXMLEqual(
            resultant_xml,
            expected_xml,
        )
示例#10
0
    def test_serializer(self):
        credentials = Mock(base_url="")
        manager = Manager("contacts", credentials)

        example_invoice_input = {
            "Date": datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
            "Reference": "ABAS 123",
            "LineItems": [
                {"Description": "Example description only"},
                {
                    "UnitAmount": "0.0000",
                    "Quantity": 1,
                    "AccountCode": "200",
                    "Description": "Example line item 2",
                    "TaxType": "OUTPUT",
                },
                {
                    "UnitAmount": "231.0000",
                    "Quantity": 1,
                    "AccountCode": "200",
                    "Description": "Example line item 3",
                    "TaxType": "OUTPUT",
                },
            ],
            "Status": "DRAFT",
            "Type": "ACCREC",
            "DueDate": datetime.datetime(2015, 7, 6, 16, 25, 2, 711136),
            "LineAmountTypes": "Exclusive",
            "Contact": {"Name": "Basket Case"},
        }
        resultant_xml = manager._prepare_data_for_save(example_invoice_input)
        resultant_xml = "<Invoice>%s</Invoice>" % resultant_xml

        expected_xml = """
        <Invoice>
          <Status>DRAFT</Status>
          <Contact>
            <Name>Basket Case</Name>
          </Contact>
          <Reference>ABAS 123</Reference>
          <Date>2015-06-06T16:25:02</Date>
          <LineAmountTypes>Exclusive</LineAmountTypes>
          <LineItems>
            <LineItem>
              <Description>Example description only</Description>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>0.0000</UnitAmount>
              <Description>Example line item 2</Description>
              <Quantity>1</Quantity>
            </LineItem>
            <LineItem>
              <TaxType>OUTPUT</TaxType>
              <AccountCode>200</AccountCode>
              <UnitAmount>231.0000</UnitAmount>
              <Description>Example line item 3</Description>
              <Quantity>1</Quantity>
            </LineItem>
          </LineItems>
          <Type>ACCREC</Type>
          <DueDate>2015-07-06T16:25:02</DueDate>
        </Invoice>
        """

        self.assertXMLEqual(
            resultant_xml, expected_xml,
        )