Skip to content

Commit a44bd79

Browse files
Add some code coverage for SPO connector to be able to backport/merge stuff again (#3795)
Subj. (cherry picked from commit 530e7c0) # Conflicts: # NOTICE.txt
1 parent 3fb9dd0 commit a44bd79

File tree

2 files changed

+85
-18
lines changed

2 files changed

+85
-18
lines changed

NOTICE.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
MarkupSafe
3535
3.0.3
36-
UNKNOWN
36+
BSD-3-Clause
3737
Copyright 2010 Pallets
3838

3939
Redistribution and use in source and binary forms, with or without
@@ -92,7 +92,7 @@ SOFTWARE.
9292

9393
PyMySQL
9494
1.1.2
95-
UNKNOWN
95+
MIT
9696
Copyright (c) 2010, 2013 PyMySQL contributors
9797

9898
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1603,7 +1603,7 @@ Apache License
16031603

16041604
anyio
16051605
4.11.0
1606-
UNKNOWN
1606+
MIT
16071607
The MIT License (MIT)
16081608

16091609
Copyright (c) 2018 Alex Grönholm
@@ -1855,7 +1855,7 @@ Copyright (C) 2016-present the asyncpg authors and contributors.
18551855

18561856
attrs
18571857
25.4.0
1858-
UNKNOWN
1858+
MIT
18591859
The MIT License (MIT)
18601860

18611861
Copyright (c) 2015 Hynek Schlawack and the attrs contributors
@@ -2164,7 +2164,7 @@ Apache Software License
21642164

21652165
beautifulsoup4
21662166
4.12.2
2167-
MIT License
2167+
MIT
21682168
Beautiful Soup is made available under the MIT license:
21692169

21702170
Copyright (c) Leonard Richardson
@@ -2564,7 +2564,7 @@ Apache Software License
25642564

25652565
bracex
25662566
2.6
2567-
MIT License
2567+
MIT
25682568
MIT License
25692569

25702570
Copyright (c) 2018 - 2025 Isaac Muse
@@ -3341,7 +3341,7 @@ SOFTWARE
33413341

33423342
elasticsearch
33433343
8.18.0
3344-
Apache Software License
3344+
Apache-2.0
33453345

33463346
Apache License
33473347
Version 2.0, January 2004
@@ -5032,7 +5032,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50325032

50335033
httpcore
50345034
1.0.9
5035-
BSD License
5035+
BSD-3-Clause
50365036
Copyright © 2020, [Encode OSS Ltd](https://www.encode.io/).
50375037
All rights reserved.
50385038

@@ -5064,7 +5064,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50645064

50655065
httpx
50665066
0.27.0
5067-
BSD License
5067+
BSD-3-Clause
50685068
Copyright © 2019, [Encode OSS Ltd](https://www.encode.io/).
50695069
All rights reserved.
50705070

@@ -5101,7 +5101,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51015101

51025102
idna
51035103
3.11
5104-
UNKNOWN
5104+
BSD-3-Clause
51055105
BSD 3-Clause License
51065106

51075107
Copyright (c) 2013-2025, Kim Davies and contributors.
@@ -6725,7 +6725,7 @@ Apache Software License
67256725

67266726
pyspnego
67276727
0.12.0
6728-
UNKNOWN
6728+
MIT
67296729
MIT License
67306730

67316731
Copyright (c) 2020 Jordan Borean, Red Hat
@@ -7433,7 +7433,7 @@ made under the terms of *both* these licenses.
74337433

74347434
soupsieve
74357435
2.8
7436-
MIT License
7436+
MIT
74377437
MIT License
74387438

74397439
Copyright (c) 2018 - 2025 Isaac Muse <[email protected]>
@@ -7781,7 +7781,7 @@ DEALINGS IN THE SOFTWARE.
77817781

77827782
typing_extensions
77837783
4.15.0
7784-
UNKNOWN
7784+
PSF-2.0
77857785
A. HISTORY OF THE SOFTWARE
77867786
==========================
77877787

@@ -8122,7 +8122,7 @@ made under the terms of *both* these licenses.
81228122

81238123
urllib3
81248124
2.5.0
8125-
UNKNOWN
8125+
MIT
81268126
MIT License
81278127

81288128
Copyright (c) 2008-2020 Andrey Petrov and contributors.

tests/sources/test_sharepoint_online.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
_prefix_user,
5050
_prefix_user_id,
5151
)
52-
from connectors.utils import iso_utc
52+
from connectors.utils import ISO_ZULU_TIMESTAMP_FORMAT, iso_utc
5353
from tests.commons import AsyncIterator
5454
from tests.sources.support import create_source
5555

@@ -234,6 +234,8 @@ async def create_spo_source(
234234
tenant_name="test",
235235
client_id="2",
236236
secret_value="3",
237+
certificate=None,
238+
private_key=None,
237239
auth_method="secret",
238240
site_collections=WILDCARD,
239241
use_document_level_security=False,
@@ -248,6 +250,8 @@ async def create_spo_source(
248250
tenant_id=tenant_id,
249251
client_id=client_id,
250252
secret_value=secret_value,
253+
certificate=certificate,
254+
private_key=private_key,
251255
tenant_name=tenant_name,
252256
site_collections=site_collections,
253257
use_document_level_security=use_document_level_security,
@@ -2991,16 +2995,64 @@ async def test_download_function_with_filtering_rule(self):
29912995
async with create_spo_source() as source:
29922996
max_drive_item_age = 15
29932997
drive_item = {
2994-
"name": "test",
2995-
"lastModifiedDateTime": str(
2998+
"name": "test.txt",
2999+
"@microsoft.graph.downloadUrl": "http://localhost/filename",
3000+
"lastModifiedDateTime": (
29963001
datetime.utcnow() - timedelta(days=max_drive_item_age + 1)
2997-
),
3002+
).strftime(ISO_ZULU_TIMESTAMP_FORMAT),
3003+
}
3004+
3005+
download_result = source.download_function(drive_item, max_drive_item_age)
3006+
3007+
assert download_result is None
3008+
3009+
@pytest.mark.asyncio
3010+
async def test_download_function_for_file_with_no_lastModifiedDatetTime(self):
3011+
async with create_spo_source() as source:
3012+
max_drive_item_age = 15
3013+
drive_item = {
3014+
"name": "test.txt",
3015+
"@microsoft.graph.downloadUrl": "http://localhost/filename",
29983016
}
29993017

30003018
download_result = source.download_function(drive_item, max_drive_item_age)
30013019

30023020
assert download_result is None
30033021

3022+
@pytest.mark.asyncio
3023+
async def test_download_function_for_too_large_file(self):
3024+
async with create_spo_source() as source:
3025+
max_drive_item_age = 15
3026+
drive_item = {
3027+
"name": "test.txt",
3028+
"@microsoft.graph.downloadUrl": "http://localhost/filename",
3029+
"size": 5 * 1024 * 1024 * 1024,
3030+
"lastModifiedDateTime": (
3031+
datetime.now(timezone.utc) - timedelta(days=max_drive_item_age - 5)
3032+
).strftime(ISO_ZULU_TIMESTAMP_FORMAT),
3033+
}
3034+
3035+
download_result = source.download_function(drive_item, max_drive_item_age)
3036+
3037+
assert download_result is None
3038+
3039+
@pytest.mark.asyncio
3040+
async def test_download_function_for_recently_changed_file(self):
3041+
async with create_spo_source() as source:
3042+
max_drive_item_age = 15
3043+
drive_item = {
3044+
"name": "test.txt",
3045+
"@microsoft.graph.downloadUrl": "http://localhost/filename",
3046+
"size": 5000,
3047+
"lastModifiedDateTime": (
3048+
datetime.now(timezone.utc) - timedelta(days=max_drive_item_age - 5)
3049+
).strftime(ISO_ZULU_TIMESTAMP_FORMAT),
3050+
}
3051+
3052+
download_result = source.download_function(drive_item, max_drive_item_age)
3053+
3054+
assert download_result is not None
3055+
30043056
def test_get_default_configuration(self):
30053057
config = SharepointOnlineDataSource.get_default_configuration()
30063058

@@ -3053,6 +3105,21 @@ async def test_validate_config(self, patch_sharepoint_client):
30533105
patch_sharepoint_client.rest_api_token.get.assert_awaited()
30543106
patch_sharepoint_client.site_collections.assert_not_called()
30553107

3108+
@pytest.mark.asyncio
3109+
async def test_correct_tokens_are_set_when_certificates_are_used(self):
3110+
private_key = "opens_all_locks"
3111+
certificate = "its_certified"
3112+
async with create_spo_source(
3113+
auth_method="certificate",
3114+
secret_value=None,
3115+
private_key=private_key,
3116+
certificate=certificate,
3117+
) as source:
3118+
client = source.client
3119+
3120+
assert isinstance(client.graph_api_token, EntraAPIToken)
3121+
assert isinstance(client.rest_api_token, EntraAPIToken)
3122+
30563123
@pytest.mark.asyncio
30573124
async def test_validate_config_when_invalid_tenant(self, patch_sharepoint_client):
30583125
invalid_tenant_name = "wat"

0 commit comments

Comments
 (0)