def test_profile_middleware_no_profile(self): """User without profile and isn't banned""" req = self.request('/projects/import', method='post', data=self.data) req.user = get(User, profile=None) resp = ImportWizardView.as_view()(req) self.assertEqual(resp.status_code, 302) self.assertEqual(resp['location'], '/projects/foobar/')
def test_profile_middleware_spam(self, form): """User will be banned""" form.side_effect = ProjectSpamError req = self.request('/projects/import', method='post', data=self.data) req.user = get(User) resp = ImportWizardView.as_view()(req) self.assertEqual(resp.status_code, 302) self.assertEqual(resp['location'], '/') self.assertTrue(req.user.profile.banned)
def test_profile_middleware_banned(self): """User is banned""" req = self.request('/projects/import', method='post', data=self.data) req.user = get(User) req.user.profile.banned = True req.user.profile.save() self.assertTrue(req.user.profile.banned) resp = ImportWizardView.as_view()(req) self.assertEqual(resp.status_code, 302) self.assertEqual(resp['location'], '/')