Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LITE-29138 Fix bool method for ResourceSe #79

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions connect/client/models/resourceset.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ def __iter__(self):
return iter(self._results)

def __bool__(self):
self._fetch_all()
return bool(self._results)
if self._results is not None:
return bool(self._results)
copy = self._copy()
copy._fetch_all()
return bool(copy._results)

def __getitem__(self, key): # noqa: CCR001
self._validate_key(key)
Expand Down
69 changes: 0 additions & 69 deletions tests/client/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,37 +917,6 @@ def test_rs_values_list(mocker, rs_factory):
assert list(rs) == expected


def test_rs_values_list_evaluated(mocker, rs_factory):
mocker.patch(
'connect.client.models.resourceset.parse_content_range',
return_value=ContentRange(0, 9, 10),
)
return_value = [
{
'id': i,
'name': f'name {i}',
'inner': {
'title': f'title {i}',
},
}
for i in range(10)
]
expected = [
{
'id': i,
'inner.title': f'title {i}',
}
for i in range(10)
]
rs = rs_factory()
rs._client.get = mocker.MagicMock(return_value=return_value)

bool(rs)
values = rs.values_list('id', 'inner.title')

assert values == expected


def test_rs_pagination(mocker, rs_factory):
mocker.patch(
'connect.client.models.iterators.parse_content_range',
Expand Down Expand Up @@ -1127,20 +1096,6 @@ def test_rs_help(rs_factory):
assert rs2 == rs


def test_rs_bool_truthy_already_evaluated(mocker, rs_factory):
mocker.patch(
'connect.client.models.resourceset.parse_content_range',
return_value=ContentRange(0, 9, 10),
)
expected = [{'id': i} for i in range(10)]
rs = rs_factory()
mocked = mocker.patch.object(ResourceSet, '_execute_request', wraps=rs._execute_request)
rs._client.get = mocker.MagicMock(return_value=expected)
assert bool(rs) is True
assert bool(rs) is True
mocked.assert_called_once()


def test_rs_count_already_evaluated(mocker, rs_factory):
mocker.patch(
'connect.client.models.resourceset.parse_content_range',
Expand All @@ -1162,27 +1117,3 @@ def test_rs_slice_single_bound(mocker, rs_factory):
with pytest.raises(ValueError) as cv:
rs[:1]
assert str(cv.value) == 'Both start and stop indexes must be specified.'


def test_rs_slice_already_evaluated(mocker, rs_factory):
mocker.patch(
'connect.client.models.resourceset.parse_content_range',
return_value=ContentRange(0, 9, 10),
)
expected = [{'id': i} for i in range(10)]
rs = rs_factory()
rs._client.get = mocker.MagicMock(return_value=expected)
assert bool(rs) is True
assert rs[0:2] == expected[0:2]


def test_rs_iterate_already_evaluated(mocker, rs_factory):
mocker.patch(
'connect.client.models.resourceset.parse_content_range',
return_value=ContentRange(0, 9, 10),
)
expected = [{'id': i} for i in range(10)]
rs = rs_factory()
rs._client.get = mocker.MagicMock(return_value=expected)
assert bool(rs) is True
assert [item for item in rs] == expected