~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/widgets/tests/test_launchpadtarget.py

Added tests for setUpOptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
        # hasInput is true is the widget's name in the form data.
82
82
        form = {
83
83
            'field.target': 'package',
84
 
            'field.target.distribution': 'ubuntu',
85
 
            'field.target.package': 'evolution'}
 
84
            'field.target.distribution': 'fnord',
 
85
            'field.target.package': 'snarf',
 
86
            }
86
87
        self.widget.request = LaunchpadTestRequest(form=form)
87
88
        self.assertEqual('field.target', self.widget.name)
88
89
        self.assertTrue(self.widget.hasInput())
95
96
            self.widget.distribution_widget.context.vocabulary,
96
97
            DistributionVocabulary)
97
98
        self.assertIsInstance(
 
99
            self.widget.package_widget.context.vocabulary,
 
100
            BinaryAndSourcePackageNameVocabulary)
 
101
        self.assertIsInstance(
98
102
            self.widget.product_widget.context.vocabulary,
99
103
            ProductVocabulary)
100
 
        self.assertIsInstance(
101
 
            self.widget.package_widget.context.vocabulary,
102
 
            BinaryAndSourcePackageNameVocabulary)
103
104
 
104
105
    def test_setUpSubWidgets_second_call(self):
105
106
        # The setUpSubWidgets method exits early if a flag is set to
118
119
        self.assertIsInstance(
119
120
            self.widget.package_widget.context.vocabulary,
120
121
            DistributionSourcePackageVocabulary)
 
122
 
 
123
    def test_setUpOptions_default_package_checked(self):
 
124
        # The radio button options are composed of the setup widgets with
 
125
        # the package widget set as the default.
 
126
        self.widget.setUpSubWidgets()
 
127
        self.widget.setUpOptions()
 
128
        self.assertEqual(
 
129
            "selectWidget('field.target.option.package', event)",
 
130
            self.widget.package_widget.onKeyPress)
 
131
        self.assertEqual(
 
132
            "selectWidget('field.target.option.product', event)",
 
133
            self.widget.product_widget.onKeyPress)
 
134
        self.assertEqual(
 
135
            '<input class="radioType" checked="checked" '
 
136
            'id="field.target.option.package" name="field.target" '
 
137
            'type="radio" value="package" />',
 
138
            self.widget.options['package'])
 
139
        self.assertEqual(
 
140
            '<input class="radioType" '
 
141
            'id="field.target.option.product" name="field.target" '
 
142
            'type="radio" value="product" />',
 
143
            self.widget.options['product'])
 
144
 
 
145
    def test_setUpOptions_product_checked(self):
 
146
        # The product radio button is selected when the form is submitted
 
147
        # with product as the target.
 
148
        form = {
 
149
            'field.target': 'product',
 
150
            }
 
151
        self.widget.request = LaunchpadTestRequest(form=form)
 
152
        self.widget.setUpSubWidgets()
 
153
        self.widget.setUpOptions()
 
154
        self.assertEqual(
 
155
            '<input class="radioType" '
 
156
            'id="field.target.option.package" name="field.target" '
 
157
            'type="radio" value="package" />',
 
158
            self.widget.options['package'])
 
159
        self.assertEqual(
 
160
            '<input class="radioType" checked="checked" '
 
161
            'id="field.target.option.product" name="field.target" '
 
162
            'type="radio" value="product" />',
 
163
            self.widget.options['product'])