Skip to content

Commit

Permalink
[EventHubs] add contains to DictMixin (#19886)
Browse files Browse the repository at this point in the history
  • Loading branch information
swathipil authored Jul 20, 2021
1 parent a65e853 commit f496498
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sdk/eventhub/azure-eventhub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("_")})
Expand Down
75 changes: 75 additions & 0 deletions sdk/eventhub/azure-eventhub/tests/unittest/test_dict_mixin.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f496498

Please sign in to comment.