コード例 #1
0
    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)
コード例 #2
0
ファイル: mapper.py プロジェクト: forbidden-ali/faraday
 def test_host_serialization(self):
     host = Host(name="pepito", os="linux")
     host.setDescription("Some description")
     host.setOwned(True)
     hserialized = self.hmapper.serialize(host)
     # if serialization fails, returns None
     self.assertNotEqual(
         hserialized,
         None,
         "Serialized host shouldn't be None")
     # we check the host attributes
     self.assertEquals(
         hserialized.get("_id"),
         host.getID(),
         "Serialized ID is not the same as Host ID")
     self.assertEquals(
         hserialized.get("name"),
         host.getName(),
         "Serialized name is not the same as Host name")
     self.assertEquals(
         hserialized.get("os"),
         host.getOS(),
         "Serialized OS is not the same as Host OS")
     self.assertEquals(
         hserialized.get("description"),
         host.getDescription(),
         "Serialized description is not the same as Host description")
     self.assertEquals(
         hserialized.get("owned"),
         host.isOwned(),
         "Serialized owned flag is not the same as Host owned flag")
コード例 #3
0
    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()) 
コード例 #4
0
    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())
コード例 #5
0
    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)
コード例 #6
0
ファイル: model_controller.py プロジェクト: BwRy/faraday
    def testAddSavesObjectNameInTrie(self):
        host = Host('coco')

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        triemock = mock()

        when(mappersManager).getMapper(host).thenReturn(objectMapper)
        when(objectMapper).saveObject(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)
        verify(objectMapper).saveObject(host)
        verify(triemock).addWord(host.getName())
コード例 #7
0
    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())
コード例 #8
0
    def test_host_saving(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        self.assertNotEquals(self.connector.getDocument(host.getID()), None,
                             "Document shouldn't be None")

        self.assertEquals(
            self.connector.getDocument(host.getID()).get("name"),
            host.getName(), "Document should have the same host name")
コード例 #9
0
ファイル: mapper_integration.py プロジェクト: BwRy/faraday
    def test_host_saving(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        self.assertNotEquals(
            self.connector.getDocument(host.getID()),
            None,
            "Document shouldn't be None")

        self.assertEquals(
            self.connector.getDocument(host.getID()).get("name"),
            host.getName(),
            "Document should have the same host name")
コード例 #10
0
ファイル: model_controller.py プロジェクト: BwRy/faraday
    def testEditHostSyncGetsMapperDispatchedSYNC(self):
        host = Host("coquito")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        triemock = mock()
        when(mappersManager).find(host.getID()).thenReturn(host)
        when(mappersManager).saveObject(host).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager) 

        model_controller.editHostSYNC(host.getID(), 'new_name', 'new_desc', 'new_os', True)

        verify(mappersManager).saveObject(host) 
        verify(mappersManager).find(host.getID())

        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")
コード例 #11
0
    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")