Reputation: 101
Code below is unit test I'm writing for a flask app but results in the following error when I run the test:
File "/Users/ausername/projects/term_trader/tt2/tests/testRoutes.py", line 47, in test_deposit_route
response = self.app.post(BASE_URL,
AttributeError: 'TestRoutes' object has no attribute 'app'
Imports look okay to me as I had some other tests running out of a 'tests' folder with no issue. The routes themselves work just fine when I tested them in curl, I'm just trying to get in the habit of writing tests. Just can't seem to figure out what the issue is. This is flask version 1.0.3. Any advise is appreciated.
Code:
from unittest import TestCase
from model.user import User
from model.position import Position
from model.trade import Trade
from flask_app.app import app
from schema import build_user, build_positions, build_trades
import json
import os
BASE_URL = 'http://localhost:5000/api/'
class TestRoutes(TestCase):
def setup(self):
self.app.config['TESTING'] = True
self.app.config['DEBUG'] = False
self.app = app.test_client()
build_user()
build_positions()
build_trades()
bob = User(**{
"user_name": "bobdean",
"password": "password",
"real_name": "Bob Dean",
"balance": 0.0
})
bob.hash_password("password")
bob.api_key = "11111111111111111111"
bob.save()
def tearDown(self):
pass
def test_deposit_route(self):
bob = User.from_pk(1)
self.assertEqual(mike.user_name, "bobdean")
deposit = {"amount":1500.0}
response = self.app.post(BASE_URL,
data=json.dumps(deposit),
content_type='application/json')
self.assertEqual(response.status_code, 201, "Status Code should be 201")
self.assertEqual(bob.balance, 1500.0, "Bob's balance should equal 1500")
Upvotes: 0
Views: 1246