def test_update_with_parent(self): account_type = factories.AccountTypeFactory(account_type='Bank Accont') currency = factories.CurrencyFactory() o = dm.Account( account_id=self.tips.account_id, name='Acme', account_type=account_type.account_type, currency=currency.cur_code, description='Modified description', book=self.salary.book_id, parent_id=self.salary.account_id, ) qset = models.Account.objects.filter( account_id=o.account_id, name=o.name, description=o.description, account_type=account_type, currency=currency, book=self.salary.book, ) assert not qset.exists() self.query_obj.save(o) assert qset.exists() o = self.query_obj.get(o.book, o.account_id) assert o.path == 'Income::Salary::Acme'
def test_create_with_reference_not_exists(self, field): currency = factories.CurrencyFactory() o = dm.Account( name='Example', account_type=self.salary.account_type_id, currency=currency.cur_code, description='Example description', book=self.salary.book_id, parent_id=self.salary.account_id, ) setattr(o, field, 1000) with pytest.raises(query.IntegrityError): self.query_obj.save(o)
def test_shallow_domain_to_orm(self): obj = domain.Account( account_id=10, name='Education', book=3, account_type='Expense', currency='USD', description='Education Expense', ) instance = orm.domain_to_orm(obj) assert isinstance(instance, db.Account) assert instance.book_id == 3 assert instance.currency_id == 'USD' assert instance.account_type_id == 'Expense' assert instance.account_id == 10 assert instance.name == 'Education' assert instance.description == 'Education Expense'
def test_create_no_parent(self): currency = factories.CurrencyFactory() o = dm.Account( name='Other', account_type=self.salary.account_type_id, currency=currency.cur_code, description='Other description', book=self.salary.book_id, ) qset = models.Account.objects.filter( name=o.name, description=o.description, account_type=self.salary.account_type_id, currency=currency, book=self.salary.book, ) assert not qset.exists() self.query_obj.save(o) assert qset.exists()
def test_deep_domain_to_orm(self): obj = domain.Account( account_id=10, parent_id=2, path='Expense::Education', name='Education', book=self.book, account_type=self.account_type, currency=self.currency, description='Education Expense', ) instance = orm.domain_to_orm(obj) assert isinstance(instance, db.Account) assert instance.book_id == 3 assert instance.parent_id == 2 assert instance.currency_id == 'USD' assert instance.account_type_id == 'Expense' assert instance.account_id == 10 assert instance.name == 'Education' assert instance.path == 'Expense::Education' assert instance.description == 'Education Expense'
def test_dm_to_pd(self): obj = dm.Account( account_id=8, name='Chase Checking', account_type='Asset', currency='NIS', description='Test Account', book=1, parent_id=3, path='Bank::Chase Checking', ) ser = self.serializer_class(obj) data = ser.data assert data['account_type'] == 'Asset' assert data['account_id'] == 8 assert data['name'] == 'Chase Checking' assert data['account_type'] == 'Asset' assert data['currency'] == 'NIS' assert data['description'] == 'Test Account' assert data['book'] == 1 assert data['parent_id'] == 3 assert data['path'] == 'Bank::Chase Checking'
def test_create_with_parent(self): currency = factories.CurrencyFactory() o = dm.Account( name='Example', account_type=self.salary.account_type_id, currency=currency.cur_code, description='Example description', book=self.salary.book_id, parent_id=self.salary.account_id, ) qset = models.Account.objects.filter( name=o.name, description=o.description, account_type=self.salary.account_type_id, currency=currency, book=self.salary.book, ) assert not qset.exists() self.query_obj.save(o) assert qset.exists() o = self.query_obj.get(self.salary.book_id, qset.get().pk) assert o.parent_id == self.salary.account_id assert o.path == 'Income::Salary::Example'