-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EventHubs] add contains to DictMixin (#19886)
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
sdk/eventhub/azure-eventhub/tests/unittest/test_dict_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |