Ejemplo n.º 1
0
 def test_custom_template_terms2(self):
     """A call to update doesn't change the terms"""
     oc = OptChoiceWidget(self.request)
     oc.name = 'opt-widget'
     oc.terms = sample_terms
     oc.update()
     self.assertListEqual([x.value for x in oc.terms], comparison_terms )
Ejemplo n.º 2
0
 def test_select_input_extract(self):
     """Base case for extract method -- select one of the values"""
     oc = OptChoiceWidget(self.request)
     oc.name = oc.id = 'oc'
     oc.terms = sample_terms
     oc.request = TestRequest(form={'oc':['first']})
     values = oc.extract()
     self.assertListEqual(values, ['first'])
Ejemplo n.º 3
0
 def test_select_input_extract(self):
     """Base case for extract method -- select one of the values"""
     oc = OptChoiceWidget(self.request)
     oc.name = oc.id = 'oc'
     oc.terms = sample_terms
     oc.request = TestRequest(form={'oc': ['first']})
     values = oc.extract()
     self.assertListEqual(values, ['first'])
Ejemplo n.º 4
0
 def test_select_in_wrapper(self):
     """
     Test when SimpleVocabulary is wrapped with
     z3c.form.term.ChoiceTermsVocabulary
     """
     ct = ChoiceTermsVocabulary(*[None]*6)
     ct.terms = sample_terms
     oc = OptChoiceWidget(self.request, other_token=ot)
     oc.name = oc.id = 'optional_widget'
     oc.terms = ct
     oc.update()
     self.assertEquals(len(oc.terms.terms), len(sample_terms)+1)
Ejemplo n.º 5
0
 def test_select_in_wrapper(self):
     """
     Test when SimpleVocabulary is wrapped with
     z3c.form.term.ChoiceTermsVocabulary
     """
     ct = ChoiceTermsVocabulary(*[None] * 6)
     ct.terms = sample_terms
     oc = OptChoiceWidget(self.request, other_token=ot)
     oc.name = oc.id = 'optional_widget'
     oc.terms = ct
     oc.update()
     self.assertEquals(len(oc.terms.terms), len(sample_terms) + 1)
Ejemplo n.º 6
0
 def test_custom_template_terms(self):
     oc = OptChoiceWidget(self.request)
     oc.terms = sample_terms
     oc.name = 'opt-widget'
     oc.ignoreContext = True
     oc.update()
     data = oc.render()
     self.assertGreaterEqual(len(data), 28)
Ejemplo n.º 7
0
 def test_render_sequence(self):
     opt_widget = OptChoiceWidget(self.request)
     opt_widget.name = 'opt-choice'
     opt_widget.id = 'oc1'
     opt_widget.terms = longer_sample_terms
     opt_widget.update()
     rendered_data = opt_widget.render()
     self.assertIn('id="oc1"', rendered_data)
     self.assertIn('id="oc1-0"', rendered_data)
     self.assertIn('id="oc1-7"', rendered_data)
     self.assertEqual(8, rendered_data.count('value="f'))
Ejemplo n.º 8
0
 def test_custom_template_terms(self):
     oc = OptChoiceWidget(self.request)
     oc.terms = sample_terms
     oc.name = 'opt-widget'
     oc.ignoreContext = True
     oc.update()
     data = oc.render()
     self.assertGreaterEqual(len(data), 28)
Ejemplo n.º 9
0
 def test_optional_input_token_present(self):
     """Make sure that the optional input token is appended to the list"""
     token_widget = OptChoiceWidget(self.request, other_token=ot)
     token_widget.name = 'opt-choice-in'
     token_widget.id = 'tw'
     token_widget.terms = longer_sample_terms
     token_widget.update()
     items = token_widget.items
     self.assertEqual(len(items), len(longer_sample_terms) + 1)
     self.assertEqual(items[-1]['content'], 'Other')
Ejemplo n.º 10
0
 def test_custom_template_terms2(self):
     """A call to update doesn't change the terms"""
     oc = OptChoiceWidget(self.request)
     oc.name = 'opt-widget'
     oc.terms = sample_terms
     oc.update()
     self.assertListEqual([x.value for x in oc.terms], comparison_terms)
Ejemplo n.º 11
0
 def test_render_sequence(self):
     opt_widget = OptChoiceWidget(self.request)
     opt_widget.name = 'opt-choice'
     opt_widget.id = 'oc1'
     opt_widget.terms = longer_sample_terms
     opt_widget.update()
     rendered_data = opt_widget.render()
     self.assertIn('id="oc1"', rendered_data)
     self.assertIn('id="oc1-0"', rendered_data)
     self.assertIn('id="oc1-7"', rendered_data)
     self.assertEqual(8, rendered_data.count('value="f'))
Ejemplo n.º 12
0
 def test_select_custom_input(self):
     """Extract data from input field"""
     """Base case for extract method -- select one of the values"""
     oc = OptChoiceWidget(self.request, other_token=ot)
     oc.name = oc.id = 'oc'
     oc.terms = sample_terms
     oc.update()
     oc.request = TestRequest(form={
         'oc': ['other'],
         'oc-input': 'testval1'
     })
     values = oc.extract()
     self.assertListEqual(['testval1'], values)
Ejemplo n.º 13
0
 def test_optional_input_token_present(self):
     """Make sure that the optional input token is appended to the list"""
     token_widget = OptChoiceWidget(self.request,other_token=ot)
     token_widget.name = 'opt-choice-in'
     token_widget.id = 'tw'
     token_widget.terms = longer_sample_terms
     token_widget.update()
     items = token_widget.items
     self.assertEqual(len(items), len(longer_sample_terms)+1)
     self.assertEqual(items[-1]['content'], 'Other')
Ejemplo n.º 14
0
 def test_select_custom_input(self):
     """Extract data from input field"""
     """Base case for extract method -- select one of the values"""
     oc = OptChoiceWidget(self.request, other_token=ot)
     oc.name = oc.id = 'oc'
     oc.terms = sample_terms
     oc.update()
     oc.request = TestRequest(form={'oc':['other'], 'oc-input':'testval1'})
     values = oc.extract()
     self.assertListEqual(['testval1'], values)
Ejemplo n.º 15
0
 def test_custom_template_noterms(self):
     """Sequence widget with no terms raises ComponentLookupError"""
     oc = OptChoiceWidget(self.request)
     with self.assertRaises(ComponentLookupError):
         oc.update()
         data = oc.render()
Ejemplo n.º 16
0
 def test_init_widget(self):
     opt_widget = OptChoiceWidget(self.request)
     opt_widget.name = 'opt-choice'
     self.assertIsNone(opt_widget.terms)
Ejemplo n.º 17
0
 def test_init_widget(self):
     opt_widget = OptChoiceWidget(self.request)
     opt_widget.name = 'opt-choice'
     self.assertIsNone(opt_widget.terms)
Ejemplo n.º 18
0
 def test_custom_template_noterms(self):
     """Sequence widget with no terms raises ComponentLookupError"""
     oc = OptChoiceWidget(self.request)
     with self.assertRaises(ComponentLookupError):
         oc.update()
         data = oc.render()