예제 #1
0
 def test__convertstringfields_in_list_of_dicts(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = [{
         'clientnr': 123,
         'showcontact': True,
         'timestamp': datetime(2013, 12, 31, 0, 0)
     }, {
         'clientnr': 124,
         'showcontact': False,
         'timestamp': datetime(2012, 1, 1, 0, 0)
     }]
     expected_output = [{
         'clientnr': '123',
         'showcontact': 'true',
         'timestamp': '2013-12-31'
     }, {
         'clientnr': '124',
         'showcontact': 'false',
         'timestamp': '2012-01-01'
     }]
     test_output = fact._convertstringfields_in_list_of_dicts(
         test_input, 'clients', 'tostring')
     self.assertListEqual(test_output, expected_output)
     try:
         test_output = fact._convertstringfields_in_list_of_dicts(
             test_input, 'clients', 'wrongargument')
         self.fail(
             "_convertstringfields_in_dict should throw exception when called wrong"
         )
     except factuursturen.FactuursturenWrongCall:
         pass
예제 #2
0
 def test__wrongauth(self):
     apikey = 'foo'
     try:
         fact = factuursturen.Client(apikey)
         self.fail("test should fail when only half auth is passed")
     except factuursturen.FactuursturenNoAuth:
         pass
예제 #3
0
 def test__string2bool(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = 'true'
     test_output = fact._string2bool(test_input)
     self.assertEqual(test_output, True)
     self.assertIsInstance(test_output, bool)
예제 #4
0
 def test__date2string(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = datetime(2013, 12, 31, 0, 0)
     test_output = fact._date2string(test_input)
     self.assertEqual(test_output, "2013-12-31")
     self.assertIsInstance(test_output, str)
예제 #5
0
 def test__float2string(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = 123.45
     test_output = fact._float2string(test_input)
     self.assertEqual(test_output, '123.45')
     self.assertIsInstance(test_output, str)
예제 #6
0
 def test__bool2string(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = True
     test_output = fact._bool2string(test_input)
     self.assertEqual(test_output, 'true')
     self.assertIsInstance(test_output, str)
예제 #7
0
 def test__string2float(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = '123.450'
     test_output = fact._string2float(test_input)
     self.assertEqual(test_output, 123.45)
     self.assertIsInstance(test_output, float)
     test_input = 'A123.450'
     try:
         test_output = fact._string2float(test_input)
     except factuursturen.FactuursturenConversionError:
         pass
예제 #8
0
 def test__string2date(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = "2013-12-31"
     test_output = fact._string2date(test_input)
     self.assertEqual(test_output, datetime(2013, 12, 31, 0, 0))
     self.assertIsInstance(test_output, datetime)
     test_input = "2013-12-32"
     try:
         test_output = fact._string2date(test_input)
         self.fail('2013-12-32 should throw exception when converted to')
     except factuursturen.FactuursturenConversionError:
         pass
예제 #9
0
 def test__int2string(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = 123
     test_output = fact._int2string(test_input)
     self.assertEqual(test_output, '123')
     self.assertIsInstance(test_output, str)
     test_input = 123.45
     try:
         test_output = fact._int2string(test_input)
         self.fail(
             '123.45 should throw exception when converted from int to string'
         )
     except factuursturen.FactuursturenConversionError:
         pass
예제 #10
0
    def test__translated(self):
        apikey = 'foo'
        username = '******'
        fact = factuursturen.Client(apikey, username)
        test_input = {
            'clientnr': 123,
            'showcontact': True,
            'reference': {
                'line1': 'remark1',
                'line2': 'remark2'
            }
        }

        expected_output = {
            'clientnr': '123',
            'showcontact': 'true',
            'reference[line1]': 'remark1',
            'reference[line2]': 'remark2'
        }
        test_output = fact._prepare_for_send(test_input, 'clients')
        self.assertDictEqual(test_output, expected_output)
예제 #11
0
 def test__fixkeynames(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     testinput = {
         'lines[line0][amount_desc]': 1,
         'lines[line0][tax]': 1,
         'lines[line1][amount_desc]': 1,
         'lines[line1][tax]': 1,
         'lines[line2][amount_desc]': 1,
         'lines[line2][tax]': 1
     }
     expected_output = {
         'lines[0][amount_desc]': 1,
         'lines[0][tax]': 1,
         'lines[1][amount_desc]': 1,
         'lines[1][tax]': 1,
         'lines[2][amount_desc]': 1,
         'lines[2][tax]': 1
     }
     test_output = fact._fixkeynames(testinput)
     self.assertDictEqual(test_output, expected_output)
예제 #12
0
 def test__flatten(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     test_input = {
         'lines': {
             'line1': {
                 'amount': 1,
                 'tax': 21
             },
             'line2': {
                 'amount': 2,
                 'tax': 21
             }
         }
     }
     expected_output = {
         'lines[line1][amount]': 1,
         'lines[line1][tax]': 21,
         'lines[line2][amount]': 2,
         'lines[line2][tax]': 21
     }
     test_output = fact._flatten(test_input)
     self.assertDictEqual(test_output, expected_output)
예제 #13
0
    else:
        file_logger = logging.StreamHandler()
    file_logger.setLevel(loglevel)
    file_logger.setFormatter(formatter)
    logger.addHandler(file_logger)

    return logger


if __name__ == '__main__':
    arguments = do_options()
    logger = setLogger(arguments)

    mkdir_p(arguments.directory)

    fact = factuursturen.Client(apikey=arguments.apikey,
                                username=arguments.username)
    logger.debug("using username {}".format(fact._username))

    invoices = fact.get('invoices')
    logger.debug("got {} invoices from API".format(len(invoices)))

    for invoice in invoices:
        invoicenr = invoice[u'invoicenr']
        invoicefilename = invoicenr.replace('/', '_')
        year = invoice[u'sent'].year
        if arguments.id is None or invoicenr in arguments.id:
            logger.debug("invoice {} from year {}".format(invoicenr, year))
            if arguments.year:
                mkdir_p('{}/{}'.format(arguments.directory, year))
                filename = '{}/{}/{}.pdf'.format(arguments.directory, year,
                                                 invoicefilename)
예제 #14
0
 def test_remaining(self):
     apikey = 'foo'
     username = '******'
     fact = factuursturen.Client(apikey, username)
     fact._remaining = 1234
     self.assertEqual(fact.remaining, 1234)