1 # Copyright © 2019 Intel Corporation
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 from unittest
import mock
27 from . import post_version
30 # Mock out subprocess.run to avoid having git commits
31 @mock.patch('bin.post_version.subprocess.run', mock
.Mock())
32 class TestUpdateCalendar
:
34 HEAD
= textwrap
.dedent("""\
35 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
38 <meta http-equiv="content-type" content="text/html; charset=utf-8">
39 <title>Release Calendar</title>
40 <link rel="stylesheet" type="text/css" href="mesa.css">
45 TABLE
= textwrap
.dedent("""\
49 <th>Expected date</th>
51 <th>Release manager</th>
56 FOOT
= "</body></html>"
58 TABLE_FOOT
= "</table>"
60 def wrap_table(self
, table
: str) -> str:
61 return self
.HEAD
+ self
.TABLE
+ table
+ self
.TABLE_FOOT
+ self
.FOOT
64 data
= self
.wrap_table(textwrap
.dedent("""\
66 <td rowspan="3">19.2</td>
80 <td>Last planned 19.2.x release</td>
84 parsed
= html
.fromstring(data
)
85 parsed
.write
= mock
.Mock()
87 with mock
.patch('bin.post_version.html.parse',
88 mock
.Mock(return_value
=parsed
)):
89 post_version
.update_calendar('19.2.3')
91 assert len(parsed
.findall('.//tr')) == 3
92 # we need the second element becouse the first is the header
94 tr
= parsed
.findall('.//tr')[1]
95 tds
= tr
.findall('.//td')
96 assert tds
[0].get("rowspan") == "2"
97 assert tds
[0].text
== "19.2"
98 assert tds
[1].text
== "2019-11-20"
101 def two_releases(self
) -> html
.etree
.ElementTree
:
102 data
= self
.wrap_table(textwrap
.dedent("""\
104 <td rowspan="1">19.1</td>
107 <td>Not Dylan Baker</td>
110 <td rowspan="3">19.2</td>
124 <td>Last planned 19.2.x release</td>
128 p
= html
.fromstring(data
)
129 p
.write
= mock
.Mock()
132 def test_two_releases(self
, two_releases
: html
.etree
.ElementTree
):
133 with mock
.patch('bin.post_version.html.parse',
134 mock
.Mock(return_value
=two_releases
)):
135 post_version
.update_calendar('19.2.3')
137 assert len(two_releases
.findall('.//tr')) == 4
138 # we need the second element becouse the first is the header
140 tr
= two_releases
.findall('.//tr')[2]
141 tds
= tr
.findall('.//td')
142 assert tds
[0].get("rowspan") == "2"
143 assert tds
[0].text
== "19.2"
144 assert tds
[1].text
== "2019-11-20"
146 def test_last_Release(self
, two_releases
: html
.etree
.ElementTree
):
147 with mock
.patch('bin.post_version.html.parse',
148 mock
.Mock(return_value
=two_releases
)):
149 post_version
.update_calendar('19.1.8')
151 assert len(two_releases
.findall('.//tr')) == 4
152 # we need the second element becouse the first is the header
154 tr
= two_releases
.findall('.//tr')[1]
155 tds
= tr
.findall('.//td')
156 assert tds
[0].get("rowspan") == "3"
157 assert tds
[0].text
== "19.2"
158 assert tds
[1].text
== "2019-11-06"