Skip to content
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
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ Changelog
=========


0.20.0 (not yet released)
~~~~~~~~~~~~~~~~~~~~~~~~~

Bug fixes and minor changes
---------------------------

+ `#90`_, `#91`_, `#95`_: :attr:`icat.query.Query.join_specs` was not
taken into account in :meth:`icat.query.Query.copy` and
:meth:`icat.query.Query.__repr__`.

.. _#90: https://github.com/icatproject/python-icat/issues/90
.. _#91: https://github.com/icatproject/python-icat/issues/91
.. _#95: https://github.com/icatproject/python-icat/pull/95


0.19.0 (2021-07-20)
~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 4 additions & 2 deletions icat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,13 @@ def __repr__(self):
"""Return a formal representation of the query.
"""
return ("%s(%s, %s, attributes=%s, aggregate=%s, order=%s, "
"conditions=%s, includes=%s, limit=%s)"
"conditions=%s, includes=%s, limit=%s, join_specs=%s)"
% (self.__class__.__name__,
repr(self.client), repr(self.entity.BeanName),
repr(self.attributes), repr(self.aggregate),
repr(self.order), repr(self.conditions),
repr(self.includes), repr(self.limit)))
repr(self.includes), repr(self.limit),
repr(self.join_specs)))

def __str__(self):
"""Return a string representation of the query.
Expand Down Expand Up @@ -538,6 +539,7 @@ def copy(self):
q.conditions = self.conditions.copy()
q.includes = self.includes.copy()
q.limit = self.limit
q.join_specs = self.join_specs.copy()
return q

def setAttribute(self, attribute):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_06_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,3 +763,32 @@ def test_query_aggregate_misc(client, attribute, aggregate, expected):
assert len(res) == 1
assert res[0] == expected

@pytest.mark.parametrize(("entity", "kwargs"), [
("Datafile", dict(attributes="name", order=True)),
("InvestigationUser",
dict(attributes=("investigation.name", "role"),
conditions={"investigation.name": "= '08100122-EF'"},
aggregate="DISTINCT")),
("Datafile", dict(order=[("name", "ASC")])),
("Datafile", dict(conditions={
"name": "= 'e208945.nxs'",
"dataset.name": "= 'e208945'",
"dataset.investigation.name": "= '12100409-ST'",
})),
("Instrument", dict(order=["name"],
includes={"facility", "instrumentScientists.user"})),
("Rule", dict(order=['grouping', 'what', 'id'],
conditions={"grouping":"IS NOT NULL"},
limit=(0,10))),
("Rule", dict(order=['grouping', 'what', 'id'],
join_specs={"grouping": "LEFT OUTER JOIN"})),
])
def test_query_copy(client, entity, kwargs):
"""Test the Query.copy() method.

Very basic test: verify that Query.copy() yields an equivalent
query for various Query() constructor argument sets.
"""
query = Query(client, entity, **kwargs)
clone = query.copy()
assert str(clone) == str(query)