示例#1
0
    def test_uni_form_helper_form_attributes(self):
        

        template = get_template_from_string("""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        

        # First we build a standard form helper
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
    
        # now we render it
        c = Context({'form':TestForm(),'form_helper':form_helper})            
        html = template.render(c)        
        # Lets make sure everything loads right
        self.assertTrue("""<form""" in html)                
        self.assertTrue("""class="uniForm forms-that-rock" """ in html)
        self.assertTrue("""method="get" """ in html)
        self.assertTrue("""id="this-form-rocks">""" in html)        
        
        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        c = Context({'form':TestForm(),'form_helper':form_helper})            
        html = template.render(c)        
        self.assertFalse("""<form""" in html)        
        self.assertFalse("""id="this-form-rocks">""" in html)                
        self.assertFalse("""class="uniForm forms-that-rock" """ in html)
        self.assertFalse("""method="get" """ in html)
        self.assertFalse("""id="this-form-rocks">""" in html)
示例#2
0
    def test_uni_form_with_helper_attributes(self):
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
    
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        

        # now we render it
        c = Context({'form': TestForm(), 'form_helper': form_helper})            
        html = template.render(c)        
        
        # Lets make sure everything loads right
        self.assertTrue('<form' in html)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        
        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False 
        html = template.render(c)        
        self.assertFalse('<form' in html)        
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#3
0
    def test_uni_form_helper_form_attributes(self):

        template = get_template_from_string("""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)

        # First we build a standard form helper
        form_helper = FormHelper()
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'

        # now we render it
        c = Context({'form': TestForm(), 'form_helper': form_helper})
        html = template.render(c)
        # Lets make sure everything loads right
        self.assertTrue("""<form""" in html)
        self.assertTrue("""class="uniForm forms-that-rock" """ in html)
        self.assertTrue("""method="get" """ in html)
        self.assertTrue("""id="this-form-rocks">""" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        c = Context({'form': TestForm(), 'form_helper': form_helper})
        html = template.render(c)
        self.assertFalse("""<form""" in html)
        self.assertFalse("""id="this-form-rocks">""" in html)
        self.assertFalse("""class="uniForm forms-that-rock" """ in html)
        self.assertFalse("""method="get" """ in html)
        self.assertFalse("""id="this-form-rocks">""" in html)
示例#4
0
def lacking_form_tag(request):
    # Create the form
    if request.method == "POST":
        form = TestForm(request.POST)
    else:
        form = TestForm()

    # create a formHelper
    helper = FormHelper()

    # remove the form tag
    helper.form_tag = False

    # create the response dictionary
    response_dictionary = {'form':form, 'helper': helper, 'title':'Lacking Form Tag Test'}
    
    return render_to_response('test_app/generic_form_test.html', 
        response_dictionary, 
        context_instance=RequestContext(request))   
示例#5
0
文件: tests.py 项目: Bauke900/dnevnik
    def test_uni_form_with_helper_attributes_without_layout(self):
        form_helper = FormHelper()
        form_helper.form_id = "this-form-rocks"
        form_helper.form_class = "forms-that-rock"
        form_helper.form_method = "GET"
        form_helper.form_action = "simpleAction"
        form_helper.form_error_title = "ERRORS"

        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """
        )

        # now we render it, with errors
        form = TestForm({"password1": "wargame", "password2": "god"})
        form.is_valid()
        c = Context({"testForm": form, "form_helper": form_helper})
        html = template.render(c)

        # Lets make sure everything loads right
        self.assertTrue("<form" in html)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse("simpleAction") in html)

        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        html = template.render(c)
        self.assertFalse("<form" in html)
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#6
0
    def test_uni_form_with_helper_without_layout(self):
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
        form_helper.form_error_title = 'ERRORS'
    
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """)        

        # now we render it, with errors
        form = TestForm({'password1': 'wargame','password2': 'god'})
        form.is_valid()
        c = Context({'testForm': form, 'form_helper': form_helper})            
        html = template.render(c)
        
        # Lets make sure everything loads right
        self.assertTrue(html.count('<form'), 1)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        self.assertEqual(html.count('<fieldset'), 1)


        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False 
        html = template.render(c)        
        self.assertFalse('<form' in html)        
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#7
0
    def test_uni_form_with_helper_without_layout(self):
        form_helper = FormHelper()
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
        form_helper.form_error_title = 'ERRORS'

        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """)

        # now we render it, with errors
        form = TestForm({'password1': 'wargame', 'password2': 'god'})
        form.is_valid()
        c = Context({'testForm': form, 'form_helper': form_helper})
        html = template.render(c)

        # Lets make sure everything loads right
        self.assertTrue(html.count('<form'), 1)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        self.assertEqual(html.count('<fieldset'), 1)

        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        html = template.render(c)
        self.assertFalse('<form' in html)
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#8
0
def lacking_form_tag(request):
    # Create the form
    if request.method == "POST":
        form = TestForm(request.POST)
    else:
        form = TestForm()

    # create a formHelper
    helper = FormHelper()

    # remove the form tag
    helper.form_tag = False

    # create the response dictionary
    response_dictionary = {
        'form': form,
        'helper': helper,
        'title': 'Lacking Form Tag Test'
    }

    return render_to_response('test_app/generic_form_test.html',
                              response_dictionary,
                              context_instance=RequestContext(request))