Skip to content

Commit 75315e0

Browse files
committed
For #28441: added support + tests for 'include_template_projects' flag
1 parent 18358b5 commit 75315e0

3 files changed

Lines changed: 184 additions & 19 deletions

File tree

shotgun_api3/shotgun.py

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ def ensure_include_archived_projects(self):
162162
'label': 'include_archived_projects parameter'
163163
})
164164

165+
def ensure_include_template_projects(self):
166+
"""Wrapper for ensure_support"""
167+
self._ensure_support({
168+
'version': (6, 0, 0),
169+
'label': 'include_template_projects parameter'
170+
})
171+
165172

166173
def __str__(self):
167174
return "ServerCapabilities: host %s, version %s, is_dev %s"\
@@ -426,7 +433,8 @@ def info(self):
426433
return self._call_rpc("info", None, include_auth_params=False)
427434

428435
def find_one(self, entity_type, filters, fields=None, order=None,
429-
filter_operator=None, retired_only=False, include_archived_projects=True):
436+
filter_operator=None, retired_only=False,
437+
include_archived_projects=True, include_template_projects=False):
430438
"""Calls the find() method and returns the first result, or None.
431439
432440
:param entity_type: Required, entity type (string) to find.
@@ -445,24 +453,34 @@ def find_one(self, entity_type, filters, fields=None, order=None,
445453
:param limit: Optional, number of entities to return per page.
446454
Defaults to 0 which returns all entities that match.
447455
448-
:param page: Optional, page of results to return. By default all
449-
results are returned. Use together with limit.
450-
451456
:param retired_only: Optional, flag to return only entities that have
452457
been retried. Defaults to False which returns only entities which
453458
have not been retired.
459+
460+
:param page: Optional, page of results to return. By default all
461+
results are returned. Use together with limit.
462+
463+
:param include_archived_projects: Optional, flag to include entities
464+
whose projects have been archived. Default: True
465+
466+
:param include_template_projects: Optional, flag to include entities
467+
belonging to template projects. Default: False
468+
469+
:returns: Result
454470
"""
455471

456472
results = self.find(entity_type, filters, fields, order,
457-
filter_operator, 1, retired_only, include_archived_projects=include_archived_projects)
473+
filter_operator, 1, retired_only,
474+
include_archived_projects=include_archived_projects,
475+
include_template_projects=include_template_projects)
458476

459477
if results:
460478
return results[0]
461479
return None
462480

