from django.test import TestCase

from groups import models as group_model
from signup import models as signup_model
from signup import randata

import models

import random

class SimpleTest(TestCase):
    def test_prepare_groups(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(1)

        for i in range(100):
            random_group = random.choice(groups)
            random_user = random.choice(random_group['members'])

            self.assertEqual(random_group['timezone'], random_user['questions']['timezone'])


    def test_every_man_is_an_island(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        groups = models.prepare_groups(1, max_group_size=1)

        for i in range(100):
            random_group = random.choice(groups)
            random_user = random.choice(random_group['members'])
            self.assertEqual(random_group['timezone'], random_user['questions']['timezone'])
            self.assertEqual(len(random_group['members']), 1)

    def test_here_comes_everyone(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)
        groups = models.prepare_groups(1, max_group_size=1001)
        self.assertEqual(len(groups), 0)


    def test_group_creation(self):
        for signup in randata.random_data(1000):
            signup_model.create_or_update_signup(**signup)

        group_data = models.prepare_groups(1)
        models.create_groups(group_data, 'g-')
        groups = group_model.get_groups()

        self.assertEqual(len(group_data), len(groups))
        for i, member in enumerate(groups[0]['members']):
            self.assertEqual(member, group_data[0]['members'][i]['email'])


@@ -142,37 +142,151 @@
 ta%0A%0A
-import models%0A%0Aimport random%0A
+from mock import patch%0Aimport random%0Aimport math%0A%0Aimport models%0A%0A%0A@patch('signup.models.sequence_model.get_current_sequence_number', lambda: 1)
 %0Acla
@@ -509,235 +509,175 @@
     
-for i in range(100):%0A            random_group = random.choice(groups)%0A            random
+grouped
 _user
+s
  = 
-random.choice(random_group%5B'members'%5D)%0A%0A            self.assertEqual(random_group%5B'timezone'%5D, random_user%5B'questions'%5D%5B'timezone'%5D
+filter(lambda x: x%5B'questions'%5D%5B'groupRadios'%5D, signup_model.get_signups(1))%0A%0A        self.assertEquals(len(groups), math.ceil(len(grouped_users)/40.0)
 )%0A%0A%0A
@@ -905,231 +905,24 @@
 for 
-i in range(100):%0A            random_group = random.choice(groups)%0A            random_user = random.choice(random_group%5B'members'%5D)%0A            self.assertEqual(random_group%5B'timezone'%5D, random_user%5B'questions'%5D%5B'timezone'%5D)
+group in groups:
 %0A   
@@ -955,38 +955,21 @@
 len(
-random_group%5B'members'%5D
+group
 ), 1)%0A%0A
+%0A
     
@@ -1213,17 +1213,17 @@
 roups), 
-0
+1
 )%0A%0A%0A    
@@ -1354,32 +1354,41 @@
 gnup(**signup)%0A%0A
+        %0A
         group_da
@@ -1462,12 +1462,9 @@
 ta, 
-'g-'
+1
 )%0A  
@@ -1501,16 +1501,17 @@
 _groups(
+1
 )%0A%0A     
@@ -1564,138 +1564,4 @@
 s))%0A
-        for i, member in enumerate(groups%5B0%5D%5B'members'%5D):%0A            self.assertEqual(member, group_data%5B0%5D%5B'members'%5D%5Bi%5D%5B'email'%5D)%0A%0A

Fix tests for grouping