def test_invalid_blog_creation_name_too_long(self): user = self.admin blog_name = ("My first blog has a ridiculously long name and I'm " + "not embarrassed by it lol AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") data = {'blogName': blog_name, 'catagories': [str(self.cat1.id), str(self.cat2.id)]} form = BlogForm(data) self.assertFalse(form.is_valid())
def create_blog(request): if request.user.is_superuser: if request.method == 'POST': form = BlogForm(request.POST) if form.is_valid(): created_blog = form.save() #add the catagories from the form to image clean_catagories = form.cleaned_data.get('catagories') for cat in clean_catagories: created_blog.catagories.add(cat) #Redirect to blog list view return redirect('blogs') else: form = BlogForm() return render(request, 'blogs/create_blog.html', {'form': form}) else: return redirect('index')
def test_blog_creation_catagories_help_text(self): form = BlogForm() self.assertEqual(form.fields['catagories'].help_text, "Catagories Relevant to Blog Being Created")
def test_blog_creation_blog_name_label_text(self): form = BlogForm() self.assertEqual(form.fields['blogName'].label, "Blog Name")
def test_blog_creation_blog_name_help_text(self): form = BlogForm() self.assertEqual(form.fields['blogName'].help_text, "Name For the Blog")
def test_invalid_blog_creation_no_catagory_selected(self): user = self.admin blog_name = "My first blog" data = {'blogName': blog_name} form = BlogForm(data) self.assertFalse(form.is_valid())
def test_invalid_blog_creation_no_blog_name(self): user = self.admin blog_name = "My first blog" data = {'catagories': [str(self.cat1.id), str(self.cat2.id)]} form = BlogForm(data) self.assertFalse(form.is_valid())
def test_valid_blog_creation(self): user = self.admin blog_name = "My first blog" data = {'blogName': blog_name, 'catagories': [str(self.cat1.id), str(self.cat2.id)]} form = BlogForm(data) self.assertTrue(form.is_valid())