Ejemplo n.º 1
0
 def test_getState_noItems(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     room.items = {}
     h.rooms = {1: room, 2: room}
     self.assertEqual(h.getState(), {'states': []})
Ejemplo n.º 2
0
 def test_getState_noItems(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     room.items = {}
     h.rooms = {1: room, 2 : room}
     self.assertEqual(h.getState(), {'states' : []})
Ejemplo n.º 3
0
 def test_deleteRoom(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     h.deleteRoom(1)
     self.assertRaises(KeyError, lambda: h.rooms[1])
Ejemplo n.º 4
0
 def test_executeMethod_itemDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     room.items = {}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.executeMethod, 1, 1, "getState")
Ejemplo n.º 5
0
 def test_addRoom(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     self.assertEqual(h.rooms[db.room.i].id, db.room.entries[db.room.i].id)
     self.assertEqual(h.rooms[db.room.i].name,
                      db.room.entries[db.room.i].name)
Ejemplo n.º 6
0
 def test_updateRoom(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     h.updateRoom(1, "new name")
     self.assertEqual(h.rooms[1].name, "new name")
Ejemplo n.º 7
0
 def test_executeMethod_itemDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     room.items = {}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.executeMethod, 1, 1, "getState")
Ejemplo n.º 8
0
 def test_deleteRoom(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     h.deleteRoom(1)
     self.assertRaises(KeyError, lambda: h.rooms[1])
Ejemplo n.º 9
0
 def test_updateRoom(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     h.updateRoom(1, "new name")
     self.assertEqual(h.rooms[1].name, "new name")
Ejemplo n.º 10
0
 def test_executeMethod_methodDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(AttributeError, h.executeMethod, 1, 1, "open")
Ejemplo n.º 11
0
 def test_getState(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room, 2 : room}
     self.assertEqual(h.getState(), {'states' : [{"id" : 1, "state" : 1}, {"id" : 1, "state" : 1} ]})
Ejemplo n.º 12
0
 def test_executeMethod_methodDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(AttributeError, h.executeMethod, 1, 1, "open")
Ejemplo n.º 13
0
 def test_executeMethod(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertEqual(h.executeMethod(1, 1, "getState"), 1)
Ejemplo n.º 14
0
 def test_executeMethod(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertEqual(h.executeMethod(1, 1, "getState"), 1)
Ejemplo n.º 15
0
 def test_getRoomByItemId(self):
     db = MockDatabase()
     h = House(db)
     roomId = h.addRoom("lounge")
     id = 0
     itemId = h.addItem(id, "sensor", "mock", "motionSensor", "0.0.0.0")
     room = h.getRoomByItemId(itemId)
     self.assertEqual(room.name, "lounge")
     self.assertEqual(room.id, roomId)
Ejemplo n.º 16
0
 def test_updateItem_wrongItemId(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.updateItem, 1, 2, "new name", "new brand", "lightSensor", "new ip")
     self.assertFalse(db.items.updateEntryCalled)
Ejemplo n.º 17
0
 def test_getRoomByItemId(self):
     db = MockDatabase()
     h = House(db)
     roomId = h.addRoom("lounge")
     id = 0
     itemId = h.addItem(id, "sensor", "mock", "motionSensor", "0.0.0.0")
     room = h.getRoomByItemId(itemId)
     self.assertEqual(room.name, "lounge")
     self.assertEqual(room.id, roomId)
Ejemplo n.º 18
0
 def test_deleteItem_invalidItemId(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.deleteItem, 1, 2)
     self.assertFalse(db.items.deleteEntryCalled)
Ejemplo n.º 19
0
 def test_deleteItem_invalidItemId(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.deleteItem, 1, 2)
     self.assertFalse(db.items.deleteEntryCalled)
Ejemplo n.º 20
0
 def test_updateItem_wrongItemId(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.updateItem, 1, 2, "new name",
                       "new brand", "lightSensor", "new ip")
     self.assertFalse(db.items.updateEntryCalled)
Ejemplo n.º 21
0
 def test_addItem(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     h.addItem(0, "sensor", "mock", "motionSensor", "0.0.0.0")
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i]._id, db.items.entries[MockItemsTable.i]._id)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].name, db.items.entries[MockItemsTable.i].name)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i]._type, "motionSensor")
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].brand, db.items.entries[MockItemsTable.i].brand)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].ip, db.items.entries[MockItemsTable.i].ip)
Ejemplo n.º 22
0
 def test_deleteItem(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     h.deleteItem(1, 1)
     self.assertRaises(KeyError, lambda: h.rooms[1].items[1])
     self.assertTrue(db.items.deleteEntryCalled)
Ejemplo n.º 23
0
 def test_deleteItem(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     h.deleteItem(1, 1)
     self.assertRaises(KeyError, lambda: h.rooms[1].items[1])
     self.assertTrue(db.items.deleteEntryCalled)
Ejemplo n.º 24
0
 def test_getHouseStructure(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     self.assertEqual(h.getStructure(),
                      {'rooms': [{
                          'id': 1,
                          'name': "lounge",
                          'items': []
                      }]})
Ejemplo n.º 25
0
 def test_getItemById(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     id = 0
     itemId = h.addItem(id, "sensor", "mock", "motionSensor", "0.0.0.0")
     item = h.getItemById(itemId)
     self.assertEqual(item.name, "sensor")
     self.assertEqual(item._type, "motionSensor")
     self.assertEqual(item._id, itemId)
     self.assertEqual(item.ip, "0.0.0.0")
     self.assertEqual(item.brand, "mock")
Ejemplo n.º 26
0
 def test_updateItem(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     h.updateItem(1, 1, "new name", "new brand", "lightSensor", "new ip")
     self.assertEqual(room.items[1].name, "new name")
     self.assertEqual(room.items[1].brand, "new brand")
     self.assertEqual(room.items[1]._type, "lightSensor")
     self.assertEqual(room.items[1].ip, "new ip")
     self.assertTrue(db.items.updateEntryCalled)
Ejemplo n.º 27
0
 def test_updateItem(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room}
     h.updateItem(1, 1, "new name", "new brand", "lightSensor", "new ip")
     self.assertEqual(room.items[1].name, "new name")
     self.assertEqual(room.items[1].brand, "new brand")
     self.assertEqual(room.items[1]._type, "lightSensor")
     self.assertEqual(room.items[1].ip, "new ip")
     self.assertTrue(db.items.updateEntryCalled)
Ejemplo n.º 28
0
    def test_stateChangesTriggered(self):
        db = MockDB()
        house = House(db)
        item = Openable(1, "item1", "mock", "door", "192.168.0.100", house.listenerManager)
        item.stateChanged = MethCallLogger(item.stateChanged)
        room = MockRoom(1, "lounge")
        room.items = {1: item}
        house.rooms = {1: room}

        item.close()

        # Sleep for 3 seconds to give the thread a chance to call checkForStateChange()
        time.sleep(3)

        self.assertTrue(item.stateChanged.was_called)
Ejemplo n.º 29
0
 def test_getState(self):
     db = MockDatabase()
     h = House(db)
     item1 = MockItem(1, "mockName", "mockBrand", "motionSensor", "mockIP")
     room = MockRoom(1, "lounge")
     room.items = {1: item1}
     h.rooms = {1: room, 2: room}
     self.assertEqual(
         h.getState(),
         {'states': [{
             "id": 1,
             "state": 1
         }, {
             "id": 1,
             "state": 1
         }]})
Ejemplo n.º 30
0
 def test_getVersion(self):
     tupleDB = (('motionSensor', 'getState'), ('light', 'on'),
                ('light', 'off'), ('light', 'getState'))
     db = MockDatabase(tupleDB)
     h = House(db)
     self.assertEqual(
         h.getVersion(), {
             'supportedTypes': {
                 'motionSensor': {
                     'states': [{
                         'id': 1,
                         'name': 'motion detected'
                     }, {
                         'id': 0,
                         'name': 'no motion'
                     }],
                     'supportedBrands': ['mock', 'arduino'],
                     'name':
                     'Motion Sensor',
                     'isPassive':
                     True,
                     'methods': ['getState']
                 },
                 'light': {
                     'states': [{
                         'method': 'on',
                         'id': 1,
                         'name': 'on'
                     }, {
                         'method': 'off',
                         'id': 0,
                         'name': 'off'
                     }],
                     'supportedBrands': ['mock', 'lightwaveRF'],
                     'name':
                     'Light',
                     'isPassive':
                     False,
                     'methods': ['on', 'off', 'getState']
                 }
             }
         })
Ejemplo n.º 31
0
 def test_getItemById(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     id = 0
     itemId = h.addItem(id, "sensor", "mock", "motionSensor", "0.0.0.0")
     item = h.getItemById(itemId)
     self.assertEqual(item.name, "sensor")
     self.assertEqual(item._type, "motionSensor")
     self.assertEqual(item._id, itemId)
     self.assertEqual(item.ip, "0.0.0.0")
     self.assertEqual(item.brand, "mock")
Ejemplo n.º 32
0
 def test_addItem(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     h.addItem(0, "sensor", "mock", "motionSensor", "0.0.0.0")
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i]._id,
                      db.items.entries[MockItemsTable.i]._id)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].name,
                      db.items.entries[MockItemsTable.i].name)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i]._type,
                      "motionSensor")
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].brand,
                      db.items.entries[MockItemsTable.i].brand)
     self.assertEqual(h.rooms[db.room.i].items[MockItemsTable.i].ip,
                      db.items.entries[MockItemsTable.i].ip)
