def test_full_valid_submission(self): test_data = { 'title': 'submission_title', 'url': 'http://example.com', 'text': 'submission text' } form = SubmissionForm(data=test_data) self.assertTrue(form.is_valid())
def test_invalid_data(self): test_data = {'title': '.' * 300, 'url': 'notaurl', 'text': '.' * 5001} form = SubmissionForm(data=test_data) self.assertEqual( form.errors['title'], ["Ensure this value has at most 250 characters (it has 300)."]) self.assertEqual(form.errors['url'], ["Enter a valid URL."]) self.assertEqual( form.errors['text'], ["Ensure this value has at most 5000 characters (it has 5001)."]) self.assertFalse(form.is_valid())
def test_invalid_data(self): test_data = { 'title': '.' * 300, 'url': 'notaurl', 'text': '.' * 5001 } form = SubmissionForm(data=test_data) self.assertEqual(form.errors['title'], [u"Ensure this value has at most 250 characters (it has 300)."]) self.assertEqual(form.errors['url'], [u"Enter a valid URL."]) self.assertEqual(form.errors['text'], [u"Ensure this value has at most 5000 characters (it has 5001)."]) self.assertFalse(form.is_valid())
def submit(request): """ Handles new submission.. submission. """ submission_form = SubmissionForm() if request.method == 'POST': submission_form = SubmissionForm(request.POST) if submission_form.is_valid(): submission = submission_form.save(commit=False) submission.generate_html() user = User.objects.get(username=request.user) redditUser = RedditUser.objects.get(user=user) submission.author = redditUser submission.author_name = user.username submission.save() messages.success(request, 'Submission created') return redirect('/comments/{}'.format(submission.id)) return render(request, 'public/submit.html', {'form': submission_form})
def submit(request): """ Handles new submission.. submission. """ submission_form = SubmissionForm() if request.method == 'POST': submission_form = SubmissionForm(request.POST, request.FILES) if submission_form.is_valid(): submission = submission_form.save(commit=False) submission.generate_html() reddit_user = KagisoUser.objects.get(id=request.user.id) submission.author = reddit_user submission.author_name = '{} {}'.format(reddit_user.first_name, reddit_user.last_name) submission.save() messages.success(request, 'Submission created') return redirect('/') return render(request, 'public/submit.html', {'form': submission_form})
def test_minimum_data_required(self): test_data = {'title': 'submission title'} form = SubmissionForm(data=test_data) self.assertTrue(form.is_valid())
def test_minimum_data_required(self): test_data = { 'title': 'submission title' } form = SubmissionForm(data=test_data) self.assertTrue(form.is_valid())