Skip to content

Commit ba83707

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

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
@@ -167,6 +167,13 @@ def ensure_include_archived_projects(self):
167167
'label': 'include_archived_projects parameter'
168168
})
169169

170+
def ensure_include_template_projects(self):
171+
"""Wrapper for ensure_support"""
172+
self._ensure_support({
173+
'version': (6, 0, 0),
174+
'label': 'include_template_projects parameter'
175+
})
176+
170177

171178
def __str__(self):
172179
return "ServerCapabilities: host %s, version %s, is_dev %s"\
@@ -474,7 +481,8 @@ def info(self):
474481
return self._call_rpc("info", None, include_auth_params=False)
475482

476483
def find_one(self, entity_type, filters, fields=None, order=None,
477-
filter_operator=None, retired_only=False, include_archived_projects=True):
484+
filter_operator=None, retired_only=False,
485+
include_archived_projects=True, include_template_projects=False):
478486
"""Calls the find() method and returns the first result, or None.
479487
480488
:param entity_type: Required, entity type (string) to find.
@@ -493,24 +501,34 @@ def find_one(self, entity_type, filters, fields=None, order=None,
493501
:param limit: Optional, number of entities to return per page.
494502
Defaults to 0 which returns all entities that match.
495503
496-
:param page: Optional, page of results to return. By default all
497-
results are returned. Use together with limit.
498-
499504
:param retired_only: Optional, flag to return only entities that have
500505
been retried. Defaults to False which returns only entities which
501506
have not been retired.
507+
508+
:param page: Optional, page of results to return. By default all
509+
results are returned. Use together with limit.
510+
511+
:param include_archived_projects: Optional, flag to include entities
512+
whose projects have been archived. Default: True
513+
514+
:param include_template_projects: Optional, flag to include entities
515+
belonging to template projects. Default: False
516+
517+
:returns: Result
502518
"""
503519

504520
results = self.find(entity_type, filters, fields, order,
505-
filter_operator, 1, retired_only, include_archived_projects=include_archived_projects)
521+
filter_operator, 1, retired_only,
522+
include_archived_projects=include_archived_projects,
523+
include_template_projects=include_template_projects)
506524

507525
if results:
508526
return results[0]
509527
return None
510528

511529
def find(self, entity_type, filters, fields=None, order=None,
512530
filter_operator=None, limit=0, retired_only=False, page=0,
513-
include_archived_projects=True):
531+
include_archived_projects=True, include_template_projects=False):
514532
"""Find entities matching the given filters.
515533
516534
:param entity_type: Required, entity type (string) to find.
@@ -537,7 +555,10 @@ def find(self, entity_type, filters, fields=None, order=None,
537555
have not been retired.
538556
539557
:param include_archived_projects: Optional, flag to include entities
540-
whose projects have been archived
558+
whose projects have been archived. Default: True
559+
560+
:param include_template_projects: Optional, flag to include entities
561+
belonging to template projects. Default: False
541562
542563
:returns: list of the dicts for each entity with the requested fields,
543564
and their id and type.
@@ -561,13 +582,19 @@ def find(self, entity_type, filters, fields=None, order=None,
561582
# So we only need to check the server version if it is False
562583
self.server_caps.ensure_include_archived_projects()
563584

585+
if include_template_projects:
586+
# This defaults to False on the server (no argument is sent)
587+
# So we only need to check the server version if it is True
588+
self.server_caps.ensure_include_template_projects()
589+
564590

565591
params = self._construct_read_parameters(entity_type,
566592
fields,
567593
filters,
568594
retired_only,
569595
order,
570-
include_archived_projects)
596+
include_archived_projects,
597+
include_template_projects)
571598

572599
if limit and limit <= self.config.records_per_page:
573600
params["paging"]["entities_per_page"] = limit
@@ -611,7 +638,8 @@ def _construct_read_parameters(self,
611638
filters,
612639
retired_only,
613640
order,
614-
include_archived_projects):
641+
include_archived_projects,
642+
include_template_projects):
615643
params = {}
616644
params["type"] = entity_type
617645
params["return_fields"] = fields or ["id"]
@@ -625,6 +653,10 @@ def _construct_read_parameters(self,
625653
# Defaults to True on the server, so only pass it if it's False
626654
params["include_archived_projects"] = False
627655

656+
if include_template_projects is True:
657+
# Defaults to False on the server, so only pass it if it's True
658+
params["include_template_projects"] = True
659+
628660
if order:
629661
sort_list = []
630662
for sort in order:
@@ -645,7 +677,8 @@ def summarize(self,
645677
summary_fields,
646678
filter_operator=None,
647679
grouping=None,
648-
include_archived_projects=True):
680+
include_archived_projects=True,
681+
include_template_projects=False):
649682
"""
650683
Return group and summary information for entity_type for summary_fields
651684
based on the given filters.
@@ -658,19 +691,24 @@ def summarize(self,
658691
if isinstance(filters, (list, tuple)):
659692
filters = _translate_filters(filters, filter_operator)
660693

661-
if not include_archived_projects:
662-
# This defaults to True on the server (no argument is sent)
663-
# So we only need to check the server version if it is False
664-
self.server_caps.ensure_include_archived_projects()
665-
666694
params = {"type": entity_type,
667695
"summaries": summary_fields,
668696
"filters": filters}
669697

670-
if include_archived_projects is False:
671-
# Defaults to True on the server, so only pass it if it's False
698+
if not include_archived_projects:
699+
# This defaults to True on the server (no argument is sent)
700+
# So we only need to check the server version if it is False
701+
self.server_caps.ensure_include_archived_projects()
702+
# Only pass it if it's False
672703
params["include_archived_projects"] = False
673704

705+
if include_template_projects:
706+
# This defaults to False on the server (no argument is sent)
707+
# So we only need to check the server version if it is True
708+
self.server_caps.ensure_include_template_projects()
709+
# Only pass it if it's True
710+
params["include_template_projects"] = True
711+
674712
if grouping != None:
675713
params['grouping'] = grouping
676714

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)