Ejemplo n.º 33
0
 def test_getHouseStructure(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     self.assertEqual(h.getStructure(), {'rooms': [{'id': 1, 'name': "lounge", 'items': []}]})
Ejemplo n.º 34
0
 def test_deleteRoom_idNotInDict(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.deleteRoom, 2)
Ejemplo n.º 35
0
 def test_deleteRoom_emptyList(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.deleteRoom, 1)
Ejemplo n.º 36
0
 def test_getVersionEmpty(self):
     tupleDB = ()
     db = MockDatabase(tupleDB)
     h = House(db)
     self.assertEqual(h.getVersion(), {'supportedTypes': {}})
Ejemplo n.º 37
0
 def test_getHouseStructure_emptylist(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertEqual(h.getStructure(), {'rooms': []})
Ejemplo n.º 38
0
 def test_getHouseStructure_emptylist(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertEqual(h.getStructure(), {'rooms': []})
Ejemplo n.º 39
0
 def test_deleteItem_emptyList(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.deleteItem, 1, 1)
     self.assertFalse(db.items.deleteEntryCalled)
Ejemplo n.º 40
0
 def test_initFromDatabase(self):
     db = MockDatabase()
     h = House(db)
     h.initFromDatabase()
     self.assertEqual(h.rooms[1].name, "lounge")
     self.assertEqual(h.rooms[1].id, 1)
Ejemplo n.º 41
0
 def test_executeMethod_roomDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.executeMethod, 1, 1, "getState")
Ejemplo n.º 42
0
 def test_executeMethod_roomDoesNotExist(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.executeMethod, 1, 1, "getState")
Ejemplo n.º 43
0
 def test_getState_noRooms(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertEqual(h.getState(), {'states' : []})
Ejemplo n.º 44
0
 def test_getVersion(self):
     tupleDB = (('motionSensor', 'getState'), ('light', 'on'), ('light', 'off'), ('light', 'getState'))
     db = MockDatabase(tupleDB)
     h = House(db)
     self.assertEqual(h.getVersion(), {'supportedTypes': {'motionSensor': {'states': [{'id': 1, 'name': 'motion detected'}, {'id': 0, 'name': 'no motion'}], 'supportedBrands': ['mock', 'arduino'], 'name': 'Motion Sensor', 'isPassive': True, 'methods': ['getState']}, 'light': {'states': [{'method': 'on', 'id': 1, 'name': 'on'}, {'method': 'off', 'id': 0, 'name': 'off'}], 'supportedBrands': ['mock', 'lightwaveRF'], 'name': 'Light', 'isPassive': False, 'methods': ['on', 'off', 'getState']}}})
Ejemplo n.º 45
0
 def test_getVersionEmpty(self):
     tupleDB = ()
     db = MockDatabase(tupleDB)
     h = House(db)
     self.assertEqual(h.getVersion(), {'supportedTypes' : {}})
Ejemplo n.º 46
0
 def test_deleteRoom_idNotInDict(self):
     db = MockDatabase()
     h = House(db)
     room = MockRoom(1, "lounge")
     h.rooms = {1: room}
     self.assertRaises(KeyError, h.deleteRoom, 2)
Ejemplo n.º 47
0
 def test_initFromDatabase(self):
     db = MockDatabase()
     h = House(db)
     h.initFromDatabase()
     self.assertEqual(h.rooms[1].name, "lounge")
     self.assertEqual(h.rooms[1].id, 1)
Ejemplo n.º 48
0
 def test_getState_noRooms(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertEqual(h.getState(), {'states': []})
Ejemplo n.º 49
0
 def test_init(self):
     db = MockDatabase()
     h = House(db)
     self.assertEqual({}, h.rooms)
     self.assertEqual(db, h.database)
Ejemplo n.º 50
0
 def test_deleteRoom_emptyList(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.deleteRoom, 1)
Ejemplo n.º 51
0
 def test_deleteItem_emptyList(self):
     db = MockDatabase()
     h = House(db)
     h.rooms = {}
     self.assertRaises(KeyError, h.deleteItem, 1, 1)
     self.assertFalse(db.items.deleteEntryCalled)
Ejemplo n.º 52
0
 def test_addRoom(self):
     db = MockDatabase()
     h = House(db)
     h.addRoom("lounge")
     self.assertEqual(h.rooms[db.room.i].id, db.room.entries[db.room.i].id)
     self.assertEqual(h.rooms[db.room.i].name, db.room.entries[db.room.i].name)