Example #1
0
 def addItem(self, period):
     entry = HistoryEntry(period)
     file = printJson(period)
     fileName = entry.fileName
     self._removeHistoryItem(fileName)
     self.dataProvider.addItem(printJson(entry), kind='historyitem')
     self.dataProvider.setItem(fileName, file)
Example #2
0
 def test(self):
     afbij = self.makeAfBij()
     afbij.addRow(
         self.rowFactory.createRow(['20180509', '34.67', 'in', 'paycheck']))
     afbijObj = printJson(afbij)
     self.assertEqual(afbijObj['from'], datetime(2018, 5, 9))
     self.assertEqual(afbijObj['hasBeginning'], True)
Example #3
0
 def test(self):
     category = self.makeCategory({
         'name':
         'test',
         'categories': [{
             'name': 'one',
             'acceptRow': {
                 'propertyContains': {
                     'name': 'info',
                     'values': ['nothing']
                 }
             }
         }, {
             'name': 'two'
         }]
     })
     row = self.rowFactory.createRow(
         ['20180509', '34.67', 'in', 'something on 08/05/2018 12:34'])
     self.assertEqual(category.canAddRow(row), True)
     category.addRow(row)
     self.assertEqual(
         printJson(category), {
             'name': 'test',
             'total': 3467,
             'categories': [{
                 'name': 'two',
                 'total': 3467
             }]
         })
Example #4
0
 def test(self):
     collection = self.rowCollectionFactory.getDefault({'default': True})
     collection.addRow(
         self.rowFactory.createRow(
             ['20180509', '34.67', 'in', 'something on 08/05/2018 12:34']))
     self.assertEqual(
         printJson(collection), {
             'items': [{
                 'properties': [{
                     'name': 'direction',
                     'type': 'direction',
                     'value': Direction.INCOMING
                 }, {
                     'name': 'date',
                     'type': 'date',
                     'value': datetime(2018, 5, 9)
                 }, {
                     'name': 'amount',
                     'type': 'amount',
                     'value': 3467
                 }, {
                     'name': 'info',
                     'type': 'string',
                     'value': 'something on 08/05/2018 12:34'
                 }]
             }]
         })
Example #5
0
 def test(self):
     collection = self.rowCollectionFactory.getDefault({
         'properties': [{
             'name': 'date',
             'source': 'info',
             'conversion': {
                 'type': 'date',
                 'pattern': r'%d/%m/%Y %H:%M'
             }
         }, {
             'name': 'amount',
             'source': 'amount'
         }],
         'displayLimit':
         3
     })
     for i in range(4):
         collection.addRow(
             self.rowFactory.createRow([
                 '20180509', '34.67', 'in', 'something on 08/05/2018 12:34'
             ]))
     collectionObj = printJson(collection)
     items = collectionObj['items']
     self.assertEqual(len(items), 3)
     self.assertTrue('more' in collectionObj)
     self.assertEqual(collectionObj['more'], 1)
Example #6
0
 def test(self):
     collection = self.rowCollectionFactory.getDefault({
         'properties': [{
             'name': 'date',
             'source': 'info',
             'conversion': {
                 'type': 'date',
                 'pattern': r'%d/%m/%Y %H:%M'
             }
         }, {
             'name': 'amount',
             'source': 'amount'
         }]
     })
     collection.addRow(
         self.rowFactory.createRow(
             ['20180509', '34.67', 'in', 'something on 08/05/2018 12:34']))
     self.assertEqual(
         printJson(collection), {
             'items': [{
                 'properties': [{
                     'name': 'date',
                     'type': 'date',
                     'value': datetime(2018, 5, 8, 12, 34)
                 }, {
                     'name': 'amount',
                     'type': 'amount',
                     'value': 3467
                 }]
             }]
         })
    def processCsv(self, csvfile):
        reader = csv.reader(csvfile, delimiter=',')
        rows = [
            self.rowFactory.createRow(csvRow)
            for csvRow in self.getSkippingReader(reader)
        ]
        days = set(map(lambda row: row['date'], rows))
        rowsByDay = [(day, [row for row in rows if row['date'] == day])
                     for day in days]
        rowsByDay.sort(key=lambda rd: rd[0])

        importer = TopCategory(self.rowCheckerFactory,
                               self.rowCollectionFactory,
                               self.categoriesConfiguration)

        for dayRows in rowsByDay:
            importer.addDayRows(dayRows[1])

        complete = importer.getComplete()
        incomplete = importer.getIncomplete()

        for c in complete:
            self.history.addItem(c)

        return printJson(
            PrintableList([
                PeriodFile.fromPeriod(period)
                for period in incomplete + complete
            ]))
Example #8
0
 def test(self):
     afbij = self.makeAfBij()
     afbij.addRow(
         self.rowFactory.createRow(
             ['20180509', '34.67', 'out', 'something']))
     afbijObj = printJson(afbij)
     self.assertEqual(
         afbijObj['Af'], {
             'name':
             'out',
             'total':
             3467,
             'categories': [{
                 'name': 'leftovers',
                 'total': 3467,
                 'rows': {
                     'items': [{
                         'properties': [{
                             'name': 'direction',
                             'value': Direction.OUTGOING,
                             'type': 'direction'
                         }, {
                             'name': 'date',
                             'value': datetime(2018, 5, 9),
                             'type': 'date'
                         }, {
                             'name': 'amount',
                             'value': 3467,
                             'type': 'amount'
                         }, {
                             'name': 'info',
                             'value': 'something',
                             'type': 'string'
                         }]
                     }]
                 }
             }]
         })
Example #9
0
 def test(self):
     collection = self.rowCollectionFactory.getDefault({
         'properties': [{
             'name': 'date',
             'source': 'date'
         }, {
             'name': 'infoPart',
             'source': 'info',
             'conversion': {
                 'type': 'string',
                 'match': r'(?<=abraham\s)(?:(?!\W).)*'
             }
         }, {
             'name': 'amount',
             'source': 'amount'
         }]
     })
     collection.addRow(
         self.rowFactory.createRow(
             ['20180509', '34.67', 'in', 'lincoln\'s car']))
     self.assertEqual(
         printJson(collection), {
             'items': [{
                 'properties': [{
                     'name': 'date',
                     'type': 'date',
                     'value': datetime(2018, 5, 9)
                 }, {
                     'name': 'infoPart',
                     'type': 'string',
                     'value': ''
                 }, {
                     'name': 'amount',
                     'type': 'amount',
                     'value': 3467
                 }]
             }]
         })
Example #10
0
 def test(self):
     category = self.makeCategory({'name': 'test', 'expect': 1})
     for i in range(3):
         category.addRow(
             self.rowFactory.createRow([
                 '20180509', '34.67', 'in', 'something on 08/05/2018 12:34'
             ]))
     self.assertEqual(
         printJson(category), {
             'name': 'test',
             'total': 3 * 3467,
             'expectation': {
                 'expected':
                 1,
                 'actual':
                 3,
                 'dates': [
                     datetime(2018, 5, 9),
                     datetime(2018, 5, 9),
                     datetime(2018, 5, 9)
                 ]
             }
         })
Example #11
0
 def test(self):
     category = self.makeCategory({'name': 'test', 'expect': 1})
     category.addRow(
         self.rowFactory.createRow(
             ['20180509', '34.67', 'in', 'something on 08/05/2018 12:34']))
     self.assertEqual(printJson(category), {'name': 'test', 'total': 3467})