From 24f379f9d1160c01c5324c69773f98fe391dfabb Mon Sep 17 00:00:00 2001 From: Renaud Lessard Larouche Date: Tue, 29 Oct 2019 16:16:30 -0400 Subject: [PATCH] Ensure mockgun string comparison are case insensitive --- package.py | 2 +- shotgun_api3/lib/mockgun/mockgun.py | 7 ++ tests/test_mockgun.py | 105 ++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/package.py b/package.py index 987ff20e..52c7dfa2 100644 --- a/package.py +++ b/package.py @@ -3,7 +3,7 @@ name = 'shotgun_api3' _shotgunSoftwareVersion = '3.1.1' -_rdoVersion = '1.0.0' +_rdoVersion = '1.1.0' version = '{0}-rdo-{1}'.format(_shotgunSoftwareVersion, _rdoVersion) authors = ['shotgundev@rodeofx.com'] diff --git a/shotgun_api3/lib/mockgun/mockgun.py b/shotgun_api3/lib/mockgun/mockgun.py index d26bf427..c0f71068 100644 --- a/shotgun_api3/lib/mockgun/mockgun.py +++ b/shotgun_api3/lib/mockgun/mockgun.py @@ -597,6 +597,13 @@ def _compare(self, field_type, lval, operator, rval): if operator == "is": return lval == rval elif field_type == "text": + # Shotgun string comparison is case insensitive + lval = lval.lower() + if isinstance(rval, list): + rval = [val.lower() for val in rval] + elif isinstance(rval, six.string_types): + rval = rval.lower() + if operator == "is": return lval == rval elif operator == "is_not": diff --git a/tests/test_mockgun.py b/tests/test_mockgun.py index b7e8b158..72c1a1b1 100644 --- a/tests/test_mockgun.py +++ b/tests/test_mockgun.py @@ -205,6 +205,62 @@ def setUp(self): self._mockgun = Mockgun("https://test.shotgunstudio.com", login="user", password="1234") self._user = self._mockgun.create("HumanUser", {"login": "user"}) + def test_operator_is(self): + """ + Ensure is operator work. + """ + item = self._mockgun.find_one("HumanUser", [["login", "is", "user"]]) + self.assertTrue(item) + + def test_operator_is_case_sensitivity(self): + """ + Ensure is operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "is", "USER"]]) + self.assertTrue(item) + + def test_operator_is_not(self): + """ + Ensure the is_not operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "is_not", "another_user"]]) + self.assertTrue(item) + + def test_operator_is_not_case_sensitivity(self): + """ + Ensure the is_not operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "is_not", "USER"]]) + self.assertFalse(item) + + def test_operator_in(self): + """ + Ensure the in operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "in", ["user"]]]) + self.assertTrue(item) + + def test_operator_in_case_sensitivity(self): + """ + Ensure the in operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "in", ["USER"]]]) + self.assertTrue(item) + + def test_operator_not_in(self): + """ + Ensure the not_in operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "not_in", ["foo"]]]) + self.assertTrue(item) + + def test_operator_not_in_case_sensitivity(self): + """ + Ensure not_in operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "not_in", ["USER"]]]) + self.assertFalse(item) + def test_operator_contains(self): """ Ensures contains operator works. @@ -212,6 +268,55 @@ def test_operator_contains(self): item = self._mockgun.find_one("HumanUser", [["login", "contains", "se"]]) self.assertTrue(item) + def test_operator_contains_case_sensitivity(self): + """ + Ensure contains operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "contains", "SE"]]) + self.assertTrue(item) + + def test_operator_not_contains(self): + """ + Ensure not_contains operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "not_contains", "foo"]]) + self.assertTrue(item) + + def test_operator_not_contains_case_sensitivity(self): + """ + Ensure not_contains operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "not_contains", "USER"]]) + self.assertFalse(item) + + def test_operator_starts_with(self): + """ + Ensure starts_with operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "starts_with", "us"]]) + self.assertTrue(item) + + def test_operator_starts_with_case_sensitivity(self): + """ + Ensure starts_with operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "starts_with", "US"]]) + self.assertTrue(item) + + def test_operator_ends_with(self): + """ + Ensure ends_with operator works. + """ + item = self._mockgun.find_one("HumanUser", [["login", "ends_with", "er"]]) + self.assertTrue(item) + + def test_operator_ends_with_case_sensitivity(self): + """ + Ensure starts_with operator is case insensitive. + """ + item = self._mockgun.find_one("HumanUser", [["login", "ends_with", "ER"]]) + self.assertTrue(item) + class TestDateDatetimeFields(TestBaseWithExceptionTests): """Test Suite for the behavior of the fields date and datetime."""