def testGetHost(self): host = Host("coquito") mappersManager = self.createMapperMock() objectMapper = mock() when(mappersManager).getMapper(host.__class__.__name__).thenReturn(objectMapper) when(objectMapper).find(host.getName()).thenReturn(host) model_controller = controller.ModelController(mock(), mappersManager) host_obt = model_controller.getHost('coquito') verify(objectMapper).find(host.getName()) verify(mappersManager).getMapper(host.__class__.__name__) self.assertEqual(host, host_obt)
def testDelRemovesObjectFromTrie(self): host = Host("coquito") mappersManager = self.createMapperMock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(objectMapper) when(mappersManager).find(host.getID()).thenReturn(host) when(triemock).addWord(host.getName()).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.treeWordsTries = triemock model_controller.delHostSYNC(host.getID()) verify(mappersManager).remove(host.getID()) verify(triemock).removeWord(host.getName())
def testAddSavesObjectNameInTrie(self): host = Host('coco') mappersManager = self.createMapperMock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(objectMapper) when(objectMapper).save(host).thenReturn(True) when(triemock).addWord(host.getName()).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.treeWordsTries = triemock model_controller.addHostSYNC(host) verify(mappersManager).getMapper(host.class_signature) verify(objectMapper).save(host) verify(triemock).addWord(host.getName())
def testEditHostSyncGetsMapperDispatchedSYNC(self): host = Host("coquito") mappersManager = self.createMapperMock() dataMapper = mock() objectMapper = mock() triemock = mock() when(mappersManager).getMapper(host.class_signature).thenReturn(dataMapper) when(dataMapper).save(host).thenReturn(True) model_controller = controller.ModelController(mock(), mappersManager) model_controller.editHostSYNC(host, 'new_name', 'new_desc', 'new_os', True) verify(dataMapper).save(host) self.assertEquals(host.getName(), 'new_name', "Name not updated") self.assertEquals(host.getDescription(), 'new_desc', "Description not updated") self.assertEquals(host.getOS(), 'new_os', "OS not updated") self.assertEquals(host.isOwned(), True, "Owned status not updated")