def test_type_to_user(self):
        xr = self.client.get('/testapp.use.testapp.nomodel/')
        self.assertEqual(xr.status_code, 302)
        xr = self.client.get('/testapp.use.testapp.testmodel/')
        self.assertEqual(xr.status_code, 302)
        
        self.client.login(username='user', password='')
        # logged in, but without correct perm
        xr = self.client.get('/testapp.use.testapp.nomodel/')
        self.assertEqual(xr.status_code, 302)
        xr = self.client.get('/testapp.use.testapp.testmodel/')
        self.assertEqual(xr.status_code, 302)
        
        AppPermission.objects.assign('rubberstamp.manage.rubberstamp.apppermission', self.user)
        # nonexistent should raise 404
        xr = self.client.get('/testapp.use.testapp.nomodel/')
        self.assertEqual(xr.status_code, 404)
        # model to which this perm doesn't apply should raise 404
        xr = self.client.get('/testapp.use.auth.user/')
        self.assertEqual(xr.status_code, 404)
        r = self.client.get('/testapp.use.testapp.testmodel/')
        self.assertEqual(r.status_code, 200)
        
        assign_form = r.context['assign_form']
        self.assertFalse(assign_form.is_bound)
        self.assertRaises(KeyError, lambda: r.context['objects'])
        
        post_dict = {
            'users': ['4', '5'],
        }
        rp = self.client.post('/testapp.use.testapp.testmodel/', post_dict)
        self.assertEqual(rp.status_code, 200)
        assign_form = rp.context['assign_form']
        self.assertTrue(assign_form.is_valid())
        user4 = User.objects.get(pk=4)
        self.assertTrue(user4.has_perm('testapp.use.testapp.testmodel'))
Assign a permission for a type to a user.
dataset/ETHPy150Open jlecker/django-rubberstamp/rubberstamp/tests/views.py/ViewTest.test_type_to_user