| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # Copyright (c) 2020 Cinc |
|---|
| 3 | # All rights reserved. |
|---|
| 4 | # |
|---|
| 5 | # Redistribution and use in source and binary forms, with or without |
|---|
| 6 | # modification, are permitted provided that the following conditions |
|---|
| 7 | # are met: |
|---|
| 8 | # 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | # notice, this list of conditions and the following disclaimer. |
|---|
| 10 | # 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | # documentation and/or other materials provided with the distribution. |
|---|
| 13 | # 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | # derived from this software without specific prior written permission. |
|---|
| 15 | # |
|---|
| 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | |
|---|
| 27 | import unittest |
|---|
| 28 | from milestonetemplate.web_ui import MilestoneTemplatePlugin |
|---|
| 29 | from trac.test import EnvironmentStub |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | class TestHtmlFragment(unittest.TestCase): |
|---|
| 33 | |
|---|
| 34 | def setUp(self): |
|---|
| 35 | self.env = EnvironmentStub(default_data=True, enable=['trac.*', |
|---|
| 36 | 'milestonrtemplate.*', |
|---|
| 37 | ]) |
|---|
| 38 | self.plugin = MilestoneTemplatePlugin(self.env) |
|---|
| 39 | |
|---|
| 40 | def tearDown(self): |
|---|
| 41 | self.env.shutdown() |
|---|
| 42 | |
|---|
| 43 | def test_create_admin_fragment(self): |
|---|
| 44 | expected = u"""<div class="field"> |
|---|
| 45 | <label>Template: |
|---|
| 46 | <select id="ms-templates" name="template"> |
|---|
| 47 | <option value="">(blank)</option> |
|---|
| 48 | <option value="Foo"> |
|---|
| 49 | Foo |
|---|
| 50 | </option><option value="Bar"> |
|---|
| 51 | Bar |
|---|
| 52 | </option> |
|---|
| 53 | </select> |
|---|
| 54 | <span class="hint">For Milestone description</span> |
|---|
| 55 | </label> |
|---|
| 56 | </div>""" |
|---|
| 57 | # Produces a Genshi stream |
|---|
| 58 | templates = ['Foo', 'Bar'] |
|---|
| 59 | res = self.plugin.create_admin_page_select_ctrl(templates) |
|---|
| 60 | self.assertEqual(expected, res) |
|---|
| 61 | |
|---|
| 62 | def test_create_milestone_page_fragment(self): |
|---|
| 63 | expected = u"""<div class="field"> |
|---|
| 64 | <p>Or use a template for the description:</p> |
|---|
| 65 | <label>Template: |
|---|
| 66 | <select id="ms-templates" name="template"> |
|---|
| 67 | <option value="" selected="selected">(Use given Description)</option> |
|---|
| 68 | <option value="Foo"> |
|---|
| 69 | Foo |
|---|
| 70 | </option><option value="Bar"> |
|---|
| 71 | Bar |
|---|
| 72 | </option> |
|---|
| 73 | </select> |
|---|
| 74 | <span class="hint">The description will be replaced with the template contents on submit.</span> |
|---|
| 75 | </label> |
|---|
| 76 | </div>""" |
|---|
| 77 | # Produces a Genshi stream |
|---|
| 78 | templates = ['Foo', 'Bar'] |
|---|
| 79 | res = self.plugin.create_milestone_page_select_ctrl(templates) |
|---|
| 80 | self.assertEqual(expected, res) |
|---|
| 81 | |
|---|
| 82 | def test_create_milestone_page_fragment_select(self): |
|---|
| 83 | expected = u"""<div class="field"> |
|---|
| 84 | <p>Or use a template for the description:</p> |
|---|
| 85 | <label>Template: |
|---|
| 86 | <select id="ms-templates" name="template"> |
|---|
| 87 | <option value="">(Use given Description)</option> |
|---|
| 88 | <option value="Foo"> |
|---|
| 89 | Foo |
|---|
| 90 | </option><option value="Bar" selected="selected"> |
|---|
| 91 | Bar |
|---|
| 92 | </option> |
|---|
| 93 | </select> |
|---|
| 94 | <span class="hint">The description will be replaced with the template contents on submit.</span> |
|---|
| 95 | </label> |
|---|
| 96 | </div>""" |
|---|
| 97 | # Produces a Genshi stream |
|---|
| 98 | templates = ['Foo', 'Bar'] |
|---|
| 99 | res = self.plugin.create_milestone_page_select_ctrl(templates, 'Bar') |
|---|
| 100 | self.assertEqual(expected, res) |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | def fragment_suite(): |
|---|
| 104 | suite = unittest.TestSuite() |
|---|
| 105 | |
|---|
| 106 | suite.addTest(unittest.makeSuite(TestHtmlFragment)) |
|---|
| 107 | |
|---|
| 108 | return suite |
|---|