function test_upload_endpoint
A test function that validates the reMarkable Cloud API file upload endpoint by attempting to upload a test JSON file and verifying the GET endpoint functionality.
/tf/active/vicechatdev/e-ink-llm/cloudtest/test_upload_endpoint.py
21 - 96
moderate
Purpose
This function serves as a diagnostic tool to test the reMarkable Cloud sync API endpoints. It authenticates with the reMarkable service, attempts to upload a small test file to the /sync/v3/files endpoint with proper headers and CRC32C checksum, and then validates that the GET endpoint is working correctly. It provides detailed console output for debugging API interactions, including response status codes, headers, and error messages.
Source Code
def test_upload_endpoint():
print("๐งช Testing File Upload Endpoint")
print("=" * 40)
# Authenticate
auth = RemarkableAuth()
user_token = auth.authenticate()
session = auth.get_authenticated_session()
if not session or not user_token:
print("โ Authentication failed")
return
# Test with a simple small file
test_content = '{"test": "data"}'
test_crc = calculate_crc32c(test_content)
print(f"๐ Test content: {test_content}")
print(f"๐ข CRC32C: {test_crc}")
print(f"๐ Token length: {len(user_token)}")
headers = {
'Authorization': f'Bearer {user_token}',
'User-Agent': 'reMarkable-desktop-win/3.11.1.1951',
'rm-filename': 'test.json',
'rm-crc32c': test_crc,
'Content-Type': 'application/octet-stream'
}
print(f"๐ค Headers:")
for key, value in headers.items():
if key == 'Authorization':
print(f" {key}: Bearer {value[7:20]}...")
else:
print(f" {key}: {value}")
try:
print(f"\n๐ Testing PUT to: https://eu.tectonic.remarkable.com/sync/v3/files")
response = session.put(
'https://eu.tectonic.remarkable.com/sync/v3/files',
headers=headers,
data=test_content
)
print(f"๐ Response status: {response.status_code}")
print(f"๐ Response headers:")
for key, value in response.headers.items():
print(f" {key}: {value}")
print(f"๐ Response body: {response.text}")
if response.status_code == 201:
print("โ
Upload successful!")
elif response.status_code == 404:
print("โ 404 Not Found - endpoint might be wrong")
elif response.status_code == 401:
print("โ 401 Unauthorized - token issue")
elif response.status_code == 403:
print("โ 403 Forbidden - permission issue")
else:
print(f"โ Unexpected status: {response.status_code}")
except Exception as e:
print(f"โ Request failed: {e}")
# Also test if we can read existing files
print(f"\n๐ Testing GET endpoint...")
try:
get_response = session.get('https://eu.tectonic.remarkable.com/sync/v3/files/root.docSchema')
print(f"๐ GET Response status: {get_response.status_code}")
if get_response.status_code == 200:
print(f"๐ GET Response size: {len(get_response.text)} bytes")
print("โ
GET endpoint works fine")
else:
print(f"โ GET also failing: {get_response.status_code}")
except Exception as e:
print(f"โ GET failed: {e}")
Return Value
This function does not return any value (implicitly returns None). It outputs diagnostic information to the console via print statements, including authentication status, request/response details, and success/failure indicators with emoji markers.
Dependencies
authjsonbase64binasciirequests
Required Imports
from auth import RemarkableAuth
import json
import base64
import binascii
Usage Example
# Ensure auth.py is available with RemarkableAuth class
# Ensure calculate_crc32c function is defined
def calculate_crc32c(content):
# Implementation of CRC32C calculation
import binascii
return format(binascii.crc32(content.encode()) & 0xffffffff, '08x')
# Run the test
test_upload_endpoint()
# Expected output:
# ๐งช Testing File Upload Endpoint
# ========================================
# ๐ Test content: {"test": "data"}
# ๐ข CRC32C: <checksum>
# ... (detailed diagnostic output)
Best Practices
- This is a test/diagnostic function and should not be used in production code
- Ensure the calculate_crc32c function is properly implemented before calling this function
- The function prints sensitive information (partial tokens) - use only in secure development environments
- The hardcoded EU region endpoint may not work for all users - consider making it configurable
- No error handling for missing calculate_crc32c function - ensure it exists before execution
- The function does not clean up test files created on the reMarkable Cloud
- Consider adding timeout parameters to HTTP requests for production use
- The test file name 'test.json' may conflict with existing files - use unique names in production
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v15 80.8% similar
-
function main_v6 79.4% similar
-
function test_remarkable_auth 77.7% similar
-
function test_quick_upload 75.9% similar
-
function main_v100 74.6% similar