463481
def find(self, entity_type, filters, fields=None, order=None,
464482
filter_operator=None, limit=0, retired_only=False, page=0,
465-
include_archived_projects=True):
483+
include_archived_projects=True, include_template_projects=False):
466484
"""Find entities matching the given filters.
467485
468486
:param entity_type: Required, entity type (string) to find.
@@ -489,7 +507,10 @@ def find(self, entity_type, filters, fields=None, order=None,
489507
have not been retired.
490508
491509
:param include_archived_projects: Optional, flag to include entities
492-
whose projects have been archived
510+
whose projects have been archived. Default: True
511+
512+
:param include_template_projects: Optional, flag to include entities
513+
belonging to template projects. Default: False
493514
494515
:returns: list of the dicts for each entity with the requested fields,
495516
and their id and type.
@@ -513,13 +534,19 @@ def find(self, entity_type, filters, fields=None, order=None,
513534
# So we only need to check the server version if it is False
514535
self.server_caps.ensure_include_archived_projects()
515536

537+
if include_template_projects:
538+
# This defaults to False on the server (no argument is sent)
539+
# So we only need to check the server version if it is True
540+
self.server_caps.ensure_include_template_projects()
541+
516542

517543
params = self._construct_read_parameters(entity_type,
518544
fields,
519545
filters,
520546
retired_only,
521547
order,
522-
include_archived_projects)
548+
include_archived_projects,
549+
include_template_projects)
523550

524551
if limit and limit <= self.config.records_per_page:
525552
params["paging"]["entities_per_page"] = limit
@@ -563,7 +590,8 @@ def _construct_read_parameters(self,
563590
filters,
564591
retired_only,
565592
order,
566-
include_archived_projects):
593+
include_archived_projects,
594+
include_template_projects):
567595
params = {}
568596
params["type"] = entity_type
569597
params["return_fields"] = fields or ["id"]
@@ -577,6 +605,10 @@ def _construct_read_parameters(self,
577605
# Defaults to True on the server, so only pass it if it's False
578606
params["include_archived_projects"] = False
579607

608+
if include_template_projects is True:
609+
# Defaults to False on the server, so only pass it if it's True
610+
params["include_template_projects"] = True
611+
580612
if order:
581613
sort_list = []
582614
for sort in order:
@@ -597,7 +629,8 @@ def summarize(self,
597629
summary_fields,
598630
filter_operator=None,
599631
grouping=None,
600-
include_archived_projects=True):
632+
include_archived_projects=True,
633+
include_template_projects=False):
601634
"""
602635
Return group and summary information for entity_type for summary_fields
603636
based on the given filters.
@@ -610,19 +643,24 @@ def summarize(self,
610643
if isinstance(filters, (list, tuple)):
611644
filters = _translate_filters(filters, filter_operator)
612645

613-
if not include_archived_projects:
614-
# This defaults to True on the server (no argument is sent)
615-
# So we only need to check the server version if it is False
616-
self.server_caps.ensure_include_archived_projects()
617-
618646
params = {"type": entity_type,
619647
"summaries": summary_fields,
620648
"filters": filters}
621649

622-
if include_archived_projects is False:
623-
# Defaults to True on the server, so only pass it if it's False
650+
if not include_archived_projects:
651+
# This defaults to True on the server (no argument is sent)
652+
# So we only need to check the server version if it is False
653+
self.server_caps.ensure_include_archived_projects()
654+
# Only pass it if it's False
624655
params["include_archived_projects"] = False
625656

657+
if include_template_projects:
658+
# This defaults to False on the server (no argument is sent)
659+
# So we only need to check the server version if it is True
660+
self.server_caps.ensure_include_template_projects()
661+
# Only pass it if it's True
662+
params["include_template_projects"] = True
663+
626664
if grouping != None:
627665
params['grouping'] = grouping
628666

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def test_simple_summary(self):
439439
assert(result['groups'][0]['summaries'])
440440
assert(result['summaries'])
441441

442-
def test_summary_include_archived_projects(self):
442+
def _test_summary_include_archived_projects(self):
443443
if self.sg.server_caps.version > (5, 3, 13):
444444
# archive project
445445
self.sg.update('Project', self.project['id'], {'archived':True})
@@ -1345,7 +1345,7 @@ def test_zero_is_not_none(self):
13451345
result = self.sg.find_one( 'Asset', [['id','is',self.asset['id']],[num_field, 'is_not', None]] ,[num_field] )
13461346
self.assertFalse(result == None)
13471347

1348-
def test_include_archived_projects(self):
1348+
def _test_include_archived_projects(self):
13491349
if self.sg.server_caps.version > (5, 3, 13):
13501350
# Ticket #25082
13511351
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]])

