Example #1
0
class TestUpdateChangedEntities(CommonTest):
    def setUp(self):
        self.account = Account()

        self.client = factory.create_client(budgetname='budgetname',
                                            nynabconnection=MockConnection(),
                                            sync=False)
        self.client.budget.be_accounts = [self.account]
        self.account2 = self.account.copy()
        self.client.session.commit()

    def testupdateChangedEntities_add(self):
        new_account = Account()
        changed_entities = dict(be_accounts=[new_account])
        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 2)
        self.assertIn(new_account, self.client.budget.be_accounts)

    def testupdateChangedEntities_delete(self):
        self.account2.is_tombstone = True
        changed_entities = dict(be_accounts=[self.account2])
        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 0)

    def testupdateChangedEntities_modify(self):
        self.account2 = self.account.copy()
        self.account2.note = 'note'
        changed_entities = dict(be_accounts=[self.account2])

        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 1)
        acc = self.client.budget.be_accounts[0]
        self.assertEqual(acc, self.account2)
Example #2
0
class TestUpdateChangedEntities(CommonTest):
    def setUp(self):
        super(TestUpdateChangedEntities, self).setUp()
        self.account = Account()
        self.client = nYnabClient_(budgetname='Mock Budget')
        self.client.budget.be_accounts = [self.account]
        self.account2 = self.account.copy()
        self.client.session.commit()

    def testupdateChangedEntities_add(self):
        new_account = Account()
        changed_entities = dict(be_accounts=[new_account])
        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 2)
        self.assertIn(new_account, self.client.budget.be_accounts)

    def testupdateChangedEntities_delete(self):
        self.account2.is_tombstone = True
        changed_entities = dict(be_accounts=[self.account2])
        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 0)

    def testupdateChangedEntities_modify(self):
        self.account2 = self.account.copy()
        self.account2.note = 'note'
        changed_entities = dict(be_accounts=[self.account2])

        self.client.budgetClient.update_from_changed_entities(changed_entities)
        self.assertEqual(len(self.client.budget.be_accounts), 1)
        acc = self.client.budget.be_accounts[0]
        self.assertEqual(acc, self.account2)
Example #3
0
class TestGetChangedEntities(CommonTest):
    def setUp(self):
        super(TestGetChangedEntities, self).setUp()
        self.obj = Budget()
        self.account = Account()
        self.obj.be_accounts = [self.account]
        self.obj.clear_changed_entities()
        self.account2 = Account(id=self.account)

    def testgetChangedEntities_add(self):
        added_account = Account()
        self.obj.be_accounts.append(added_account)
        changed_entities = self.obj.get_changed_entities()
        self.assertEqual(changed_entities, {'be_accounts': [added_account]})

    def testgetChangedEntities_delete(self):
        self.obj.be_accounts.remove(self.account)
        changed_entities = self.obj.get_changed_entities()
        deleted = self.account.copy()
        deleted.is_tombstone = True
        self.assertEqual(changed_entities, {'be_accounts': [deleted]})

    def testgetChangedEntities_modify(self):
        self.account.account_name = 'BLA'
        changed_entities = self.obj.get_changed_entities()
        self.assertEqual(changed_entities, {'be_accounts': [self.account]})
Example #4
0
class TestGetChangedEntities(CommonTest):
    def setUp(self):
        super(TestGetChangedEntities, self).setUp()
        self.obj = Budget()
        self.account = Account()
        self.obj.be_accounts = [self.account]
        self.obj.clear_changed_entities()
        self.account2 = Account(id=self.account)

        self.client = factory.create_client(budget_name='budgetname',
                                            nynabconnection=MockConnection(),
                                            sync=False)

    def testgetChangedEntities_add(self):
        added_account = Account()
        self.obj.be_accounts.append(added_account)
        changed_entities = self.obj.get_changed_entities()
        self.assertEqual(changed_entities, {'be_accounts': [added_account]})

    def testgetChangedEntities_addtransactionsubtransaction(self):
        added_transaction = Transaction()
        subtransaction1 = Subtransaction(
            entities_transaction=added_transaction)
        subtransaction2 = Subtransaction(
            entities_transaction=added_transaction)

        self.client.budget.be_transactions.append(added_transaction)
        self.client.budget.be_subtransactions.append(subtransaction1)
        self.client.budget.be_subtransactions.append(subtransaction2)

        self.client.session.commit()

        changed_entities = self.client.budget.get_changed_entities()
        self.assertIsInstance(changed_entities, dict)
        self.assertEqual(1, len(changed_entities.keys()))
        self.assertEqual('be_transaction_groups',
                         list(changed_entities.keys())[0])
        transaction_groups = changed_entities['be_transaction_groups']

        self.assertEqual(1, len(transaction_groups))
        self.assertEqual(added_transaction,
                         transaction_groups[0]['be_transaction'])

        self.assertIsNotNone(transaction_groups[0]['be_subtransactions'])
        try:
            self.assertItemsEqual(
                [subtransaction1, subtransaction2],
                set(transaction_groups[0]['be_subtransactions']))
        except AttributeError:
            self.assertCountEqual(
                [subtransaction1, subtransaction2],
                set(transaction_groups[0]['be_subtransactions']))

    def testgetChangedEntities_delete(self):
        self.obj.be_accounts.remove(self.account)
        changed_entities = self.obj.get_changed_entities()
        deleted = self.account.copy()
        deleted.is_tombstone = True
        self.assertEqual(changed_entities, {'be_accounts': [deleted]})

    def testgetChangedEntities_modify(self):
        self.account.account_name = 'BLA'
        changed_entities = self.obj.get_changed_entities()
        self.assertEqual(changed_entities, {'be_accounts': [self.account]})

    def test_arraytype(self):
        user = User()
        user.feature_flags = ['featureA', 'feature1']
        self.session.add(user)
        self.session.commit()

        fetched_user = self.session.query(User).first()
        self.assertEqual(user, fetched_user)
Example #5
0
 def test_copy(self):
     obj = Account()
     objc = obj.copy()
     self.assertEqual(obj.id, objc.id)
     self.assertEqual(obj.get_dict(), objc.get_dict())
Example #6
0
def test_copy():
    obj = Account()
    objc = obj.copy()
    assert obj.id == objc.id
    assert obj.get_dict() == objc.get_dict()