There is a problem when I test my Model using unittest module,which is that nothing was displayed when the process was succeed except for a string came from the "print".the result of my Iteration of the users didnt show up.What i was dong is below:
1,models.py
class UserManager(models.Manager):
def hah(self):
return None
class User(models.Model):
id = models.IntegerField(primary_key=True)
email = models.CharField(unique=True, max_length=50)
password = models.CharField(max_length=50)
logintime = models.IntegerField(default='')
registertime = models.IntegerField()
modifytime = models.IntegerField()
loginip = models.CharField(max_length=60)
islock = models.IntegerField()
isavtive = models.IntegerField()
activecode = models.CharField(max_length=45)
role = models.CharField(max_length=1)
objects = UserManager()
class Meta:
db_table = 'user'
2,serializers.py
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id','email','password','loginip')
3,tests.py
class UserModelTest(unittest.TestCase):
def get_user(self):
users = User.objects.all()
userserializer = UserSerializer(users,many=True)
print(userserializer.data)
print(users)
for row in users:
print(row.email)
print("this is user model test")
When I ran python3.4 ./manage.py test user.tests.UserModelTest.get_user ,the results were:
Creating test database for alias 'default'...
[]
[]
this is user model test
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
Destroying test database for alias 'default'...
Did i miss something or any misunderstanding about unittest? And I notice someone has the same problem,what they are suggested to do is add -- -s option,but not work for me.And any solutions? Thanks in advance!