Ejemplo n.º 1
0
    def test_get_attributes_success(self, m_repository):
        cfg = {'return_value.read.return_value': random_string()}
        m_repository.return_value.get_file.configure_mock(**cfg)

        controller = ztpserver.controller.NodesController()
        (resp, state) = controller.get_attributes(dict(),
                                                  resource=random_string())

        self.assertEqual(state, 'do_substitution')
        self.assertIsInstance(resp, dict)
Ejemplo n.º 2
0
    def test_get_attributes_success(self, m_repository):
        cfg = {'return_value.read.return_value': random_string()}
        m_repository.return_value.get_file.configure_mock(**cfg)

        controller = ztpserver.controller.NodesController()
        (resp, state) = controller.get_attributes(dict(),
                                                  resource=random_string())

        self.assertEqual(state, 'do_substitution')
        self.assertIsInstance(resp, dict)
Ejemplo n.º 3
0
    def test_get_attributes_missing(self, m_repository):
        node = create_node()

        m_repository.return_value.exists.return_value = False
        m_repository.return_value.get_file = \
            Mock(side_effect=ztpserver.repository.FileObjectNotFound)

        controller = ztpserver.controller.NodesController()
        (resp, state) = controller.get_attributes(dict(),
                                                  resource=node.serialnumber)

        self.assertEqual(state, 'do_substitution')
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['attributes'], dict())
Ejemplo n.º 4
0
    def test_get_attributes_missing(self, m_repository):
        node = create_node()

        m_repository.return_value.exists.return_value = False
        m_repository.return_value.get_file = \
            Mock(side_effect=ztpserver.repository.FileObjectNotFound)


        controller = ztpserver.controller.NodesController()
        (resp, state) = controller.get_attributes(dict(),
                                                  resource=node.serialnumber)

        self.assertEqual(state, 'do_substitution')
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['attributes'], dict())
    def test_get_attributes_success(self):
        systemmac = random_string()
        contents = random_string()

        filestore = Mock()
        filestore.return_value.get_file.return_value = Mock(contents=contents)
        ztpserver.controller.create_file_store = filestore

        controller = ztpserver.controller.NodesController()
        (resp, state) = controller.get_attributes(dict(), resource=systemmac)

        filepath = '%s/%s' % (systemmac, ztpserver.controller.ATTRIBUTES_FN)
        filestore.return_value.get_file.assert_called_with(filepath)
        self.assertEqual(state, 'do_substitution')
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['attributes'], contents)