Skip to content

Commit 2ce2ddc

Browse files
authored
Merge pull request #163 from peternewman/plugfest
Fix a longstanding bug in returning the latest software version
2 parents 0f779a2 + 34d9646 commit 2ce2ddc

File tree

8 files changed

+274
-5
lines changed

8 files changed

+274
-5
lines changed

common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def GetLatestSoftware(responder):
7474
A SoftwareVersion object or None.
7575
"""
7676
max_version = None
77-
version = None
77+
max_version_info = None
7878
for version in responder.software_version_set:
7979
if max_version is None or version.version_id > max_version:
8080
max_version = version.version_id
81-
version = version
82-
return version
81+
max_version_info = version
82+
return max_version_info
8383

8484

8585
def LookupProductCategory(category_id):

data/controller_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# controller_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestControllerData(unittest.TestCase):
22+
""" Test the controller data files are valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/controller_data.py", globals, locals)
27+
self.data = locals['CONTROLLER_DATA']
28+
29+
def test_ControllerData(self):
30+
# Check the type
31+
self.assertEqual(type(self.data), dict)
32+
33+
for esta_id in self.data:
34+
self.assertEqual(int, type(esta_id))
35+
self.assertEqual(list, type(self.data[esta_id]))
36+
37+
seen_names = set()
38+
39+
for controller in self.data[esta_id]:
40+
name = controller['name']
41+
self.assertNotIn(name, seen_names,
42+
"Name %s for ESTA ID 0x%04x is present twice" % (name, esta_id))
43+
seen_names.add(name)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

data/model_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# model_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestDeviceModelData(unittest.TestCase):
22+
""" Test the device model data files are valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/model_data.py", globals, locals)
27+
self.data = locals['DEVICE_MODEL_DATA']
28+
29+
def test_DeviceModelData(self):
30+
# Because there may not be model data present, we just check the type
31+
self.assertEqual(type(self.data), dict)
32+
33+
34+
if __name__ == '__main__':
35+
unittest.main()

data/node_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# along with this program; if not, write to the Free Software
1414
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1515
#
16-
# splitter_data.py
16+
# node_data.py
1717
# Copyright (C) 2012 Simon Newton
18-
# Data for the splitters & distribution units.
18+
# Data for the nodes.
1919

2020
NODE_DATA = {
2121
0x414c: [

data/node_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# node_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestNodeData(unittest.TestCase):
22+
""" Test the node data files are valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/node_data.py", globals, locals)
27+
self.data = locals['NODE_DATA']
28+
29+
def test_NodeData(self):
30+
# Check the type
31+
self.assertEqual(type(self.data), dict)
32+
33+
for esta_id in self.data:
34+
self.assertEqual(int, type(esta_id))
35+
self.assertEqual(list, type(self.data[esta_id]))
36+
37+
seen_names = set()
38+
39+
for node in self.data[esta_id]:
40+
name = node['name']
41+
self.assertNotIn(name, seen_names,
42+
"Name %s for ESTA ID 0x%04x is present twice" % (name, esta_id))
43+
seen_names.add(name)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

data/sensor_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# sensor_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestSensorTypes(unittest.TestCase):
22+
""" Test the sensor types data file is valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/sensor_types.py", globals, locals)
27+
self.data = locals['SENSOR_TYPES']
28+
29+
def test_SensorTypeData(self):
30+
seen_names = set()
31+
32+
for sensor_type_id in self.data:
33+
name = self.data[sensor_type_id]
34+
self.assertEqual(int, type(sensor_type_id))
35+
self.assertEqual(str, type(name))
36+
37+
self.assertNotIn(name, seen_names,
38+
"Sensor Name %s is present twice" % name)
39+
seen_names.add(name)
40+
41+
# check that some sensors exist
42+
self.assertGreater(len(seen_names), 30)
43+
44+
45+
if __name__ == '__main__':
46+
unittest.main()

data/software_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# software_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestSoftwareData(unittest.TestCase):
22+
""" Test the software data files are valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/software_data.py", globals, locals)
27+
self.data = locals['SOFTWARE_DATA']
28+
29+
def test_SoftwareData(self):
30+
# Check the type
31+
self.assertEqual(type(self.data), dict)
32+
33+
for esta_id in self.data:
34+
self.assertEqual(int, type(esta_id))
35+
self.assertEqual(list, type(self.data[esta_id]))
36+
37+
seen_names = set()
38+
39+
for software in self.data[esta_id]:
40+
name = software['name']
41+
self.assertNotIn(name, seen_names,
42+
"Name %s for ESTA ID 0x%04x is present twice" % (name, esta_id))
43+
seen_names.add(name)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

data/splitter_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python
2+
# This program is free software; you can redistribute it and/or modify
3+
# it under the terms of the GNU General Public License as published by
4+
# the Free Software Foundation; either version 2 of the License, or
5+
# (at your option) any later version.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU Library General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
#
16+
# splitter_test.py
17+
# Copyright (C) 2017 Peter Newman
18+
19+
import unittest
20+
21+
class TestSplitterData(unittest.TestCase):
22+
""" Test the splitter data files are valid."""
23+
def setUp(self):
24+
globals = {}
25+
locals = {}
26+
execfile("data/splitter_data.py", globals, locals)
27+
self.data = locals['SPLITTER_DATA']
28+
29+
def test_SplitterData(self):
30+
# Check the type
31+
self.assertEqual(type(self.data), dict)
32+
33+
for esta_id in self.data:
34+
self.assertEqual(int, type(esta_id))
35+
self.assertEqual(list, type(self.data[esta_id]))
36+
37+
seen_names = set()
38+
39+
for splitter in self.data[esta_id]:
40+
name = splitter['name']
41+
self.assertNotIn(name, seen_names,
42+
"Name %s for ESTA ID 0x%04x is present twice" % (name, esta_id))
43+
seen_names.add(name)
44+
45+
46+
if __name__ == '__main__':
47+
unittest.main()

0 commit comments

Comments
 (0)