1+ import os
2+ import tempfile
3+ import pytest
4+ import csv
5+ import io
6+ from src .quip_client import convert_xlsx_to_csv
7+
8+ @pytest .mark .e2e
9+ def test_connection (quip_client , test_thread_id ):
10+ """Test connection to Quip API"""
11+ thread = quip_client .get_thread (test_thread_id )
12+ assert thread is not None
13+ assert "thread" in thread
14+ print (thread ["thread" ])
15+ assert thread ["thread" ]["id" ] == test_thread_id or \
16+ ("secret_path" in thread ["thread" ] and thread ["thread" ]["secret_path" ] == test_thread_id ) or \
17+ test_thread_id in thread ["thread" ]["link" ]
18+
19+ @pytest .mark .e2e
20+ def test_is_spreadsheet (quip_client , test_thread_id ):
21+ """Test if the thread is correctly identified as a spreadsheet"""
22+ is_spreadsheet = quip_client .is_spreadsheet (test_thread_id )
23+ assert is_spreadsheet is True
24+
25+ @pytest .mark .e2e
26+ def test_export_to_xlsx (quip_client , test_thread_id ):
27+ """Test exporting to XLSX format"""
28+ with tempfile .NamedTemporaryFile (suffix = ".xlsx" , delete = False ) as temp_file :
29+ xlsx_path = temp_file .name
30+
31+ try :
32+ # Export to XLSX
33+ quip_client .export_thread_to_xlsx (test_thread_id , xlsx_path )
34+ assert os .path .exists (xlsx_path )
35+ assert os .path .getsize (xlsx_path ) > 0
36+ finally :
37+ # Clean up temporary file
38+ if os .path .exists (xlsx_path ):
39+ os .remove (xlsx_path )
40+
41+ @pytest .mark .e2e
42+ def test_convert_xlsx_to_csv (quip_client , test_thread_id , test_sheet_name ):
43+ """Test converting XLSX to CSV and validate content"""
44+ with tempfile .NamedTemporaryFile (suffix = ".xlsx" , delete = False ) as temp_file :
45+ xlsx_path = temp_file .name
46+
47+ try :
48+ # Export to XLSX
49+ quip_client .export_thread_to_xlsx (test_thread_id , xlsx_path )
50+
51+ # Convert to CSV
52+ csv_data = convert_xlsx_to_csv (xlsx_path , test_sheet_name )
53+
54+ # Validate CSV data
55+ assert csv_data is not None
56+ assert len (csv_data ) > 0
57+
58+ # Parse CSV data for more detailed validation
59+ csv_reader = csv .reader (io .StringIO (csv_data ))
60+ rows = list (csv_reader )
61+ assert len (rows ) > 0 # At least one row of data
62+
63+ # You can add more specific validations for your data
64+ finally :
65+ # Clean up temporary file
66+ if os .path .exists (xlsx_path ):
67+ os .remove (xlsx_path )
68+
69+ @pytest .mark .e2e
70+ def test_export_to_csv_fallback (quip_client , test_thread_id , test_sheet_name ):
71+ """Test exporting to CSV format using fallback method"""
72+ csv_data = quip_client .export_thread_to_csv_fallback (test_thread_id , test_sheet_name )
73+ assert csv_data is not None
74+ assert len (csv_data ) > 0
75+
76+ # Parse CSV data for more detailed validation
77+ csv_reader = csv .reader (io .StringIO (csv_data ))
78+ rows = list (csv_reader )
79+ assert len (rows ) > 0 # At least one row of data
80+
81+ @pytest .mark .e2e
82+ def test_error_handling_invalid_thread (quip_client ):
83+ """Test handling of invalid threadId"""
84+ invalid_thread_id = "invalid_thread_id_123456"
85+
86+ # Test is_spreadsheet method
87+ is_spreadsheet = quip_client .is_spreadsheet (invalid_thread_id )
88+ assert is_spreadsheet is False
89+
90+ # Test export_thread_to_xlsx method
91+ with tempfile .NamedTemporaryFile (suffix = ".xlsx" ) as temp_file :
92+ with pytest .raises (Exception ):
93+ quip_client .export_thread_to_xlsx (invalid_thread_id , temp_file .name )
94+
95+ # Test export_thread_to_csv_fallback method
96+ with pytest .raises (Exception ):
97+ quip_client .export_thread_to_csv_fallback (invalid_thread_id )
0 commit comments