[Kimchi-devel] [PATCH V2][Wok 05/12] FVT: Base test class, takes care common actions required for any FVT test cases.

Aline Manera alinefm at linux.vnet.ibm.com
Thu Jul 21 20:46:12 UTC 2016



On 05/30/2016 04:10 AM, archus at linux.vnet.ibm.com wrote:
> From: Archana Singh <archus at linux.vnet.ibm.com>
>
> Common action methods like creating/destoring session,
> authorization using wok level fvt config file,
> creating JSON validator and logging.

I'd like to understand better what you are calling 'session'.
Wok works with an internal user session on backend. Why do we need a 
different one to do the tests?

> Signed-off-by: Archana Singh <archus at linux.vnet.ibm.com>
> ---
>   tests/fvt/fvt_base.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 92 insertions(+)
>   create mode 100644 tests/fvt/fvt_base.py
>
> diff --git a/tests/fvt/fvt_base.py b/tests/fvt/fvt_base.py
> new file mode 100644
> index 0000000..8d152a5
> --- /dev/null
> +++ b/tests/fvt/fvt_base.py
> @@ -0,0 +1,92 @@
> +#!/usr/bin/python
> +# -*- coding: utf-8 -*-
> +#

The same I commented before about that coding macro.
It is only needed when you have non-ASCII characters in the code source 
file. And it seems to not be the case. So you can safely remove it.

> +# Project Wok
> +#
> +# Copyright IBM Corp, 2016
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301USA
> +

> +import unittest
> +import os
> +from restapilib import APISession, APIError, APIRequestError
> +from restapilib import Validator
> +

The import section must be in alphabetic order.

> +DEFAULT_CONF = os.path.dirname(os.path.abspath(__file__)) + 'config'
> +
> +
> +class TestBase(unittest.TestCase):
> +    """Represents an API session setup with the host Web Services API"""
> +
> +    session = None
> +
> +    def __init__(self, method='runTest'):
> +        """init with default method as runTest"""
> +        super(TestBase, self).__init__(method)
> +
> +    @classmethod
> +    def setUpClass(cls):
> +        """
> +        Hook method for setting up class fixture
> +        before running tests in the class.
> +        Create session and set auth to the session
> +        """
> +        print '--> TestBase.setUpClass(): Create session '
> +        cls.session = APISession()
> +        # Log on to the API.  An exception will be raised if this fails.
> +        cls.logging = cls.session.logging
> +        cls.logging.debug('--> TestBase.setUpClass()')
> +        cls.validator = Validator(cls.logging)
> +        cls.logging.debug('TestBase.setUpClass(): Setting auth to session')
> +        try:
> +            cls.session.auth()
> +            cls.logging.debug('TestBase.setUpClass(): Auth details set to '
> +                              'session and base URI created as %s'
> +                              % cls.session._base_uri)
> +        except APIError, err:
> +            print 'ERROR %s' % err
> +            print err.__str__()
> +            if cls.session is not None:
> +                cls.logging.error('TestBase.setUpClass(): Ending session'
> +                                  ' as API error happened')
> +                cls.session.end_session()
> +        finally:
> +            cls.logging.debug('<-- TestBase.setUpClass()')
> +
> +    def setUp(self):
> +        """Hook method for setting up the test fixture before exercising it."""
> +        pass
> +
> +    def tearDown(self):
> +        """Hook method for deconstructing the test fixture after testing it."""
> +        pass
> +
> +    @classmethod
> +    def tearDownClass(cls):
> +        """
> +        Hook method for deconstructing the class
> +        fixture after running all tests in the class.
> +        """
> +        if cls.session is not None:
> +            print 'TestBase.tearDownClass(): Ending session'
> +            cls.session.end_session()
> +
> +    def get(self):
> +        try:
> +            resp_net = self.session.request_get_json('/')
> +            print resp_net
> +        except APIRequestError as err:
> +            print 'ERROR %s' % err
> +            print err.__str__()




More information about the Kimchi-devel mailing list