|
35 | 35 | and can be run on their own by typing "python test_mockgun.py".
|
36 | 36 | """
|
37 | 37 |
|
| 38 | +import datetime |
38 | 39 | import re
|
39 | 40 | import os
|
40 | 41 | import unittest
|
@@ -188,14 +189,171 @@ def setUp(self):
|
188 | 189 | self._mockgun = Mockgun(
|
189 | 190 | "https://test.shotgunstudio.com", login="user", password="1234"
|
190 | 191 | )
|
191 |
| - self._user = self._mockgun.create("HumanUser", {"login": "user"}) |
| 192 | + self._user1 = self._mockgun.create("HumanUser", {"login": "user"}) |
| 193 | + self._user2 = self._mockgun.create("HumanUser", {"login": None}) |
| 194 | + |
| 195 | + def test_operator_is(self): |
| 196 | + """ |
| 197 | + Ensure is operator work. |
| 198 | + """ |
| 199 | + actual = self._mockgun.find("HumanUser", [["login", "is", "user"]]) |
| 200 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 201 | + self.assertEqual(expected, actual) |
| 202 | + |
| 203 | + def test_operator_is_none(self): |
| 204 | + """ |
| 205 | + Ensure is operator work when used with None. |
| 206 | + """ |
| 207 | + actual = self._mockgun.find("HumanUser", [["login", "is", None]]) |
| 208 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 209 | + self.assertEqual(expected, actual) |
| 210 | + |
| 211 | + def test_operator_is_case_sensitivity(self): |
| 212 | + """ |
| 213 | + Ensure is operator is case insensitive. |
| 214 | + """ |
| 215 | + actual = self._mockgun.find("HumanUser", [["login", "is", "USER"]]) |
| 216 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 217 | + self.assertEqual(expected, actual) |
| 218 | + |
| 219 | + def test_operator_is_not(self): |
| 220 | + """ |
| 221 | + Ensure the is_not operator works. |
| 222 | + """ |
| 223 | + actual = self._mockgun.find("HumanUser", [["login", "is_not", "user"]]) |
| 224 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 225 | + self.assertEqual(expected, actual) |
| 226 | + |
| 227 | + def test_operator_is_not_none(self): |
| 228 | + """ |
| 229 | + Ensure the is_not operator works when used with None. |
| 230 | + """ |
| 231 | + actual = self._mockgun.find("HumanUser", [["login", "is_not", None]]) |
| 232 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 233 | + self.assertEqual(expected, actual) |
| 234 | + |
| 235 | + def test_operator_is_not_case_sensitivity(self): |
| 236 | + """ |
| 237 | + Ensure the is_not operator is case insensitive. |
| 238 | + """ |
| 239 | + actual = self._mockgun.find("HumanUser", [["login", "is_not", "USER"]]) |
| 240 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 241 | + self.assertEqual(expected, actual) |
| 242 | + |
| 243 | + def test_operator_in(self): |
| 244 | + """ |
| 245 | + Ensure the in operator works. |
| 246 | + """ |
| 247 | + actual = self._mockgun.find("HumanUser", [["login", "in", ["user"]]]) |
| 248 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 249 | + self.assertEqual(expected, actual) |
| 250 | + |
| 251 | + def test_operator_in_none(self): |
| 252 | + """ |
| 253 | + Ensure the in operator works with a list containing None. |
| 254 | + """ |
| 255 | + actual = self._mockgun.find("HumanUser", [["login", "in", [None]]]) |
| 256 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 257 | + self.assertEqual(expected, actual) |
| 258 | + |
| 259 | + def test_operator_in_case_sensitivity(self): |
| 260 | + """ |
| 261 | + Ensure the in operator is case insensitive. |
| 262 | + """ |
| 263 | + actual = self._mockgun.find("HumanUser", [["login", "in", ["USER"]]]) |
| 264 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 265 | + self.assertEqual(expected, actual) |
| 266 | + |
| 267 | + def test_operator_not_in(self): |
| 268 | + """ |
| 269 | + Ensure the not_in operator works. |
| 270 | + """ |
| 271 | + actual = self._mockgun.find("HumanUser", [["login", "not_in", ["foo"]]]) |
| 272 | + expected = [ |
| 273 | + {"type": "HumanUser", "id": self._user1["id"]}, |
| 274 | + {"type": "HumanUser", "id": self._user2["id"]}, |
| 275 | + ] |
| 276 | + self.assertEqual(expected, actual) |
| 277 | + |
| 278 | + def test_operator_not_in_none(self): |
| 279 | + """ |
| 280 | + Ensure the not_not operator works with a list containing None. |
| 281 | + """ |
| 282 | + actual = self._mockgun.find("HumanUser", [["login", "not_in", [None]]]) |
| 283 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 284 | + self.assertEqual(expected, actual) |
| 285 | + |
| 286 | + def test_operator_not_in_case_sensitivity(self): |
| 287 | + """ |
| 288 | + Ensure the not_in operator is case insensitive. |
| 289 | + """ |
| 290 | + actual = self._mockgun.find("HumanUser", [["login", "not_in", ["USER"]]]) |
| 291 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 292 | + self.assertEqual(expected, actual) |
192 | 293 |
|
193 | 294 | def test_operator_contains(self):
|
194 | 295 | """
|
195 |
| - Ensures contains operator works. |
| 296 | + Ensures the contains operator works. |
196 | 297 | """
|
197 |
| - item = self._mockgun.find_one("HumanUser", [["login", "contains", "se"]]) |
198 |
| - self.assertTrue(item) |
| 298 | + actual = self._mockgun.find("HumanUser", [["login", "contains", "se"]]) |
| 299 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 300 | + self.assertEqual(expected, actual) |
| 301 | + |
| 302 | + def test_operator_contains_case_sensitivity(self): |
| 303 | + """ |
| 304 | + Ensure the contains operator is case insensitive. |
| 305 | + """ |
| 306 | + actual = self._mockgun.find("HumanUser", [["login", "contains", "SE"]]) |
| 307 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 308 | + self.assertEqual(expected, actual) |
| 309 | + |
| 310 | + def test_operator_not_contains(self): |
| 311 | + """ |
| 312 | + Ensure the not_contains operator works. |
| 313 | + """ |
| 314 | + actual = self._mockgun.find("HumanUser", [["login", "not_contains", "user"]]) |
| 315 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 316 | + self.assertEqual(expected, actual) |
| 317 | + |
| 318 | + def test_operator_not_contains_case_sensitivity(self): |
| 319 | + """ |
| 320 | + Ensure the not_contains operator is case insensitive. |
| 321 | + """ |
| 322 | + actual = self._mockgun.find("HumanUser", [["login", "not_contains", "USER"]]) |
| 323 | + expected = [{"type": "HumanUser", "id": self._user2["id"]}] |
| 324 | + self.assertEqual(expected, actual) |
| 325 | + |
| 326 | + def test_operator_starts_with(self): |
| 327 | + """ |
| 328 | + Ensure the starts_with operator works. |
| 329 | + """ |
| 330 | + actual = self._mockgun.find("HumanUser", [["login", "starts_with", "us"]]) |
| 331 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 332 | + self.assertEqual(expected, actual) |
| 333 | + |
| 334 | + def test_operator_starts_with_case_sensitivity(self): |
| 335 | + """ |
| 336 | + Ensure the starts_with operator is case insensitive. |
| 337 | + """ |
| 338 | + actual = self._mockgun.find("HumanUser", [["login", "starts_with", "US"]]) |
| 339 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 340 | + self.assertEqual(expected, actual) |
| 341 | + |
| 342 | + def test_operator_ends_with(self): |
| 343 | + """ |
| 344 | + Ensure the ends_with operator works. |
| 345 | + """ |
| 346 | + actual = self._mockgun.find("HumanUser", [["login", "ends_with", "er"]]) |
| 347 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 348 | + self.assertEqual(expected, actual) |
| 349 | + |
| 350 | + def test_operator_ends_with_case_sensitivity(self): |
| 351 | + """ |
| 352 | + Ensure the starts_with operator is case insensitive. |
| 353 | + """ |
| 354 | + actual = self._mockgun.find("HumanUser", [["login", "ends_with", "ER"]]) |
| 355 | + expected = [{"type": "HumanUser", "id": self._user1["id"]}] |
| 356 | + self.assertEqual(expected, actual) |
199 | 357 |
|
200 | 358 |
|
201 | 359 | class TestMultiEntityFieldComparison(unittest.TestCase):
|
@@ -345,10 +503,12 @@ def test_update_add(self):
|
345 | 503 | """
|
346 | 504 | Ensures that "add" multi_entity_update_mode works.
|
347 | 505 | """
|
| 506 | + # Attempts to add _version2 |
| 507 | + # It already exists on the playlist and should not be duplicated |
348 | 508 | self._mockgun.update(
|
349 | 509 | "Playlist",
|
350 | 510 | self._add_playlist["id"],
|
351 |
| - {"versions": [self._version3]}, |
| 511 | + {"versions": [self._version2, self._version3]}, |
352 | 512 | multi_entity_update_modes={"versions": "add"},
|
353 | 513 | )
|
354 | 514 |
|
@@ -429,15 +589,29 @@ def setUp(self):
|
429 | 589 | self._prj2_link = self._mockgun.create("Project", {"name": "prj2"})
|
430 | 590 |
|
431 | 591 | self._shot1 = self._mockgun.create(
|
432 |
| - "Shot", {"code": "shot1", "project": self._prj1_link} |
| 592 | + "Shot", |
| 593 | + { |
| 594 | + "code": "shot1", |
| 595 | + "project": self._prj1_link, |
| 596 | + "description": "a", |
| 597 | + "sg_cut_order": 2, |
| 598 | + }, |
433 | 599 | )
|
434 | 600 |
|
435 | 601 | self._shot2 = self._mockgun.create(
|
436 |
| - "Shot", {"code": "shot2", "project": self._prj1_link} |
| 602 | + "Shot", {"code": "shot2", "project": self._prj1_link, "sg_cut_order": 1} |
437 | 603 | )
|
438 | 604 |
|
439 | 605 | self._shot3 = self._mockgun.create(
|
440 |
| - "Shot", {"code": "shot3", "project": self._prj2_link} |
| 606 | + "Shot", {"code": "shot3", "project": self._prj2_link, "description": "b"} |
| 607 | + ) |
| 608 | + |
| 609 | + self._user1 = self._mockgun.create( |
| 610 | + "HumanUser", {"login": "user1", "password_strength": 0.2} |
| 611 | + ) |
| 612 | + |
| 613 | + self._user2 = self._mockgun.create( |
| 614 | + "HumanUser", {"login": "user2", "created_at": datetime.datetime(2025, 1, 1)} |
441 | 615 | )
|
442 | 616 |
|
443 | 617 | def test_simple_filter_operators(self):
|
@@ -468,6 +642,47 @@ def test_simple_filter_operators(self):
|
468 | 642 |
|
469 | 643 | self.assertEqual(len(shots), 0)
|
470 | 644 |
|
| 645 | + def test_ordered_filter_operator(self): |
| 646 | + """ |
| 647 | + Test use of the order feature of filter_operator on supported data types. |
| 648 | + """ |
| 649 | + find_args = ["Shot", [], ["code"]] |
| 650 | + |
| 651 | + # str field |
| 652 | + shots = self._mockgun.find( |
| 653 | + *find_args, order=[{"field_name": "description", "direction": "asc"}] |
| 654 | + ) |
| 655 | + self.assertEqual([s["code"] for s in shots], ["shot2", "shot1", "shot3"]) |
| 656 | + |
| 657 | + shots = self._mockgun.find( |
| 658 | + *find_args, order=[{"field_name": "description", "direction": "desc"}] |
| 659 | + ) |
| 660 | + self.assertEqual([s["code"] for s in shots], ["shot3", "shot1", "shot2"]) |
| 661 | + |
| 662 | + # int field |
| 663 | + shots = self._mockgun.find( |
| 664 | + *find_args, order=[{"field_name": "sg_cut_order", "direction": "asc"}] |
| 665 | + ) |
| 666 | + self.assertEqual([s["code"] for s in shots], ["shot3", "shot2", "shot1"]) |
| 667 | + |
| 668 | + # float field |
| 669 | + users = self._mockgun.find( |
| 670 | + "HumanUser", |
| 671 | + [], |
| 672 | + ["login"], |
| 673 | + order=[{"field_name": "password_strength", "direction": "asc"}], |
| 674 | + ) |
| 675 | + self.assertEqual([u["login"] for u in users], ["user2", "user1"]) |
| 676 | + |
| 677 | + # date_time field |
| 678 | + users = self._mockgun.find( |
| 679 | + "HumanUser", |
| 680 | + [], |
| 681 | + ["login"], |
| 682 | + order=[{"field_name": "created_at", "direction": "asc"}], |
| 683 | + ) |
| 684 | + self.assertEqual([u["login"] for u in users], ["user1", "user2"]) |
| 685 | + |
471 | 686 | def test_nested_filter_operators(self):
|
472 | 687 | """
|
473 | 688 | Tests a the use of the filter_operator nested
|
|
0 commit comments