diff --git a/CHANGES.rst b/CHANGES.rst index 2e00ac80..596ad6a0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ~~~~~~~~~~~~~~~~~~~ diff --git a/icat/query.py b/icat/query.py index e8e84eb0..65365259 100644 --- a/icat/query.py +++ b/icat/query.py @@ -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. @@ -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): diff --git a/tests/test_06_query.py b/tests/test_06_query.py index f41d0292..217ed7b4 100644 --- a/tests/test_06_query.py +++ b/tests/test_06_query.py @@ -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)