Example #1
0
    def test_create_snippet(self):
        """
        We can create a Snippet.
        """
        form = SnippetForm(
          {'name': u'My Snippet',
           'language': 'python',
           'plain_code': u'from django.test import TestCase'})

        self.assertTrue(form.is_valid(), "Form is not valid")
        snippet = form.save()

        self.assertEqual(u'My Snippet', snippet.name)
        self.assertEqual(u'python', snippet.language)
        self.assertEqual(u'from django.test import TestCase',
                         snippet.plain_code)
Example #2
0
def new(request):
    """
    Create a new Snippet.
    """
    if request.method == 'POST':
        form = SnippetForm(request.POST)
        if form.is_valid():
            snippet = form.save()
            highlight_snippet_task.delay(snippet.id)
            return HttpResponseRedirect(
                reverse('snippet_show', kwargs={'snippet_id': snippet.id}))
    else:
        form = SnippetForm() # An unbound form

    return render(request, 'create.html', {
        'form': form,
    })