from django.test import TestCase
from users.models import User

from django.core.exceptions import ValidationError

class UserPasswordTest(TestCase):
    def setUp(self):
        self.user = User()
        self.valid_email = "test@example.com"
        self.valid_password = "123456"
        self.invalid_password = "12345"

    def test_user_should_have_password_field(self):
        try:
            self.user.password
        except AttributeError:
            self.fail("User should have password field")

    def test_user_password_is_at_least_6_digit(self):
        self.user.password = self.valid_password
        self.assertGreaterEqual(len(self.user.password),6,"phone number is less than 6")

    def test_user_with_short_password_should_not_be_valid(self):
        self.assertRaises(ValidationError, User.objects.create_user,
                email = self.valid_email,
                password = self.invalid_password )

    def test_user_password_should_be_encrypted(self):
        user = User.objects.create_user( email = self.valid_email, password = self.valid_password )
        self.assertNotEqual(self.valid_password, user.password)

@@ -285,31 +285,74 @@
        self.
-invalid
+too_short_password = %22a%22 * 5%0A        self.too_long
 _password = 
@@ -356,14 +356,16 @@
  = %22
-12345%22
+a%22 * 256
 %0A%0A  
@@ -404,14 +404,8 @@
 word
-_field
 (sel
@@ -420,123 +420,47 @@
     
-try:%0A            self.user.password%0A        except AttributeError:%0A            self.fail(%22User should have 
+self.assertIsNotNone(self.user.
 password
  fie
@@ -459,15 +459,8 @@
 word
- field%22
 )%0A%0A 
@@ -489,27 +489,16 @@
 ord_
-is_at_least_6_digit
+validate
 (sel
@@ -582,16 +582,29 @@
 erEqual(
+%0A            
 len(self
@@ -623,10 +623,36 @@
 rd),
-6,
+%0A            6,%0A            
 %22pho
@@ -676,16 +676,26 @@
  than 6%22
+,%0A        
 )%0A%0A    d
@@ -711,47 +711,260 @@
 ser_
-with_short_password_should_not_be_valid
+password_too_short(self):%0A        self.assertRaises(%0A            ValidationError, %0A            User.objects.create_user,%0A            email = self.valid_email,%0A            password = self.too_short_password%0A        )%0A%0A    def test_user_password_too_long
 (sel
@@ -993,16 +993,29 @@
 tRaises(
+%0A            
 Validati
@@ -1023,16 +1023,29 @@
 nError, 
+%0A            
 User.obj
@@ -1066,36 +1066,32 @@
 er,%0A            
- 
-   
 email = self.val
@@ -1104,36 +1104,32 @@
 il,%0A            
-    
 password = self.
@@ -1132,15 +1132,16 @@
 elf.
-invalid
+too_long
 _pas
@@ -1145,16 +1145,24 @@
 password
+%0A       
  )%0A%0A    
@@ -1251,16 +1251,28 @@
 te_user(
+%0A           
  email =
@@ -1290,16 +1290,29 @@
 _email, 
+%0A            
 password
@@ -1333,16 +1333,24 @@
 password
+%0A       
  )%0A     

test password max characters test added and refactored