コード例 #1
0
    def setUp(self) -> None:
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        self.client = self.app.test_client()

        # Create user
        self.user = User.from_json({
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'confirmed': True,
            'first_name': 'test_first_name',
            'last_name': 'test_last_name'
        })
        db.session.add(self.user)

        # Login user
        response = self.client.post(url_for('api.login'),
                                    headers=self.get_api_headers(
                                        'test_user', 'new_password'))
        self.token = response.json['token']

        # Create wallet
        self.wallet = Wallet.from_json({
            'title': 'test_wallet',
            'currency': 'usd',
            'initial_balance': randint(0, 100),
            'owner_id': self.user.id
        })
        db.session.add(self.wallet)
        db.session.commit()

        # Create parent category
        self.parent_category = ParentCategory.from_json({
            'title':
            'test_parent_category',
            'budget':
            randint(0, 1000),
            'is_income':
            choice([True, False]),
            'wallet_id':
            self.wallet.id
        })
        db.session.add(self.parent_category)
        db.session.commit()

        self.data = {
            'title': 'test_parent_category2',
            'budget': randint(0, 1000),
            'is_income': choice([True, False]),
            'wallet_id': self.wallet.id
        }
コード例 #2
0
    def test_get_all_wallets(self):
        """
        The test case for get_all_wallets view.
        """
        # Create 3 wallets
        for i in range(3):
            wallet = Wallet.from_json({
                'title': 'wallet{}'.format(i),
                'currency': choice(['usd', 'eur', 'rub']),
                'initial_balance': randint(0, 100),
                'owner_id': self.user.id
            })
            db.session.add(wallet)
        db.session.commit()

        response = self.client.get(url_for('api.get_all_wallets'),
                                   headers=self.get_token_headers(self.token))

        self.assertTrue(response.status_code == 200)
        self.assertTrue(len(response.json['wallets']) == 4)