def setUp(self): self.formfield = RegexpExtractField( r'.+slideshare.net/slideshow/embed_code/(?P<id>\d+).+title="(?P<title>[^"]+)"', ['id', 'title'], 'there is something wrong with the SlideShares Embed code you pasted, please try again', help_text="Paste the embed code from slideshare.net", label="Html code", widget=forms.Textarea(attrs={'style': "width: 800px; height: 125px;"}) ) self.correct_input = '"http://www.slideshare.net/slideshow/embed_code/15936422" (.....) title="How to create great slides for presentations"'
class RegexpExtractFieldTestCase(unittest.TestCase, FormFieldTestCase): def setUp(self): self.formfield = RegexpExtractField( r'.+slideshare.net/slideshow/embed_code/(?P<id>\d+).+title="(?P<title>[^"]+)"', ['id', 'title'], 'there is something wrong with the SlideShares Embed code you pasted, please try again', help_text="Paste the embed code from slideshare.net", label="Html code", widget=forms.Textarea(attrs={'style': "width: 800px; height: 125px;"}) ) self.correct_input = '"http://www.slideshare.net/slideshow/embed_code/15936422" (.....) title="How to create great slides for presentations"' def test_clean_fails(self): self.assertRaises(ValidationError, self.formfield.clean, 'www.slideshare.net/thereisnothinghere') def test_clean_passes(self): #if value validates, clean must return the value self.assertEqual(self.formfield.clean(self.correct_input), ['15936422', 'How to create great slides for presentations'])