Пример #1
0
    def test_creating_some_hobbies_for_a_signup(self):
        # start by creating a new Poll object
        signup = SignUp()
        signup.email="*****@*****.**"
        signup.full_name = "Amerigo"
        signup.save()

        # now create a Choice object
        hobby = Hobby()

        # link it with our Poll
        hobby.signup = signup

        # give it some text
        hobby.hobby = "Reading"

        # save it
        hobby.save()

        # try retrieving it from the database, using the signup object's reverse
        # lookup
        signup_hobbies = signup.hobby_set.all()
        self.assertEquals(signup_hobbies.count(), 1)

        # finally, check its attributes have been saved
        hobby_from_db = signup_hobbies[0]
        self.assertEquals(hobby_from_db, hobby)
        self.assertEquals(hobby_from_db.hobby, "Reading")
Пример #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()
Пример #3
0
    def test_creating_some_hobbies_for_a_signup(self):
        # start by creating a new Poll object
        signup = SignUp()
        signup.email = "*****@*****.**"
        signup.full_name = "Amerigo"
        signup.save()

        # now create a Choice object
        hobby = Hobby()

        # link it with our Poll
        hobby.signup = signup

        # give it some text
        hobby.hobby = "Reading"

        # save it
        hobby.save()

        # try retrieving it from the database, using the signup object's reverse
        # lookup
        signup_hobbies = signup.hobby_set.all()
        self.assertEquals(signup_hobbies.count(), 1)

        # finally, check its attributes have been saved
        hobby_from_db = signup_hobbies[0]
        self.assertEquals(hobby_from_db, hobby)
        self.assertEquals(hobby_from_db.hobby, "Reading")
Пример #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)
Пример #5
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)
Пример #6
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()