tests/test_flags.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
"""Test using the Shotgun API flags."""
2+
3+
import shotgun_api3
4+
from shotgun_api3.lib.httplib2 import Http
5+
6+
import base
7+
8+
class TestFlags(base.LiveTestBase):
9+
def setUp(self):
10+
super(TestFlags, self).setUp()
11+
# We will need the created_at field for the shot
12+
fields = self.shot.keys()[:]
13+
fields.append('created_at')
14+
self.shot = self.sg.find_one('Shot', [['id', 'is', self.shot['id']]], fields)
15+
# We will need the uuid field for our LocalStorage
16+
fields = self.local_storage.keys()[:]
17+
fields.append('uuid')
18+
self.local_storage = self.sg.find_one('LocalStorage', [['id', 'is', self.local_storage['id']]], fields)
19+
20+
def test_summary_include_archived_projects(self):
21+
"""Test summary with 'include_archived_projects'"""
22+
23+
if self.sg.server_caps.version > (5, 3, 13):
24+
# Ticket #25082 ability to hide archived projects in summary
25+
26+
# archive project
27+
self.sg.update('Project', self.project['id'], {'archived':True})
28+
29+
summaries = [{'field': 'id', 'type': 'count'}]
30+
grouping = [{'direction': 'asc', 'field': 'id', 'type': 'exact'}]
31+
filters = [['project', 'is', self.project]]
32+
33+
# setting defaults to False, so we should get result
34+
result = self.sg.summarize('Shot',
35+
filters=filters,
36+
summary_fields=summaries,
37+
grouping=grouping)
38+
self.assertEqual(result['summaries']['id'], 1)
39+
40+
# should get no result
41+
result = self.sg.summarize('Shot',
42+
filters=filters,
43+
summary_fields=summaries,
44+
grouping=grouping,
45+
include_archived_projects=False)
46+
self.assertEqual(result['summaries']['id'], 0)
47+
48+
# reset project
49+
self.sg.update('Project', self.project['id'], {'archived':False})
50+
51+
def test_summary_include_template_projects(self):
52+
"""Test summary with 'include_template_projects'"""
53+
54+
if self.sg.server_caps.version > (6, 0, 0):
55+
# Ticket #28441
56+
57+
# set as template project
58+
self.sg.update('Project', self.project['id'], {'template':True})
59+
60+
summaries = [{'field': 'id', 'type': 'count'}]
61+
grouping = [{'direction': 'asc', 'field': 'id', 'type': 'exact'}]
62+
filters = [['project', 'is', self.project]]
63+
64+
# setting defaults to False, so we should get no result
65+
result = self.sg.summarize('Shot',
66+
filters=filters,
67+
summary_fields=summaries,
68+
grouping=grouping)
69+
self.assertEqual(result['summaries']['id'], 0)
70+
71+
# should get result
72+
result = self.sg.summarize('Shot',
73+
filters=filters,
74+
summary_fields=summaries,
75+
grouping=grouping,
76+
include_template_projects=False)
77+
self.assertEqual(result['summaries']['id'], 1)
78+
79+
# reset project
80+
self.sg.update('Project', self.project['id'], {'template':False})
81+
82+
def test_include_archived_projects(self):
83+
"""Test find with 'include_archived_projects'"""
84+
85+
if self.sg.server_caps.version > (5, 3, 13):
86+
# Ticket #25082
87+
88+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]])
89+
self.assertEquals(self.shot['id'], result['id'])
90+
91+
# archive project
92+
self.sg.update('Project', self.project['id'], {'archived':True})
93+
94+
# setting defaults to True, so we should get result
95+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]])
96+
self.assertEquals(self.shot['id'], result['id'])
97+
98+
# should get no result
99+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]], include_archived_projects=False)
100+
self.assertEquals(None, result)
101+
102+
# reset project
103+
self.sg.update('Project', self.project['id'], {'archived':False})
104+
105+
def test_include_template_projects(self):
106+
"""Test find with 'include_template_projects'"""
107+
108+
if self.sg.server_caps.version > (6, 0, 0):
109+
# Ticket #28441
110+
111+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]])
112+
self.assertEquals(self.shot['id'], result['id'])
113+
114+
# set as template project
115+
self.sg.update('Project', self.project['id'], {'is_template':True})
116+
117+
# setting defaults to False, so we should not get result
118+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]])
119+
self.assertEquals(None, result)
120+
121+
# should get result
122+
result = self.sg.find_one('Shot', [['id','is',self.shot['id']]], include_template_projects=True)
123+
self.assertEquals(self.shot['id'], result['id'])
124+
125+
# reset project
126+
self.sg.update('Project', self.project['id'], {'is_template':False})
127+

0 commit comments

Comments
 (0)