Add comprehensive test scripts for thumbnail generation and xAI collections API
- Implemented `test_thumbnail_generation.py` to validate the complete flow of document thumbnail generation in EspoCRM, including document creation, file upload, webhook triggering, and preview verification. - Created `test_xai_collections_api.py` to test critical operations of the xAI Collections API, covering file uploads, collection CRUD operations, document management, and response validation. - Both scripts include detailed logging for success and error states, ensuring robust testing and easier debugging.
This commit is contained in:
110
tests/README.md
Normal file
110
tests/README.md
Normal file
@@ -0,0 +1,110 @@
|
||||
# Test Scripts
|
||||
|
||||
This directory contains test scripts for the Motia III xAI Collections integration.
|
||||
|
||||
## Test Files
|
||||
|
||||
### `test_xai_collections_api.py`
|
||||
Tests xAI Collections API authentication and basic operations.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
cd /opt/motia-iii/bitbylaw
|
||||
python tests/test_xai_collections_api.py
|
||||
```
|
||||
|
||||
**Required Environment Variables:**
|
||||
- `XAI_MANAGEMENT_API_KEY` - xAI Management API key for collection operations
|
||||
- `XAI_API_KEY` - xAI Regular API key for file operations
|
||||
|
||||
**Tests:**
|
||||
- ✅ Management API authentication
|
||||
- ✅ Regular API authentication
|
||||
- ✅ Collection listing
|
||||
- ✅ Collection creation
|
||||
- ✅ File upload
|
||||
- ✅ Collection deletion
|
||||
- ✅ Error handling
|
||||
|
||||
### `test_preview_upload.py`
|
||||
Tests preview/thumbnail upload to EspoCRM CDokumente entity.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
cd /opt/motia-iii/bitbylaw
|
||||
python tests/test_preview_upload.py
|
||||
```
|
||||
|
||||
**Required Environment Variables:**
|
||||
- `ESPOCRM_URL` - EspoCRM instance URL (default: https://crm.bitbylaw.com)
|
||||
- `ESPOCRM_API_KEY` - EspoCRM API key
|
||||
|
||||
**Tests:**
|
||||
- ✅ Preview image generation (WebP format, 600x800px)
|
||||
- ✅ Base64 Data URI encoding
|
||||
- ✅ Attachment upload via JSON POST
|
||||
- ✅ Entity update with previewId/previewName
|
||||
|
||||
**Status:** ✅ Successfully tested - Attachment ID `69a71194c7c6baebf` created
|
||||
|
||||
### `test_thumbnail_generation.py`
|
||||
Tests thumbnail generation for various document types.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
cd /opt/motia-iii/bitbylaw
|
||||
python tests/test_thumbnail_generation.py
|
||||
```
|
||||
|
||||
**Supported Formats:**
|
||||
- PDF → WebP (first page)
|
||||
- DOCX/DOC → PDF → WebP
|
||||
- Images (JPEG, PNG, etc.) → WebP resize
|
||||
|
||||
**Dependencies:**
|
||||
- `python3-pil` - PIL/Pillow for image processing
|
||||
- `poppler-utils` - PDF rendering
|
||||
- `libreoffice` - DOCX to PDF conversion
|
||||
- `pdf2image` - PDF to image conversion
|
||||
|
||||
## Running Tests
|
||||
|
||||
### All Tests
|
||||
```bash
|
||||
cd /opt/motia-iii/bitbylaw
|
||||
python -m pytest tests/ -v
|
||||
```
|
||||
|
||||
### Individual Tests
|
||||
```bash
|
||||
cd /opt/motia-iii/bitbylaw
|
||||
python tests/test_xai_collections_api.py
|
||||
python tests/test_preview_upload.py
|
||||
python tests/test_thumbnail_generation.py
|
||||
```
|
||||
|
||||
## Environment Setup
|
||||
|
||||
Create `.env` file in `/opt/motia-iii/bitbylaw/`:
|
||||
```bash
|
||||
# xAI Collections API
|
||||
XAI_MANAGEMENT_API_KEY=xai-token-xxx...
|
||||
XAI_API_KEY=xai-xxx...
|
||||
|
||||
# EspoCRM API
|
||||
ESPOCRM_URL=https://crm.bitbylaw.com
|
||||
ESPOCRM_API_KEY=xxx...
|
||||
|
||||
# Redis (for locking)
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
REDIS_DB_ADVOWARE_CACHE=1
|
||||
```
|
||||
|
||||
## Test Results
|
||||
|
||||
Last test run: Successfully validated preview upload functionality
|
||||
- Preview upload works with base64 Data URI format
|
||||
- Attachment created with ID: `69a71194c7c6baebf`
|
||||
- CDokumente entity updated with previewId/previewName
|
||||
- WebP format at 600x800px confirmed working
|
||||
Reference in New Issue
Block a user