Skip to content

Commit eca0f55

Browse files
committed
refactor: upload_download.py uses real XLSX file, file handle pattern, no in-memory content
1 parent b7ecd39 commit eca0f55

45 files changed

Lines changed: 427 additions & 134 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
"""
2-
Upload a file to OneDrive, then download it.
2+
Upload a file to OneDrive, then download it back.
33
4-
The most common file operation — upload and download content.
5-
6-
Requires delegated permission ``Files.ReadWrite``.
7-
8-
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
9-
https://learn.microsoft.com/en-us/graph/api/driveitem-get-content
4+
Requires delegated permission Files.ReadWrite.
105
"""
116

127
import os
13-
import tempfile
8+
from pathlib import Path
149

1510
from office365.graph_client import GraphClient
1611
from tests import test_client_id, test_password, test_tenant, test_username
1712

13+
FILE_NAME = "Financial Sample.xlsx"
14+
LOCAL_PATH = Path(__file__).parent.parent.parent.parent / "tests" / "data" / FILE_NAME
15+
1816
client = GraphClient(tenant=test_tenant).with_username_and_password(test_client_id, test_username, test_password)
1917

20-
# Upload a file to OneDrive root
21-
content = b"Hello, OneDrive!"
22-
uploaded = client.me.drive.root.upload("hello.txt", content).execute_query()
23-
print(f"Uploaded: {uploaded.name} (id: {uploaded.id})")
24-
25-
# Download it back
26-
with tempfile.TemporaryDirectory() as path:
27-
local_path = os.path.join(path, "hello.txt")
28-
with open(local_path, "wb") as f:
29-
uploaded.download(f).execute_query()
30-
print(f"Downloaded to: {local_path} (size: {os.path.getsize(local_path)} bytes)")
18+
with open(LOCAL_PATH, "rb") as f:
19+
uploaded = client.me.drive.root.upload_file(f).execute_query()
20+
21+
download_path = os.path.join(os.path.dirname(__file__), FILE_NAME)
22+
with open(download_path, "wb") as f:
23+
uploaded.download(f).execute_query()
24+
25+
print(f"Uploaded and downloaded: {FILE_NAME} ({os.path.getsize(download_path):,} bytes)")

generator/.checkpoints/SharePoint.xml.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

office365/onedrive/driveitems/uploadable_properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass, field
4-
from typing import Optional, Dict, Any
4+
from typing import Any, Dict, Optional
55

66
from office365.onedrive.driveitems.source import DriveItemSource
77
from office365.onedrive.files.system_info import FileSystemInfo
@@ -28,11 +28,11 @@ def file_size(self):
2828
return self._fileSize
2929

3030
def to_json(self, json_format: Optional[ODataJsonFormat] = None) -> Dict[str, Any]:
31-
payload = super().to_json(json_format)
31+
payload = super().to_json(json_format)
3232
payload.pop("driveItemSource", None)
3333
payload.pop("mediaSource", None)
3434
return payload
3535

3636
@property
3737
def entity_type_name(self) -> str:
38-
return None # type: ignore
38+
return None # type: ignore

office365/sharepoint/gtp/base_request_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class BaseGptRequestOptions(ClientValue):
1414
Stop: Optional[str] = None
1515
Temperature: Optional[float] = None
1616
TopP: Optional[float] = None
17+
MaxCompletionTokens: int | None = None
18+
ReasoningEffort: str | None = None
1719

1820
@property
19-
def entity_type_name(self):
21+
def entity_type_name(self) -> str:
2022
return "Microsoft.SharePoint.Internal.BaseGptRequestOptions"

office365/sharepoint/gtp/message_entry.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
from dataclasses import dataclass
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass, field
24
from typing import Optional
35

46
from office365.runtime.client_value import ClientValue
7+
from office365.runtime.client_value_collection import ClientValueCollection
8+
from office365.sharepoint.sites.manager.content_part import ContentPart
59

610

711
@dataclass
812
class MessageEntry(ClientValue):
913
"""content: str"""
1014

11-
content: Optional[str] = None
1215
Role: Optional[str] = None
16+
Content: str | None = None
17+
ContentParts: ClientValueCollection[ContentPart] = field(default_factory=lambda: ClientValueCollection(ContentPart))
1318

1419
@property
1520
def entity_type_name(self):
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from dataclasses import field
2+
13
from office365.runtime.client_value_collection import ClientValueCollection
24
from office365.sharepoint.gtp.base_request_options import BaseGptRequestOptions
35
from office365.sharepoint.gtp.message_entry import MessageEntry
@@ -6,13 +8,8 @@
68
class ChatGptRequestOptions(BaseGptRequestOptions):
79
""""""
810

9-
def __init__(self, messages=None):
10-
"""Args:
11-
messages (list[MessageEntry]):
12-
"""
13-
super().__init__()
14-
self.Messages = ClientValueCollection(MessageEntry, messages)
11+
Messages: ClientValueCollection[MessageEntry] = field(default_factory=lambda: ClientValueCollection(MessageEntry))
1512

1613
@property
17-
def entity_type_name(self): # type: ignore[override]
14+
def entity_type_name(self) -> str:
1815
return "Microsoft.SharePoint.Internal.ChatGptRequestOptions"

office365/sharepoint/gtp/responseusage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
from dataclasses import dataclass
1+
from dataclasses import dataclass, field
22
from typing import Optional
33

44
from office365.runtime.client_value import ClientValue
5+
from office365.sharepoint.internal.prompt_token_details import PromptTokenDetails
56

67

78
@dataclass
89
class GptResponseUsage(ClientValue):
910
CompletionTokens: Optional[int] = None
1011
PromptTokens: Optional[int] = None
1112
TotalTokens: Optional[int] = None
13+
PromptTokensDetails: PromptTokenDetails = field(default_factory=PromptTokenDetails)
1214

1315
@property
1416
def entity_type_name(self):
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
from office365.runtime.client_value import ClientValue
4+
5+
6+
class ImageContentPart(ClientValue):
7+
@property
8+
def entity_type_name(self) -> str:
9+
return "Microsoft.SharePoint.Internal.ImageContentPart"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import annotations
2+
3+
from office365.runtime.client_value import ClientValue
4+
5+
6+
class ImageUrl(ClientValue):
7+
Detail: str | None = None
8+
Url: str | None = None
9+
10+
@property
11+
def entity_type_name(self) -> str:
12+
return "Microsoft.SharePoint.Internal.ImageUrl"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from __future__ import annotations
2+
3+
from office365.runtime.client_value import ClientValue
4+
5+
6+
class PromptTokenDetails(ClientValue):
7+
CachedTokens: int | None = None
8+
9+
@property
10+
def entity_type_name(self) -> str:
11+
return "Microsoft.SharePoint.Internal.PromptTokenDetails"

0 commit comments

Comments
 (0)