Skip to content

Commit e092d83

Browse files
committed
For #28441: added support + tests for 'include_template_projects' flag
1 parent c305fc2 commit e092d83

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
@@ -171,6 +171,13 @@ def ensure_include_archived_projects(self):
171171
'label': 'include_archived_projects parameter'
172172
})
173173

174+
def ensure_include_template_projects(self):
175+
"""Wrapper for ensure_support"""
176+
self._ensure_support({
177+
'version': (6, 0, 0),
178+
'label': 'include_template_projects parameter'
179+
})
180+
174181
def ensure_per_project_customization(self):
175182
"""Wrapper for ensure_support"""
176183
return self._ensure_support({
@@ -485,7 +492,8 @@ def info(self):
485492
return self._call_rpc("info", None, include_auth_params=False)
486493

487494
def find_one(self, entity_type, filters, fields=None, order=None,
488-
filter_operator=None, retired_only=False, include_archived_projects=True):
495+
filter_operator=None, retired_only=False,
496+
include_archived_projects=True, include_template_projects=False):
489497
"""Calls the find() method and returns the first result, or None.
490498
491499
:param entity_type: Required, entity type (string) to find.
@@ -504,24 +512,34 @@ def find_one(self, entity_type, filters, fields=None, order=None,
504512
:param limit: Optional, number of entities to return per page.
505513
Defaults to 0 which returns all entities that match.
506514
507-
:param page: Optional, page of results to return. By default all
508-
results are returned. Use together with limit.
509-
510515
:param retired_only: Optional, flag to return only entities that have
511516
been retried. Defaults to False which returns only entities which
512517
have not been retired.
518+
519+
:param page: Optional, page of results to return. By default all
520+
results are returned. Use together with limit.
521+
522+
:param include_archived_projects: Optional, flag to include entities
523+
whose projects have been archived. Default: True
524+
525+
:param include_template_projects: Optional, flag to include entities
526+
belonging to template projects. Default: False
527+
528+
:returns: Result
513529
"""
514530

515531
results = self.find(entity_type, filters, fields, order,
516-
filter_operator, 1, retired_only, include_archived_projects=include_archived_projects)
532+
filter_operator, 1, retired_only,
533+
include_archived_projects=include_archived_projects,
534+
include_template_projects=include_template_projects)
517535

518536
if results:
519537
return results[0]
520538
return None
521539

522540
def find(self, entity_type, filters, fields=None, order=None,
523541
filter_operator=None, limit=0, retired_only=False, page=0,
524-
include_archived_projects=True):
542+
include_archived_projects=True, include_template_projects=False):
525543
"""Find entities matching the given filters.
526544
527545
:param entity_type: Required, entity type (string) to find.
@@ -548,7 +566,10 @@ def find(self, entity_type, filters, fields=None, order=None,
548566
have not been retired.
549567
550568
:param include_archived_projects: Optional, flag to include entities
551-
whose projects have been archived
569+
whose projects have been archived. Default: True
570+
571+
:param include_template_projects: Optional, flag to include entities
572+
belonging to template projects. Default: False
552573
553574
:returns: list of the dicts for each entity with the requested fields,
554575
and their id and type.
@@ -572,13 +593,19 @@ def find(self, entity_type, filters, fields=None, order=None,
572593
# So we only need to check the server version if it is False
573594
self.server_caps.ensure_include_archived_projects()
574595

596+
if include_template_projects:
597+
# This defaults to False on the server (no argument is sent)
598+
# So we only need to check the server version if it is True
599+
self.server_caps.ensure_include_template_projects()
600+
575601

576602
params = self._construct_read_parameters(entity_type,
577603
fields,
578604
filters,
579605
retired_only,
580606
order,
581-
include_archived_projects)
607+
include_archived_projects,
608+
include_template_projects)
582609

583610
if limit and limit <= self.config.records_per_page:
584611
params["paging"]["entities_per_page"] = limit
@@ -622,7 +649,8 @@ def _construct_read_parameters(self,
622649
filters,
623650
retired_only,
624651
order,
625-
include_archived_projects):
652+
include_archived_projects,
653+
include_template_projects):
626654
params = {}
627655
params["type"] = entity_type
628656
params["return_fields"] = fields or ["id"]
@@ -636,6 +664,10 @@ def _construct_read_parameters(self,
636664
# Defaults to True on the server, so only pass it if it's False
637665
params["include_archived_projects"] = False
638666

667+
if include_template_projects is True:
668+
# Defaults to False on the server, so only pass it if it's True
669+
params["include_template_projects"] = True
670+
639671
if order:
640672
sort_list = []
641673
for sort in order:
@@ -665,7 +697,8 @@ def summarize(self,
665697
summary_fields,
666698
filter_operator=None,
667699
grouping=None,
668-
include_archived_projects=True):
700+
include_archived_projects=True,
701+
include_template_projects=False):
669702
"""
670703
Return group and summary information for entity_type for summary_fields
671704
based on the given filters.
@@ -678,19 +711,24 @@ def summarize(self,
678711
if isinstance(filters, (list, tuple)):
679712
filters = _translate_filters(filters, filter_operator)
680713

681-
if not include_archived_projects:
682-
# This defaults to True on the server (no argument is sent)
683-
# So we only need to check the server version if it is False
684-
self.server_caps.ensure_include_archived_projects()
685-
686714
params = {"type": entity_type,
687715
"summaries": summary_fields,
688716
"filters": filters}
689717

690-
if include_archived_projects is False:
691-
# Defaults to True on the server, so only pass it if it's False
718+
if not include_archived_projects:
719+
# This defaults to True on the server (no argument is sent)
720+
# So we only need to check the server version if it is False
721+
self.server_caps.ensure_include_archived_projects()
722+
# Only pass it if it's False
692723
params["include_archived_projects"] = False
693724

725+
if include_template_projects:
726+
# This defaults to False on the server (no argument is sent)
727+
# So we only need to check the server version if it is True
728+
self.server_caps.ensure_include_template_projects()
729+
# Only pass it if it's True
730+
params["include_template_projects"] = True
731+
694732
if grouping != None:
695733
params['grouping'] = grouping
696734

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)