16
16
POPULATE_PREVIEW_IMAGE = os .path .join (TEST_ASSET_DIR , "Sample View Image.png" )
17
17
POPULATE_PDF = os .path .join (TEST_ASSET_DIR , "populate_pdf.pdf" )
18
18
POPULATE_CSV = os .path .join (TEST_ASSET_DIR , "populate_csv.csv" )
19
+ POPULATE_EXCEL = os .path .join (TEST_ASSET_DIR , "populate_excel.xlsx" )
19
20
POPULATE_PERMISSIONS_XML = os .path .join (TEST_ASSET_DIR , "view_populate_permissions.xml" )
20
21
UPDATE_PERMISSIONS = os .path .join (TEST_ASSET_DIR , "view_update_permissions.xml" )
21
22
UPDATE_XML = os .path .join (TEST_ASSET_DIR , "workbook_update.xml" )
@@ -33,7 +34,7 @@ def setUp(self):
33
34
self .baseurl = self .server .views .baseurl
34
35
self .siteurl = self .server .views .siteurl
35
36
36
- def test_get (self ):
37
+ def test_get (self ) -> None :
37
38
with open (GET_XML , "rb" ) as f :
38
39
response_xml = f .read ().decode ("utf-8" )
39
40
with requests_mock .mock () as m :
@@ -62,7 +63,7 @@ def test_get(self):
62
63
self .assertEqual ("2002-06-05T08:00:59Z" , format_datetime (all_views [1 ].updated_at ))
63
64
self .assertEqual ("story" , all_views [1 ].sheet_type )
64
65
65
- def test_get_by_id (self ):
66
+ def test_get_by_id (self ) -> None :
66
67
with open (GET_XML_ID , "rb" ) as f :
67
68
response_xml = f .read ().decode ("utf-8" )
68
69
with requests_mock .mock () as m :
@@ -83,7 +84,7 @@ def test_get_by_id(self):
83
84
def test_get_by_id_missing_id (self ) -> None :
84
85
self .assertRaises (TSC .MissingRequiredFieldError , self .server .views .get_by_id , None )
85
86
86
- def test_get_with_usage (self ):
87
+ def test_get_with_usage (self ) -> None :
87
88
with open (GET_XML_USAGE , "rb" ) as f :
88
89
response_xml = f .read ().decode ("utf-8" )
89
90
with requests_mock .mock () as m :
@@ -102,7 +103,7 @@ def test_get_with_usage(self):
102
103
self .assertEqual ("2002-06-05T08:00:59Z" , format_datetime (all_views [1 ].updated_at ))
103
104
self .assertEqual ("story" , all_views [1 ].sheet_type )
104
105
105
- def test_get_with_usage_and_filter (self ):
106
+ def test_get_with_usage_and_filter (self ) -> None :
106
107
with open (GET_XML_USAGE , "rb" ) as f :
107
108
response_xml = f .read ().decode ("utf-8" )
108
109
with requests_mock .mock () as m :
@@ -122,7 +123,7 @@ def test_get_before_signin(self) -> None:
122
123
self .server ._auth_token = None
123
124
self .assertRaises (TSC .NotSignedInError , self .server .views .get )
124
125
125
- def test_populate_preview_image (self ):
126
+ def test_populate_preview_image (self ) -> None :
126
127
with open (POPULATE_PREVIEW_IMAGE , "rb" ) as f :
127
128
response = f .read ()
128
129
with requests_mock .mock () as m :
@@ -146,7 +147,7 @@ def test_populate_preview_image_missing_id(self) -> None:
146
147
single_view ._workbook_id = "3cc6cd06-89ce-4fdc-b935-5294135d6d42"
147
148
self .assertRaises (TSC .MissingRequiredFieldError , self .server .views .populate_preview_image , single_view )
148
149
149
- def test_populate_image (self ):
150
+ def test_populate_image (self ) -> None :
150
151
with open (POPULATE_PREVIEW_IMAGE , "rb" ) as f :
151
152
response = f .read ()
152
153
with requests_mock .mock () as m :
@@ -156,7 +157,7 @@ def test_populate_image(self):
156
157
self .server .views .populate_image (single_view )
157
158
self .assertEqual (response , single_view .image )
158
159
159
- def test_populate_image_with_options (self ):
160
+ def test_populate_image_with_options (self ) -> None :
160
161
with open (POPULATE_PREVIEW_IMAGE , "rb" ) as f :
161
162
response = f .read ()
162
163
with requests_mock .mock () as m :
@@ -169,7 +170,7 @@ def test_populate_image_with_options(self):
169
170
self .server .views .populate_image (single_view , req_option )
170
171
self .assertEqual (response , single_view .image )
171
172
172
- def test_populate_pdf (self ):
173
+ def test_populate_pdf (self ) -> None :
173
174
with open (POPULATE_PDF , "rb" ) as f :
174
175
response = f .read ()
175
176
with requests_mock .mock () as m :
@@ -187,7 +188,7 @@ def test_populate_pdf(self):
187
188
self .server .views .populate_pdf (single_view , req_option )
188
189
self .assertEqual (response , single_view .pdf )
189
190
190
- def test_populate_csv (self ):
191
+ def test_populate_csv (self ) -> None :
191
192
with open (POPULATE_CSV , "rb" ) as f :
192
193
response = f .read ()
193
194
with requests_mock .mock () as m :
@@ -200,7 +201,7 @@ def test_populate_csv(self):
200
201
csv_file = b"" .join (single_view .csv )
201
202
self .assertEqual (response , csv_file )
202
203
203
- def test_populate_csv_default_maxage (self ):
204
+ def test_populate_csv_default_maxage (self ) -> None :
204
205
with open (POPULATE_CSV , "rb" ) as f :
205
206
response = f .read ()
206
207
with requests_mock .mock () as m :
@@ -217,7 +218,7 @@ def test_populate_image_missing_id(self) -> None:
217
218
single_view ._id = None
218
219
self .assertRaises (TSC .MissingRequiredFieldError , self .server .views .populate_image , single_view )
219
220
220
- def test_populate_permissions (self ):
221
+ def test_populate_permissions (self ) -> None :
221
222
with open (POPULATE_PERMISSIONS_XML , "rb" ) as f :
222
223
response_xml = f .read ().decode ("utf-8" )
223
224
with requests_mock .mock () as m :
@@ -241,7 +242,7 @@ def test_populate_permissions(self):
241
242
},
242
243
)
243
244
244
- def test_add_permissions (self ):
245
+ def test_add_permissions (self ) -> None :
245
246
with open (UPDATE_PERMISSIONS , "rb" ) as f :
246
247
response_xml = f .read ().decode ("utf-8" )
247
248
@@ -265,7 +266,7 @@ def test_add_permissions(self):
265
266
self .assertEqual (permissions [1 ].grantee .id , "7c37ee24-c4b1-42b6-a154-eaeab7ee330a" )
266
267
self .assertDictEqual (permissions [1 ].capabilities , {TSC .Permission .Capability .Write : TSC .Permission .Mode .Allow })
267
268
268
- def test_update_tags (self ):
269
+ def test_update_tags (self ) -> None :
269
270
with open (ADD_TAGS_XML , "rb" ) as f :
270
271
add_tags_xml = f .read ().decode ("utf-8" )
271
272
with open (UPDATE_XML , "rb" ) as f :
@@ -283,3 +284,18 @@ def test_update_tags(self):
283
284
284
285
self .assertEqual (single_view .tags , updated_view .tags )
285
286
self .assertEqual (single_view ._initial_tags , updated_view ._initial_tags )
287
+
288
+ def test_populate_excel (self ) -> None :
289
+ self .server .version = "3.8"
290
+ self .baseurl = self .server .views .baseurl
291
+ with open (POPULATE_EXCEL , "rb" ) as f :
292
+ response = f .read ()
293
+ with requests_mock .mock () as m :
294
+ m .get (self .baseurl + "/d79634e1-6063-4ec9-95ff-50acbf609ff5/crosstab/excel?maxAge=1" , content = response )
295
+ single_view = TSC .ViewItem ()
296
+ single_view ._id = "d79634e1-6063-4ec9-95ff-50acbf609ff5"
297
+ request_option = TSC .CSVRequestOptions (maxage = 1 )
298
+ self .server .views .populate_excel (single_view , request_option )
299
+
300
+ excel_file = b"" .join (single_view .excel )
301
+ self .assertEqual (response , excel_file )
0 commit comments