def create_settings(self): settings = ( (SiteSettingKey.ENABLE_COMMENTS, 'True'), (SiteSettingKey.ENABLE_REGISTRATION, 'True'), (SiteSettingKey.ENABLE_UPLOADS, 'True'), ) for k, v in settings: SiteSetting.set_val(k, v, self.user)
def test_account_register_view_post_invalid(self): SiteSetting.set_val(SiteSettingKey.ENABLE_REGISTRATION, 'True', self.user) self.client.logout() response = self.client.post(reverse('account.register'), { 'username': '******', 'password1': '1234', 'password2': '5678', }) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'account/account-register.html')
def test_account_register_view_post_disabled(self): SiteSetting.set_val(SiteSettingKey.ENABLE_REGISTRATION, 'False', self.user) challenge, response = settings.get_challenge()() store = CaptchaStore.objects.create(challenge=challenge, response=response) self.client.logout() response = self.client.post(reverse('account.register'), { 'username': '******', 'password1': 'password', 'password2': 'password', 'next': reverse('tag.list.author'), 'captcha_0': store.hashkey, 'captcha_1': store.response, }) self.assertRedirects(response, reverse('account.register'))
def test_site_setting_form(self): SiteSetting.set_val(SiteSettingKey.ANNOUNCEMENT, 'This is a sample announcement', self.user) SiteSetting.set_val(SiteSettingKey.ENABLE_COMMENTS, 'True', self.user) SiteSetting.set_val(SiteSettingKey.ENABLE_UPLOADS, 'False', self.user) form = SiteSettingForm() self.assertEqual(form.fields['announcement'].initial, 'This is a sample announcement') self.assertEqual(form.fields['enable_comments'].initial, True) self.assertEqual(form.fields['enable_uploads'].initial, False)
def test_upload_list_view_post_disabled(self): SiteSetting.set_val(SiteSettingKey.ENABLE_UPLOADS, 'False', self.user) response = self.client.post(reverse('upload.list')) self.assertRedirects(response, reverse('upload.list'))
def save_setting(self, key, user): val = self.cleaned_data.get(key.lower()) SiteSetting.set_val(key, val, user)