-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_share.py
More file actions
635 lines (530 loc) · 24.7 KB
/
test_share.py
File metadata and controls
635 lines (530 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
"""
test_share.py
Tests that the Share class methods work as expected.
Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti.
Emails: rasmus.oscar.welander@cern.ch, diogo.castro@cern.ch, giuseppe.lopresti@cern.ch
Last updated: 28/08/2024
"""
import pytest
from unittest.mock import Mock, patch
import cs3.sharing.collaboration.v1beta1.resources_pb2 as cs3scr
import cs3.sharing.link.v1beta1.link_api_pb2 as cs3slapi
import cs3.storage.provider.v1beta1.resources_pb2 as cs3spr
import cs3.rpc.v1beta1.code_pb2 as cs3code
from cs3client.exceptions import (
AuthenticationException,
NotFoundException,
UnknownException,
FileLockedException,
AlreadyExistsException,
)
from .fixtures import ( # noqa: F401 (they are used, the framework is not detecting it)
mock_config,
mock_logger,
mock_gateway,
share_instance,
mock_status_code_handler,
)
# Test cases for the Share class.
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(cs3code.CODE_FAILED_PRECONDITION, "File is locked", FileLockedException, None),
(cs3code.CODE_ABORTED, "File is locked", FileLockedException, None),
(cs3code.CODE_ALREADY_EXISTS, "Share already exists", AlreadyExistsException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_create_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
opaque_id = "opaque_id"
idp = "idp"
role = "VIEWER"
resource_info = cs3spr.ResourceInfo(id=cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id"))
grantee_type = "USER"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = status_message
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "CreateShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.create_share(
auth_token,
resource_info=resource_info,
opaque_id=opaque_id,
idp=idp,
role=role,
grantee_type=grantee_type
)
else:
result = share_instance.create_share(
auth_token,
resource_info=resource_info,
opaque_id=opaque_id,
idp=idp,
role=role,
grantee_type=grantee_type
)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, (["share1", "share2"], "token")),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_list_existing_shares(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share_infos = expected_result[0]
mock_response.next_page_token = expected_result[1]
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "ListExistingShares", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.list_existing_shares(auth_token)
else:
result = share_instance.list_existing_shares(auth_token)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_get_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
share_id = "share_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "GetShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.get_share(auth_token, share_id)
else:
result = share_instance.get_share(auth_token, share_id)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_remove_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
share_id = "share_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "RemoveShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.remove_share(auth_token, share_id)
else:
result = share_instance.remove_share(auth_token, share_id)
assert result is None
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(cs3code.CODE_ALREADY_EXISTS, "Share already exists", AlreadyExistsException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_update_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
opaque_id = "share_id"
role = "VIEWER"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "UpdateShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.update_share(auth_token, role=role, opaque_id=opaque_id)
else:
result = share_instance.update_share(auth_token, role=role, opaque_id=opaque_id)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, (["share1", "share2"], "token")),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_list_existing_received_shares(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share_infos = expected_result[0]
mock_response.next_page_token = expected_result[1]
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "ListExistingReceivedShares", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.list_received_existing_shares(auth_token)
else:
result = share_instance.list_received_existing_shares(auth_token)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_get_received_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
share_id = "share_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "GetReceivedShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.get_received_share(auth_token, share_id)
else:
result = share_instance.get_received_share(auth_token, share_id)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_update_received_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
resource_id = cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id")
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "UpdateReceivedShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.update_received_share(auth_token, opaque_id=resource_id.opaque_id, state="SHARE_STATE_ACCEPTED")
else:
result = share_instance.update_received_share(auth_token, opaque_id=resource_id.opaque_id, state="SHARE_STATE_ACCEPTED")
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(cs3code.CODE_FAILED_PRECONDITION, "File is locked", FileLockedException, None),
(cs3code.CODE_ABORTED, "File is locked", FileLockedException, None),
(cs3code.CODE_ALREADY_EXISTS, "Share already exists", AlreadyExistsException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_create_public_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
resource_info = cs3spr.ResourceInfo(id=cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id"))
role = "EDITOR"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "CreatePublicShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.create_public_share(auth_token, resource_info=resource_info, role=role)
else:
result = share_instance.create_public_share(auth_token, resource_info=resource_info, role=role)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, (["share1", "share2"], "token")),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def list_existing_public_shares(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share_infos = expected_result[0]
mock_response.next_page_token = expected_result[1]
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "ListExistingPublicShares", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.list_existing_public_shares(auth_token)
else:
result = share_instance.list_existing_public_shares(auth_token)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_get_public_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
share_id = "share_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "GetPublicShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.get_public_share(auth_token, share_id)
else:
result = share_instance.get_public_share(auth_token, share_id)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_update_public_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
type = "TYPE_PERMISSIONS"
role = "EDITOR"
opqaue_id = "opaque_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "UpdatePublicShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.update_public_share(auth_token, type=type, role=role, opaque_id=opqaue_id)
else:
result = share_instance.update_public_share(auth_token, type=type, role=role, opaque_id=opqaue_id)
assert result == expected_result
@pytest.mark.parametrize(
"status_code, status_message, expected_exception, expected_result",
[
(cs3code.CODE_OK, "share", None, "share"),
(cs3code.CODE_NOT_FOUND, "Resource not found", NotFoundException, None),
(cs3code.CODE_UNAUTHENTICATED, "Authentication failed", AuthenticationException, None),
(cs3code.CODE_FAILED_PRECONDITION, "File is locked", FileLockedException, None),
(cs3code.CODE_ABORTED, "File is locked", FileLockedException, None),
(cs3code.CODE_ALREADY_EXISTS, "Share already exists", AlreadyExistsException, None),
(-1, "Internal error", UnknownException, None),
],
)
def test_remove_public_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
share_id = "share_id"
mock_response = Mock()
mock_response.status.code = status_code
mock_response.status.message = status_message
if status_code == cs3code.CODE_OK:
mock_response.share = expected_result
auth_token = ('x-access-token', "some_token")
with patch.object(share_instance._gateway, "RemovePublicShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.remove_public_share(auth_token, share_id)
else:
result = share_instance.remove_public_share(auth_token, share_id)
assert result is None
def test_create_public_share_filter_resource_id(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_RESOURCE_ID"
resource_id = cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id")
# Call the method
result = share_instance.create_public_share_filter(filter_type=filter_type, resource_id=resource_id)
# Assertions
assert result.type == cs3slapi.ListPublicSharesRequest.Filter.Type.TYPE_RESOURCE_ID
assert result.resource_id == resource_id
def test_create_public_share_filter_owner(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_OWNER"
owner_idp = "owner_idp"
owner_opaque_id = "owner_opaque_id"
# Call the method
result = share_instance.create_public_share_filter(
filter_type=filter_type, owner_idp=owner_idp, owner_opaque_id=owner_opaque_id
)
# Assertions
assert result.type == cs3slapi.ListPublicSharesRequest.Filter.Type.TYPE_OWNER
assert result.owner.idp == owner_idp
assert result.owner.opaque_id == owner_opaque_id
def test_create_public_share_filter_creator(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_CREATOR"
creator_idp = "creator_idp"
creator_opaque_id = "creator_opaque_id"
# Call the method
result = share_instance.create_public_share_filter(
filter_type=filter_type, creator_idp=creator_idp, creator_opaque_id=creator_opaque_id
)
# Assertions
assert result.type == cs3slapi.ListPublicSharesRequest.Filter.Type.TYPE_CREATOR
assert result.creator.idp == creator_idp
assert result.creator.opaque_id == creator_opaque_id
def test_create_public_share_filter_invalid_resource_id(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_RESOURCE_ID"
# This should raise ValueError due to missing resource_id
with pytest.raises(ValueError):
share_instance.create_public_share_filter(filter_type=filter_type)
def test_create_public_share_filter_invalid_owner(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_OWNER"
# This should raise ValueError due to missing owner_idp and owner_opaque_id
with pytest.raises(ValueError):
share_instance.create_public_share_filter(filter_type=filter_type)
def test_create_public_share_filter_invalid_creator(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_CREATOR"
# This should raise ValueError due to missing creator_idp and creator_opaque_id
with pytest.raises(ValueError):
share_instance.create_public_share_filter(filter_type=filter_type)
def test_create_public_share_filter_invalid_type(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "INVALID_TYPE"
# This should raise ValueError due to invalid filter_type
with pytest.raises(ValueError):
share_instance.create_public_share_filter(filter_type=filter_type)
# Test when filtering by resource ID
def test_create_share_filter_resource_id(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_RESOURCE_ID"
resource_id = cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id")
# Call the method
result = share_instance.create_share_filter(filter_type=filter_type, resource_id=resource_id)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_RESOURCE_ID
assert result.resource_id == resource_id
# Test when filtering by owner
def test_create_share_filter_owner(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_OWNER"
owner_idp = "example_idp"
owner_opaque_id = "owner_opaque_id"
# Call the method
result = share_instance.create_share_filter(
filter_type=filter_type, owner_idp=owner_idp, owner_opaque_id=owner_opaque_id
)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_OWNER
assert result.owner.idp == owner_idp
assert result.owner.opaque_id == owner_opaque_id
# Test when filtering by creator
def test_create_share_filter_creator(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_CREATOR"
creator_idp = "creator_idp"
creator_opaque_id = "creator_opaque_id"
# Call the method
result = share_instance.create_share_filter(
filter_type=filter_type, creator_idp=creator_idp, creator_opaque_id=creator_opaque_id
)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_CREATOR
assert result.creator.idp == creator_idp
assert result.creator.opaque_id == creator_opaque_id
# Test when filtering by grantee type
def test_create_share_filter_grantee_type(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_GRANTEE_TYPE"
grantee_type = cs3spr.GranteeType.GRANTEE_TYPE_USER
# Call the method
result = share_instance.create_share_filter(filter_type=filter_type, grantee_type=grantee_type)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_GRANTEE_TYPE
assert result.grantee_type == grantee_type
# Test when filtering by space ID
def test_create_share_filter_space_id(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_SPACE_ID"
space_id = "space_id"
# Call the method
result = share_instance.create_share_filter(filter_type=filter_type, space_id=space_id)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_SPACE_ID
assert result.space_id == space_id
# Test when filtering by share state
def test_create_share_filter_state(share_instance): # noqa: F811 (not a redefinition)
# Setup inputs
filter_type = "TYPE_STATE"
share_state = "SHARE_STATE_ACCEPTED" # Example state string
# Call the method
result = share_instance.create_share_filter(filter_type=filter_type, share_state=share_state)
# Assertions
assert result.type == cs3scr.Filter.Type.TYPE_STATE
assert result.state == cs3scr.ShareState.Value(share_state)
# Test for invalid filter type or missing parameters
def test_create_share_filter_invalid(share_instance): # noqa: F811 (not a redefinition)
# Setup invalid inputs
filter_type = "INVALID_TYPE"
# Call the method and check for ValueError
with pytest.raises(ValueError):
share_instance.create_share_filter(filter_type=filter_type)