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

[dev] Make mockgun string comparison case insensitive (RDEV-15305) #20

Merged
merged 1 commit into from
Nov 11, 2019
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
2 changes: 1 addition & 1 deletion package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['[email protected]']
Expand Down
7 changes: 7 additions & 0 deletions shotgun_api3/lib/mockgun/mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
105 changes: 105 additions & 0 deletions tests/test_mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,118 @@ 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.
"""
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."""
Expand Down