python - Django Test Case Can't run method -
i getting started django, may stupid, not sure google @ point.
i have method looks this:
def get_user(self,user): return utilities.get_userprofile(user)
the method looks this:
@staticmethod def get_userprofile(user): return userprofile.objects.filter(user_auth__username=user)[0]
when include in view, fine. when write test case use of methods inside utility class, none back:
two test cases:
def test_stack_overflow(self): = objname() print(a.get_user('admin')) def test_utility(self): print(utilities.get_user('admin'))
results:
creating test database alias 'default'... none ..none . ----------------------------------------------------------------------
can tell me why working in view, not working inside of test case , not generate error messages?
thanks
verify whether unit test comply followings,
testclass
must written in file nametest*.py
testclass
must have been subclassed unittest.testcasetestclass
should havesetup
function create objects(usually done in way, objects creation can happen in test functions well) in databasetestclass
functions should starttest
identified , run./manage.py
test commandtestclass
may haveteardown
end unit test case.
test case execution process:
when run ./manage.py test
django sets test_your_database_name
, creates objects mentioned in setup
function(usually) , starts executing test functions in order of placement inside class , once when test functions executed, looks teardown
function executes if present in test class , destroys test database.
it may be because might not have invoked objects creation in setup function or elsewhere in testclass
.
can kindly post entire traceback , test file better?
Comments
Post a Comment