def save(request): if request.method == 'POST': post = request.POST title = post['title'] code = Code(title=post['title'], language=post['language'], code=post['code']) code.save() return HttpResponseRedirect(reverse('show', args=(code.slug,)))
def test_slugfy(self): code = Code(title='title test',language='language',code='code') code.save() self.assertTrue(code.slug == 'title-test')
def test_should_have_a_slug(self): code = Code(title='test slug', language='python', code='code') code.save() self.assertTrue(code.slug == 'test-slug')
def test_show_code(self): code = Code(title='show test', language='python', code='code show test') code.save() response = self.client.get(reverse('show', args=(code.slug,))) self.assertTrue(response.status_code == 200) self.assertContains(response, code.title)