[EventHubs] add contains to DictMixin (#19886)
This commit is contained in:
Родитель
a65e853537
Коммит
f496498f75
|
@ -1,5 +1,11 @@
|
|||
# Release History
|
||||
|
||||
## 5.6.1 (2021-07-07)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed a bug for checking that `azure.eventhub.amqp.AmqpMessageHeader` and `azure.eventhub.amqp.AmqpMessageProperties` contain specific properties using the `in` keyword.
|
||||
|
||||
## 5.6.0 (2021-07-07)
|
||||
|
||||
### Features Added
|
||||
|
|
|
@ -41,6 +41,10 @@ class DictMixin(object):
|
|||
"""Compare objects by comparing all attributes."""
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __contains__(self, key):
|
||||
# type: (Any) -> bool
|
||||
return key in self.__dict__
|
||||
|
||||
def __str__(self):
|
||||
# type: () -> str
|
||||
return str({k: v for k, v in self.__dict__.items() if not k.startswith("_")})
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# coding=utf-8
|
||||
# ------------------------------------
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
# ------------------------------------
|
||||
|
||||
import pytest
|
||||
from azure.eventhub._mixin import DictMixin
|
||||
|
||||
class TestDictMixin:
|
||||
|
||||
def test_contains_haskey(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
model.__setitem__(key, value)
|
||||
#assert model.__contains__(key)
|
||||
assert key in model
|
||||
assert model.has_key(key)
|
||||
|
||||
def test_getitem_get(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
model.__setitem__(key, value)
|
||||
assert model.__getitem__(key) == "testval"
|
||||
assert model.get(key) == "testval"
|
||||
|
||||
def test_repr_str(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
model.__setitem__(key, value)
|
||||
assert model.__repr__() == "{'testkey': 'testval'}"
|
||||
|
||||
def test_len_delitem(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
model.__setitem__(key, value)
|
||||
assert model.__len__() == 1
|
||||
model.__delitem__(key)
|
||||
assert model[key] is None
|
||||
|
||||
def test_eq_ne(self):
|
||||
model = DictMixin()
|
||||
model2 = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
value2 = "testval2"
|
||||
model.__setitem__(key, value)
|
||||
model2.__setitem__(key, value2)
|
||||
assert model.__ne__(model2) is True
|
||||
|
||||
def test_update(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
updatedval = "updatedval"
|
||||
model.__setitem__(key, value)
|
||||
updated = {key: updatedval}
|
||||
model.update(updated)
|
||||
assert model[key] == updatedval
|
||||
|
||||
def test_values_items(self):
|
||||
model = DictMixin()
|
||||
key = "testkey"
|
||||
value = "testval"
|
||||
key2 = "testkey2"
|
||||
value2 = "testval2"
|
||||
model.__setitem__(key, value)
|
||||
model.__setitem__(key2, value2)
|
||||
vals = model.values()
|
||||
for item in model.items():
|
||||
assert item[1] in vals
|
Загрузка…
Ссылка в новой задаче