diff --git a/sdk/eventhub/azure-eventhub/CHANGELOG.md b/sdk/eventhub/azure-eventhub/CHANGELOG.md index 084e27f55c83..2299941d6cc2 100644 --- a/sdk/eventhub/azure-eventhub/CHANGELOG.md +++ b/sdk/eventhub/azure-eventhub/CHANGELOG.md @@ -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 diff --git a/sdk/eventhub/azure-eventhub/azure/eventhub/_mixin.py b/sdk/eventhub/azure-eventhub/azure/eventhub/_mixin.py index f1db10965826..ff25ea4083d4 100644 --- a/sdk/eventhub/azure-eventhub/azure/eventhub/_mixin.py +++ b/sdk/eventhub/azure-eventhub/azure/eventhub/_mixin.py @@ -41,6 +41,10 @@ def __ne__(self, other): """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("_")}) diff --git a/sdk/eventhub/azure-eventhub/tests/unittest/test_dict_mixin.py b/sdk/eventhub/azure-eventhub/tests/unittest/test_dict_mixin.py new file mode 100644 index 000000000000..e43f34c491a0 --- /dev/null +++ b/sdk/eventhub/azure-eventhub/tests/unittest/test_dict_mixin.py @@ -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