import random
import unittest
from django.contrib.auth.models import User
from website.models.userDetail import UserSearch


class ModelUnitTests(unittest.TestCase):
    def setUp(self):
        user = User.objects.create_user("testuser", "testuser@testing.solarpermit.org", "testuser")
        user.save()

    def test_user_search(self):
        user = User.objects.all()[0] #just get 1st user
        entity_id_range = range(1, 11) #1 to 10
        
        for index in entity_id_range:
            user_search = UserSearch(user=user, entity_name='Jurisdiction', entity_id=index)
            user_search.label = 'Initial Label ' + str(index)
            user_search.save()
        #repeat, but old ones should be deleted by itself
        for index in entity_id_range:
            user_search = UserSearch(user=user, entity_name='Jurisdiction', entity_id=index)
            user_search.label = 'Changed Label ' + str(index)
            user_search.save()
        
        user_searches = UserSearch.objects.filter(user=user, entity_name='Jurisdiction', entity_id__in=entity_id_range)
        self.assertEqual(10, len(user_searches), 'Got '+str(len(user_searches))+' user_searches instead of 10.')
        
        user_searches = UserSearch.objects.filter(user=user, entity_name='Jurisdiction', entity_id__in=entity_id_range, label='Changed Label 10')
        self.assertEqual(1, len(user_searches), 'Got '+str(len(user_searches))+' user_searches with "Changed Label 10" instead of 1.')
        
    def runTest(self):
        self.test_user_search()

@@ -180,32 +180,37 @@
 (self):%0A        
+self.
 user = User.obje
@@ -289,24 +289,29 @@
 r%22)%0A        
+self.
 user.save()%0A
@@ -321,30 +321,22 @@
   def te
-st_user_search
+arDown
 (self):%0A
@@ -347,55 +347,59 @@
     
-u
 se
-r = User.objects.all()%5B0%5D #just get 1st 
+lf.user.delete()%0A%0A    def test_
 user
+_search(self):
 %0A   
@@ -524,32 +524,37 @@
 UserSearch(user=
+self.
 user, entity_nam
@@ -815,24 +815,29 @@
 Search(user=
+self.
 user, entity
@@ -1024,32 +1024,37 @@
 cts.filter(user=
+self.
 user, entity_nam
@@ -1279,16 +1279,21 @@
 er(user=
+self.
 user, en

test should not rely on the first user being the one it wants