Example #1
0
    def test_form_renders_poll_choices_as_radio_inputs(self):
        # set up a signup with a couple of hobbies
        signup1 = SignUp(email='*****@*****.**', full_name='Filippo Insaghi')
        signup1.save()
        hobby1 = Hobby(signup=signup1, hobby='Fishing')
        hobby1.save()
        hobby2 = Hobby(signup=signup1, hobby='Swimming')
        hobby2.save()

        # set up another poll to make sure we only see the right choices
        signup2 = SignUp(email='*****@*****.**', full_name="Cezaro Prandelli")
        signup2.save()
        hobby = Hobby(signup=signup2, hobby='Movies')
        hobby.save()

        # build a voting form for signup1
        form = SignUpVoteForm(signup=signup1)

        # check it has a single field called 'vote', which has right choices:
        self.assertEquals(form.fields.keys(), ['vote'])

        # choices are tuples in the format (choice_number, choice_text):
        self.assertEquals(form.fields['vote'].hobbies, [
            (hobby1.id, hobby1.hobby),
            (hobby2.id, hobby2.hobby),
        ])

        # check it uses radio inputs to render
        print form.as_p()
Example #2
0
    def test_form_renders_poll_choices_as_radio_inputs(self):
        # set up a signup with a couple of hobbies
        signup1 = SignUp(email='*****@*****.**', full_name='Filippo Insaghi')
        signup1.save()
        hobby1 = Hobby(signup=signup1, hobby='Fishing')
        hobby1.save()
        hobby2 = Hobby(signup=signup1, hobby='Swimming')
        hobby2.save()

        # set up another poll to make sure we only see the right choices
        signup2 = SignUp(email='*****@*****.**', full_name="Cezaro Prandelli")
        signup2.save()
        hobby = Hobby(signup=signup2, hobby='Movies')
        hobby.save()

        # build a voting form for signup1
        form = SignUpVoteForm(signup=signup1)

        # check it has a single field called 'vote', which has right choices:
        self.assertEquals(form.fields.keys(), ['vote'])

        # choices are tuples in the format (choice_number, choice_text):
        self.assertEquals(form.fields['vote'].hobbies, [
            (hobby1.id, hobby1.hobby),
            (hobby2.id, hobby2.hobby),
        ])

        # check it uses radio inputs to render
        print form.as_p()
Example #3
0
    def test_page_shows_hobbies_using_form(self):
        # set up a signup with hobbies
        signup1 = SignUp(email='*****@*****.**', full_name='Filippo Insaghi')
        signup1.save()
        hobby1 = Hobby(signup=signup1, hobby='Fishing')
        hobby1.save()
        hobby2 = Hobby(signup=signup1, hobby='Swimming')
        hobby2.save()

        response = self.client.get('/signup/%d/' % (signup1.id, ))

        # check we've passed in a form of the right type
        self.assertTrue(isinstance(response.context['form'], SignUpVoteForm))

        # and check the form is being used in the template,
        # by checking for the hobby text
        form = SignUpVoteForm(signup=signup1)
        print form.as_p()
        self.assertIn(hobby1.hobby, response.content)
        self.assertIn(hobby2.hobby, response.content)
Example #4
0
    def test_page_shows_hobbies_using_form(self):
        # set up a signup with hobbies
        signup1 = SignUp(email='*****@*****.**', full_name='Filippo Insaghi')
        signup1.save()
        hobby1 = Hobby(signup=signup1, hobby='Fishing')
        hobby1.save()
        hobby2 = Hobby(signup=signup1, hobby='Swimming')
        hobby2.save()

        response = self.client.get('/signup/%d/' % (signup1.id, ))

        # check we've passed in a form of the right type
        self.assertTrue(isinstance(response.context['form'], SignUpVoteForm))

        # and check the form is being used in the template,
        # by checking for the hobby text
        form = SignUpVoteForm(signup=signup1)
        print form.as_p()
        self.assertIn(hobby1.hobby, response.content)
        self.assertIn(hobby2.hobby, response.content)
Example #5
0
def signup(request, signup_id):
	signup = SignUp.objects.get(pk=signup_id)
	form = SignUpVoteForm(signup=signup)
	return render(request,'signup.html', {'signup': signup, "form": form})