Exemple #1
0
    def test_first_transaction(self):
        # The user creates two accounts
        accs_raw_data = [{
            "name": "Salary",
            "acc_type": "Leaf",
            "parent": get_root_acc().pk
        }, {
            "name": "Money",
            "acc_type": "Leaf",
            "parent": get_root_acc().pk
        }]
        accs = [
            self.post_json(URLS.account, raw_data)
            for raw_data in accs_raw_data
        ]

        # And the Yen currency
        euro_raw_data = {"name": "Yen"}
        euro = self.post_json(URLS.currency, euro_raw_data)

        # And it's first transaction ever!
        trans_raw_data = {
            "description":
            "Earned some money!",
            "date":
            "2018-01-01",
            "movements_specs": [
                {
                    "account": accs[0]['pk'],
                    "money": {
                        "quantity": -1000,
                        "currency": euro['pk']
                    }
                },
                {
                    "account": accs[1]['pk'],
                    "money": {
                        "quantity": 1000,
                        "currency": euro['pk']
                    }
                },
            ]
        }
        self.post_json(URLS.transaction, trans_raw_data)

        # Which now appears when querying for all transactions
        get_trans_resp = self.get_json(URLS.transaction)
        assert len(get_trans_resp) == 1
        assert get_trans_resp[0]['date'] == trans_raw_data['date']
Exemple #2
0
 def setUp(self):
     super().setUp()
     self.data = {
         'name': 'My Account',
         'acc_type': AccTypeEnum.BRANCH,
         'parent': get_root_acc()
     }
Exemple #3
0
 def setUp(self):
     super().setUp()
     account_type_populator()
     account_populator()
     self.data = {
         "name": "Acc",
         "acc_type": AccTypeEnum.LEAF.value,
         "parent": get_root_acc().pk
     }
Exemple #4
0
 def setUp(self):
     super().setUp()
     self.date_ = date(2017, 12, 24)
     self.accs = [
         AccountFactory()("A", AccTypeEnum.LEAF, get_root_acc()),
         AccountFactory()("B", AccTypeEnum.LEAF, get_root_acc())
     ]
     # Force second money to exactly offset the first.
     self.cur = CurrencyTestFactory()
     self.moneys = [Money(100, self.cur), Money(-100, self.cur)]
     self.data = {
         "description":
         "Hola",
         "date_":
         self.date_,
         "movements_specs":
         [MovementSpec(a, m) for a, m in zip(self.accs, self.moneys)]
     }
Exemple #5
0
class AccountTestFactory(f.DjangoModelFactory):
    class Meta:
        model = Account

    name = f.Sequence(lambda *a: faker.name())
    acc_type = f.LazyAttribute(lambda *a: AccTypeEnum.LEAF)
    parent = f.LazyAttribute(lambda *a: get_root_acc())

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        return AccountFactory()(*args, **kwargs)
Exemple #6
0
 def test_post_for_new_account(self):
     self.populate_accounts()
     root_acc = get_root_acc()
     acc_data = {
         "name": "MyAcc",
         "acc_type": "Branch",
         "parent": root_acc.pk
     }
     request = self.req_fact.post(f'/accounts/', acc_data)
     resp = resolve(f'/accounts/').func(request)
     assert resp.status_code == 201, resp.data
     assert Account.objects.filter(name="MyAcc").exists()
Exemple #7
0
    def test_user_changes_account_hierarchy(self):
        # The user had previously created an Current Account whose
        # father was Root Account
        root = get_root_acc()
        cur_acc = AccountTestFactory(name="Current Account",
                                     parent=root,
                                     acc_type=AccTypeEnum.LEAF)

        # Now it wants to have Current Accounts as a child of Root, and
        # two specific accounts for two different Current Accounts
        # .
        # | -- Root Account
        # |    |-- Current Account
        # |    |   |-- Current Account Itau
        # |    |   `-- Current Account LaCaixa

        # It currects the name of the existant account
        self.patch_json(f"{URLS.account}{cur_acc.pk}/",
                        {"name": "Current Account Itau"})
        # And sees that it worked
        accounts = self.get_json(URLS.account)
        _assert_contains(accounts, 'name', 'Current Account Itau')
        _assert_not_contains(accounts, 'name', "Current Account")

        # He creates the new father for it
        new_father_data = {
            "name": "Current Account",
            "parent": root.pk,
            "acc_type": "Branch"
        }
        new_father = self.post_json(URLS.account, new_father_data)
        # And sees that it worked
        accounts = self.get_json(URLS.account)
        _assert_contains(accounts, 'name', new_father_data['name'])

        # He sets the old acc to have this father
        resp_data = self.patch_json(f"{URLS.account}{cur_acc.pk}/",
                                    json={"parent": new_father['pk']})
        assert resp_data['parent'] == new_father['pk']

        # And creates the new account
        self.post_json(URLS.account,
                       json={
                           "name": "Current Account LaCaixa",
                           "parent": new_father['pk'],
                           "acc_type": "Leaf"
                       })

        accounts = self.get_json(URLS.account)
        _assert_contains(accounts, 'name', "Current Account LaCaixa")
Exemple #8
0
 def test_base_creation(self):
     acc = self.call()
     assert acc.name == self.data['name']
     assert acc.acc_type == AccountType.objects.get(name='Branch')
     assert acc.parent == get_root_acc()