示例#1
0
    def test_update_properties_dont_add_bad_attribute_propertyx(self):
        "Check that we don't allow unknown attribute properties"
        devname = "sys/tg_test/2"
        label = "This is a test"
        dev = find_device(self.data, devname)[0]
        dev["attribute_properties"]["ampliz"].update({"fish": [label]})

        orig_dev = find_device(self.dbdict, devname)[0]
        with self.assertRaises(KeyError):
            update_properties(self.db, devname,
                              orig_dev["attribute_properties"],
                              dev["attribute_properties"],
                              attribute=True)
示例#2
0
 def test_update_properties_remove_property_leaves_protected(self):
     devname = "sys/tg_test/2"
     dev = find_device(self.dbdict, devname)[0]
     dev["properties"]["polled_attr"] = ["a", "b"]
     orig_dev = find_device(self.dbdict, devname)[0]
     added, removed = update_properties(self.db, devname,
                                        orig_dev["properties"],
                                        dev["properties"])
     self.assertDictEqual(added, {})
     self.assertDictEqual(removed, {})
示例#3
0
 def test_update_properties_replace_property(self):
     devname = "sys/tg_test/2"
     dev = find_device(self.data, devname)[0]
     dev["properties"]["bepa"] = ["573"]
     orig_dev = find_device(self.dbdict, devname)[0]
     added, removed = update_properties(self.db, devname,
                                        orig_dev["properties"],
                                        dev["properties"])
     self.assertIn("bepa", added)
     self.assertListEqual(
         self.db.calls,
         [('put_device_property', ('sys/tg_test/2', {'bepa': ['573']}), {})])
示例#4
0
 def test_update_properties_add_property(self):
     devname = "sys/tg_test/2"
     dev = find_device(self.data, devname)[0]
     dev["properties"]["flepp"] = ["56"]
     orig_dev = find_device(self.dbdict, devname)[0]
     added, removed = update_properties(self.db, devname,
                                        orig_dev["properties"],
                                        dev["properties"])
     self.assertDictEqual(added, {"flepp": ["56"]})
     self.assertDictEqual(removed, {})
     self.assertListEqual(
         self.db.calls,
         [('put_device_property', ('sys/tg_test/2', {'flepp': ['56']}), {})])
示例#5
0
 def test_update_properties_add_attribute_property(self):
     devname = "sys/tg_test/2"
     label = "This is a test"
     dev = find_device(self.data, devname)[0]
     dev["attribute_properties"]["someAttr"] = {"label": [label]}
     orig_dev = find_device(self.dbdict, devname)[0]
     added, removed = update_properties(self.db, devname,
                                        orig_dev["attribute_properties"],
                                        dev["attribute_properties"],
                                        attribute=True)
     self.assertDictEqual(added, {"someAttr": {"label": [label]}})
     self.assertDictEqual(removed, {})
     self.assertEqual(len(self.db.calls), 1)
     self.assertListEqual(
         self.db.calls,
         [('put_device_attribute_property',
           ('sys/tg_test/2', {'someAttr': {'label': [label]}}), {})])
示例#6
0
 def test_update_properties_add_more_attribute_properties(self):
     """Test adding more attribute properties to an attribute that
     has some already"""
     devname = "sys/tg_test/2"
     label = "This is a test"
     dev = find_device(self.data, devname)[0]
     dev["attribute_properties"]["ampliz"].update({"label": [label],
                                                   "unit": ["hejsan"]})
     orig_dev = find_device(self.dbdict, devname)[0]
     added, removed = update_properties(self.db, devname,
                                        orig_dev["attribute_properties"],
                                        dev["attribute_properties"],
                                        attribute=True)
     self.assertDictEqual(added, {"ampliz": {"label": [label]}})
     self.assertDictEqual(removed, {})
     self.assertEqual(len(self.db.calls), 1)
     self.assertListEqual(
         self.db.calls,
         [('put_device_attribute_property',
           ('sys/tg_test/2', {'ampliz': {'label': [label]}}), {})])