def make_split(self, dbs): return dm.Split( account_id=dbs.account_id, number=dbs.number, description=dbs.description, amount=dbs.amount, status=dbs.status, )
def mod_split(self, split): return dm.Split( account_id=split['account_id'], number=split['number'] + 'm', description='x' + split['description'], amount=split['amount'] * 2, status='r', )
def test_update_transaction(self, xdata): self.assert_transaction_exists(xdata) updated = dm.Transaction( date=xdata['date'] + timedelta(1), description='updated description', transaction_id=xdata['transaction_id'], splits=[dm.Split(s) for s in xdata['splits']], ) db_o = self.query_obj.save(updated) assert db_o.transaction_id == updated.transaction_id assert db_o.split_set.count() == 2 self.assert_transaction_exists(updated)
def domain_obj(self): return dm.Transaction( transaction_id=248, date=date(2015, 7, 16), description='Birthday card', splits=[ dm.Split( split_id=613, number=365, account_id=10, status='c', amount=-25, ), dm.Split( split_id=614, description='Moked', account_id=18, amount=25, ), ], )
def test_create_transaction(self): sa = { 'number': '101', 'account_id': self.salary.account_id, 'status': 'n', 'amount': -8000, 'description': '', } sb = { 'number': '1432', 'account_id': self.citibank.account_id, 'status': 'n', 'amount': 8000, 'description': '', } xact = { 'date': date(2015, 7, 26), 'description': 'Payday', } splits = [dm.Split(sa), dm.Split(sb)] xact_obj = dm.Transaction(xact, splits=splits) self.assert_transaction_not_exists(xact, [sa, sb]) self.query_obj.save(xact_obj) self.assert_transaction_exists(xact, [sa, sb])
def test_domain_to_orm(self): obj = domain.Split( split_id=613, number='365', description='Split Desc', account_id=12, status='n', amount='18', ) instance = orm.domain_to_orm(obj) assert isinstance(instance, db.Split) assert instance.split_id == 613 assert instance.number == '365' assert instance.description == 'Split Desc' assert instance.account_id == 12 assert instance.status == 'n' assert instance.amount == '18'
def test_dm_to_pd(self): obj = dm.Split( split_id=53, number='100', description='Paycheck', account_id=3, status='c', amount=-8000, ) ser = self.serializer_class(obj) data = ser.data assert 'split_id' not in data assert data['number'] == '100' assert data['description'] == 'Paycheck' assert data['account_id'] == 3 assert data['status'] == 'c' assert data['amount'] == '-8000.00'
def update(self, instance, validated_data): data = validated_data.copy() # this won't support partial split updates data['splits'] = [dm.Split(**sdata) for sdata in data['splits']] return super(TransactionSerializer, self).update(instance, data)
def create(self, validated_data): data = validated_data.copy() data['splits'] = [dm.Split(**sdata) for sdata in data['splits']] return super(TransactionSerializer, self).create(data)