Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / tests / __init__.py @ 6d192774

History | View | Annotate | Download (2.6 kB)

1 6d192774 Stavros Sachtouris
# Copyright 2012-2013 GRNET S.A. All rights reserved.
2 6d192774 Stavros Sachtouris
#
3 6d192774 Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 6d192774 Stavros Sachtouris
# without modification, are permitted provided that the following
5 6d192774 Stavros Sachtouris
# conditions are met:
6 6d192774 Stavros Sachtouris
#
7 6d192774 Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 6d192774 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 6d192774 Stavros Sachtouris
#      disclaimer.
10 6d192774 Stavros Sachtouris
#
11 6d192774 Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 6d192774 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 6d192774 Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 6d192774 Stavros Sachtouris
#      provided with the distribution.
15 6d192774 Stavros Sachtouris
#
16 6d192774 Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6d192774 Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6d192774 Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6d192774 Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6d192774 Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6d192774 Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6d192774 Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6d192774 Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6d192774 Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6d192774 Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6d192774 Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6d192774 Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 6d192774 Stavros Sachtouris
#
29 6d192774 Stavros Sachtouris
# The views and conclusions contained in the software and
30 6d192774 Stavros Sachtouris
# documentation are those of the authors and should not be
31 6d192774 Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 6d192774 Stavros Sachtouris
# or implied, of GRNET S.A.
33 6d192774 Stavros Sachtouris
34 6d192774 Stavros Sachtouris
from kamaki.cli.config import Config
35 6d192774 Stavros Sachtouris
36 6d192774 Stavros Sachtouris
37 6d192774 Stavros Sachtouris
def _add_value(foo, value):
38 6d192774 Stavros Sachtouris
    def wrap(self):
39 6d192774 Stavros Sachtouris
        return foo(self, value)
40 6d192774 Stavros Sachtouris
    return wrap
41 6d192774 Stavros Sachtouris
42 6d192774 Stavros Sachtouris
43 6d192774 Stavros Sachtouris
class configuration(object):
44 6d192774 Stavros Sachtouris
45 6d192774 Stavros Sachtouris
    _cnf = None
46 6d192774 Stavros Sachtouris
    _client = ''
47 6d192774 Stavros Sachtouris
48 6d192774 Stavros Sachtouris
    def __init__(self, client='', config_file=None):
49 6d192774 Stavros Sachtouris
        self._cnf = Config(config_file)
50 6d192774 Stavros Sachtouris
        self._client = client
51 6d192774 Stavros Sachtouris
52 6d192774 Stavros Sachtouris
        @property
53 6d192774 Stavros Sachtouris
        def generic_property(self, value):
54 6d192774 Stavros Sachtouris
            """
55 6d192774 Stavros Sachtouris
            :param client: (str) if given, try to get test_client.* and then
56 6d192774 Stavros Sachtouris
            client.*
57 6d192774 Stavros Sachtouris
            :returns: (str) priorities: test_client, client, test, global
58 6d192774 Stavros Sachtouris
            """
59 6d192774 Stavros Sachtouris
            if not hasattr(self, '_%s' % value):
60 6d192774 Stavros Sachtouris
                _acnt = self._cnf.get('test', '%s_%s' % (self._client, value))\
61 6d192774 Stavros Sachtouris
                    or self._cnf.get(self._client, value)\
62 6d192774 Stavros Sachtouris
                    or self._cnf.get('test', value)\
63 6d192774 Stavros Sachtouris
                    or self._cnf.get('global', value)
64 6d192774 Stavros Sachtouris
                if _acnt:
65 6d192774 Stavros Sachtouris
                    setattr(self, '_%s' % value, _acnt)
66 6d192774 Stavros Sachtouris
            return getattr(self, '_%s' % value, None)
67 6d192774 Stavros Sachtouris
68 6d192774 Stavros Sachtouris
        for foo in ('url', 'token'):
69 6d192774 Stavros Sachtouris
            setattr(self, foo, _add_value(generic_property, foo))