Ejemplo n.º 1
0
    def test_nsx_search_error_raise(self):
        """Check nsx_common.nsx_search func: error raise"""
        self._regen_ctx()
        client_session = mock.Mock()

        # we raise error?
        client_session.read = mock.Mock(return_value={
            'body': {}, 'status': 300
        })
        with self.assertRaises(cfy_exc.NonRecoverableError) as error:
            common.nsx_search(client_session, 'body/a', 'b', 'secret',
                              uri_parameters={'scopeId': 'scopeId'})
        self.assertEqual(
            str(error.exception),
            "We have error with request."
        )
Ejemplo n.º 2
0
    def test_nsx_search_dict(self):
        """Check nsx_common.nsx_search func: dict_result"""
        self._regen_ctx()
        client_session = mock.Mock()

        # dict result
        client_session.read = mock.Mock(return_value={
            'body': {'a': {'name': 'b', 'objectId': 'c'}}, 'status': 204
        })
        self.assertEqual(
            common.nsx_search(client_session, 'body/a', 'b', 'secret',
                              uri_parameters={'scopeId': 'scopeId'}),
            ('c', {'name': 'b', 'objectId': 'c'})
        )
Ejemplo n.º 3
0
    def test_nsx_search_no_results(self):
        """Check nsx_common.nsx_search func: no result"""
        self._regen_ctx()
        client_session = mock.Mock()

        # no results
        client_session.read = mock.Mock(return_value={
            'body': {}, 'status': 204
        })
        self.assertEqual(
            common.nsx_search(client_session, 'body/a', 'a', 'secret',
                              uri_parameters={'scopeId': 'scopeId'}),
            (None, None)
        )
Ejemplo n.º 4
0
    def test_nsx_search_no_object(self):
        """Check nsx_common.nsx_search func: no object"""
        self._regen_ctx()
        client_session = mock.Mock()

        # object not exist
        client_session.read = mock.Mock(return_value={
            'body': {'a': [{
                'name': 'b',
                'objectId': 'c'
            }, {
                'name': 'd',
                'objectId': 'e'
            }]}, 'status': 204
        })
        self.assertEqual(
            common.nsx_search(client_session, 'body/a', 'g', 'secret',
                              uri_parameters={'scopeId': 'scopeId'}),
            (None, None)
        )