示例#1
0
class TestLookupDict:
    @pytest.fixture(autouse=True)
    def setup(self):
        """LookupDict instance with "bad_gateway" attribute."""
        self.lookup_dict = LookupDict("test")
        self.lookup_dict.bad_gateway = 502

    def test_repr(self):
        assert repr(self.lookup_dict) == "<lookup 'test'>"

    get_item_parameters = pytest.mark.parametrize(
        "key, value",
        (
            ("bad_gateway", 502),
            ("not_a_key", None),
        ),
    )

    @get_item_parameters
    def test_getitem(self, key, value):
        assert self.lookup_dict[key] == value

    @get_item_parameters
    def test_get(self, key, value):
        assert self.lookup_dict.get(key) == value
示例#2
0
from requests.structures import LookupDict

_codes = {
    0: ('ok', ),
    4100: ('param_invalid', ),
    4101: ('access_key_invalid', ),
    4103: ('resource_unauthorized', ),
    4104: ('resource_not_found', ),
    4105: ('action_disallow', ),
    4110: ('request_format_invalid', ),
    4113: ('quota_not_enough', ),
    5000: ('server_error', ),
    5001: ('actions_totally_failed', ),
    5002: ('actions_partially_failed', ),
}

codes = LookupDict(name='ret_codes')

for (code, titles) in list(_codes.items()):
    for title in titles:
        setattr(codes, title, code)
示例#3
0
 def setup(self):
     """LookupDict instance with "bad_gateway" attribute."""
     self.lookup_dict = LookupDict("test")
     self.lookup_dict.bad_gateway = 502
示例#4
0
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from requests.structures import LookupDict
import logging
logger = logging.getLogger(__name__)

_units = {

    # Informational.
    'bytecount': ('BYTECOUNT', ),
    'duration': ('DURATION', ),
    'number': ('NUMBER', ),
    'percent': ('PERCENT', ),
}

units = LookupDict(name='units')

for code, titles in _units.items():
    for title in titles:
        setattr(units, title, code)
        if not title.startswith('\\'):
            setattr(units, title.upper(), code)
示例#5
0
# -*- coding: utf-8 -*-

from requests.structures import LookupDict

_operators = {
    'eq': ('eq', 'equals'),
    'contains': ('contains', ),
    'exists': ('exists', ),
    'not_exists': ('not_exists', ),
}

operators = LookupDict(name='validation operations')

for (operator, titles) in list(_operators.items()):
    for title in titles:
        setattr(operators, title, operator)
        if not title.startswith('\\'):
            setattr(operators, title.upper(), operator)
示例#6
0
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from requests.structures import LookupDict
import logging

logger = logging.getLogger(__name__)

_aggregates = {

    'avg': ('AVG',),
    'min': ('MIN',),
    'max': ('MAX',),
    'sum': ('SUM',),
}

aggregates = LookupDict(name='aggregates')

for code, titles in _aggregates.items():
    for title in titles:
        setattr(aggregates, title, code)
        if not title.startswith('\\'):
            setattr(aggregates, title.upper(), code)
示例#7
-1
class TestLookupDict:

    @pytest.fixture(autouse=True)
    def setup(self):
        """LookupDict instance with "bad_gateway" attribute."""
        self.lookup_dict = LookupDict('test')
        self.lookup_dict.bad_gateway = 502

    def test_repr(self):
        assert repr(self.lookup_dict) == "<lookup 'test'>"

    get_item_parameters = pytest.mark.parametrize(
        'key, value', (
            ('bad_gateway', 502),
            ('not_a_key', None)
        )
    )

    @get_item_parameters
    def test_getitem(self, key, value):
        assert self.lookup_dict[key] == value

    @get_item_parameters
    def test_get(self, key, value):
        assert self.lookup_dict.get(key) == value
示例#8
-1
 def setup(self):
     """LookupDict instance with "bad_gateway" attribute."""
     self.lookup_dict = LookupDict('test')
     self.lookup_dict.bad_gateway = 502