@@ -76,6 +76,17 @@ def test_filter_equals(self):
7676 self .assertEqual ('RESTAPISample' , matching_workbooks [0 ].name )
7777 self .assertEqual ('RESTAPISample' , matching_workbooks [1 ].name )
7878
79+ def test_filter_equals_shorthand (self ):
80+ with open (FILTER_EQUALS , 'rb' ) as f :
81+ response_xml = f .read ().decode ('utf-8' )
82+ with requests_mock .mock () as m :
83+ m .get (self .baseurl + '/workbooks?filter=name:eq:RESTAPISample' , text = response_xml )
84+ matching_workbooks = self .server .workbooks .filter (name = 'RESTAPISample' ).order_by ("name" )
85+
86+ self .assertEqual (2 , matching_workbooks .total_available )
87+ self .assertEqual ('RESTAPISample' , matching_workbooks [0 ].name )
88+ self .assertEqual ('RESTAPISample' , matching_workbooks [1 ].name )
89+
7990 def test_filter_tags_in (self ):
8091 with open (FILTER_TAGS_IN , 'rb' ) as f :
8192 response_xml = f .read ().decode ('utf-8' )
@@ -91,6 +102,22 @@ def test_filter_tags_in(self):
91102 self .assertEqual (set (['safari' ]), matching_workbooks [1 ].tags )
92103 self .assertEqual (set (['sample' ]), matching_workbooks [2 ].tags )
93104
105+ def test_filter_tags_in_shorthand (self ):
106+ with open (FILTER_TAGS_IN , 'rb' ) as f :
107+ response_xml = f .read ().decode ('utf-8' )
108+ with requests_mock .mock () as m :
109+ m .get (self .baseurl + '/workbooks?filter=tags:in:[sample,safari,weather]' , text = response_xml )
110+ matching_workbooks = self .server .workbooks .filter (tags__in = ['sample' , 'safari' , 'weather' ])
111+
112+ self .assertEqual (3 , matching_workbooks .total_available )
113+ self .assertEqual (set (['weather' ]), matching_workbooks [0 ].tags )
114+ self .assertEqual (set (['safari' ]), matching_workbooks [1 ].tags )
115+ self .assertEqual (set (['sample' ]), matching_workbooks [2 ].tags )
116+
117+ def test_invalid_shorthand_option (self ):
118+ with self .assertRaises (ValueError ):
119+ self .server .workbooks .filter (nonexistant__in = ['sample' , 'safari' ])
120+
94121 def test_multiple_filter_options (self ):
95122 with open (FILTER_MULTIPLE , 'rb' ) as f :
96123 response_xml = f .read ().decode ('utf-8' )
@@ -107,3 +134,19 @@ def test_multiple_filter_options(self):
107134 for _ in range (100 ):
108135 matching_workbooks , pagination_item = self .server .workbooks .get (req_option )
109136 self .assertEqual (3 , pagination_item .total_available )
137+
138+ def test_multiple_filter_options_shorthand (self ):
139+ with open (FILTER_MULTIPLE , 'rb' ) as f :
140+ response_xml = f .read ().decode ('utf-8' )
141+ # To ensure that this is deterministic, run this a few times
142+ with requests_mock .mock () as m :
143+ # Sometimes pep8 requires you to do things you might not otherwise do
144+ url = '' .join ((self .baseurl , '/workbooks?pageNumber=1&pageSize=100&' ,
145+ 'filter=name:eq:foo,tags:in:[sample,safari,weather]' ))
146+ m .get (url , text = response_xml )
147+
148+ for _ in range (100 ):
149+ matching_workbooks = self .server .workbooks .filter (
150+ tags__in = ['sample' , 'safari' , 'weather' ], name = 'foo'
151+ )
152+ self .assertEqual (3 , matching_workbooks .total_available )
0 commit comments