2013-07-27 20:24:38 +00:00
|
|
|
import boto
|
2020-10-06 05:54:49 +00:00
|
|
|
from unittest import SkipTest
|
2021-10-23 11:40:41 +00:00
|
|
|
from collections.abc import Iterable, Mapping
|
2021-10-18 09:17:31 +00:00
|
|
|
from sure import assertion
|
2013-07-27 20:24:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def version_tuple(v):
|
|
|
|
return tuple(map(int, (v.split("."))))
|
|
|
|
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
# Note: See https://github.com/spulec/moto/issues/201 for why this is a
|
|
|
|
# separate method.
|
2014-09-10 19:49:20 +00:00
|
|
|
def skip_test():
|
|
|
|
raise SkipTest
|
|
|
|
|
|
|
|
|
2013-07-27 20:24:38 +00:00
|
|
|
class requires_boto_gte(object):
|
|
|
|
"""Decorator for requiring boto version greater than or equal to 'version'"""
|
2017-02-24 02:37:43 +00:00
|
|
|
|
2013-07-27 20:24:38 +00:00
|
|
|
def __init__(self, version):
|
|
|
|
self.version = version
|
|
|
|
|
|
|
|
def __call__(self, test):
|
|
|
|
boto_version = version_tuple(boto.__version__)
|
|
|
|
required = version_tuple(self.version)
|
|
|
|
if boto_version >= required:
|
2014-01-24 15:45:39 +00:00
|
|
|
return test
|
2014-09-10 19:49:20 +00:00
|
|
|
return skip_test
|
2021-10-18 09:17:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@assertion
|
|
|
|
def containing_item_with_attributes(context, **kwargs):
|
|
|
|
contains = False
|
|
|
|
if kwargs and isinstance(context.obj, Iterable):
|
|
|
|
for item in context.obj:
|
|
|
|
if not isinstance(item, dict):
|
|
|
|
continue
|
|
|
|
for k, v in kwargs.items():
|
|
|
|
if k not in item or item[k] != v:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
contains = True
|
|
|
|
if context.negative:
|
|
|
|
assert not contains, f"{context.obj} contains matching item {kwargs}"
|
|
|
|
else:
|
|
|
|
assert contains, f"{context.obj} does not contain matching item {kwargs}"
|
|
|
|
return True
|
2021-10-23 11:40:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
@assertion
|
|
|
|
def match_dict(context, dict_value):
|
|
|
|
assert isinstance(dict_value, Mapping), f"Invalid match target value: {dict_value}"
|
|
|
|
assert isinstance(
|
|
|
|
context.obj, Mapping
|
|
|
|
), f"Expected dict like object, but got: {context.obj}"
|
|
|
|
|
|
|
|
for k, v in dict_value.items():
|
|
|
|
assert k in context.obj, f"No such key '{k}' in {context.obj}"
|
|
|
|
context.obj[k].should.equal(v)
|
|
|
|
return True
|