def setUp(self):
     super(TestCreateUser, self).setUp()
     self.user = factories.User(permissions=self.permissions)
     self.login_user(self.user)
     self.post_data = {
         'username': '******',
         'first_name': 'Sam',
         'last_name': 'Blue',
         'email': '*****@*****.**',
         'is_active': False,
         'is_staff': True,
         'groups': [factories.Group().pk,
                    factories.Group().pk],
         'password1': 'aaa',
         'password2': 'aaa',
     }
 def setUp(self):
     super(TestEditUser, self).setUp()
     self.user = factories.User(permissions=self.permissions)
     self.login_user(self.user)
     self.obj = self.factory.create()
     self.url_kwargs = {self.pk_url_kwarg: self.obj.pk}
     self.post_data = {
         'username': '******',
         'first_name': 'Sam',
         'last_name': 'Blue',
         'email': '*****@*****.**',
         'is_active': False,
         'is_staff': True,
         'groups': [factories.Group().pk,
                    factories.Group().pk],
     }
 def test_edit_groups(self):
     """Should be able to update user's auth groups."""
     groups = [factories.Group() for i in range(2)]
     self.post_data['groups'] = [g.pk for g in groups]
     response = self._post()
     self.assertRedirectsNoFollow(response, self.obj.get_absolute_url())
     updated_user = User.objects.get(pk=self.obj.pk)
     self.assertEquals(updated_user.groups.count(), 2)
     self.assertTrue(groups[0] in updated_user.groups.all())
     self.assertTrue(groups[1] in updated_user.groups.all())
    def test_users(self):
        """Should retrieve all users who can_clock_in."""
        perm = Permission.objects.get(codename='can_clock_in')
        group = factories.Group()
        group.permissions.add(perm)

        group_user = factories.User()
        group_user.groups.add(group)
        perm_user = self.user
        super_user = self.superuser

        self.login_user(self.manager)
        response = self.client.get(self.ajax_url)
        self.assertEquals(response.status_code, 200)
        users = [u['id'] for u in json.loads(response.content)['all_users']]
        self.assertEquals(len(users), 3)
        self.assertTrue(group_user.id in users)
        self.assertTrue(perm_user.id in users)
        self.assertTrue(super_user.id in users)