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
5353from tests .commons import AsyncIterator
5454from 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