@@ -125,5 +125,105 @@ def test_name_completed_with_multiple_names(mock_certificate, mock_event):
125125 completed_name = participant .name_completed ()
126126 assert len (completed_name .split ()) == 3
127127 assert completed_name == "Jardel Silva Santos"
128+
129+ def test_sanitize_filename_special_characters (mock_certificate ):
130+ """Testa se a função de sanitização remove adequadamente caracteres especiais"""
131+ # Cria um evento com nome contendo caracteres especiais
132+ event_with_special_chars = Event (
133+ order_id = 452 ,
134+ product_id = 316 ,
135+ product_name = "87º Python Floripa × CODECON @ UNICESUSC" ,
136+ date = datetime .strptime ("2025-03-26 20:55:25" , "%Y-%m-%d %H:%M:%S" ),
137+ time_checkin = datetime .strptime ("2025-03-26 20:55:44" , "%Y-%m-%d %H:%M:%S" ),
138+ checkin_latitude = - 27.5460492 ,
139+ checkin_longitude = - 48.6227075
140+ )
141+
142+ participant = Participant (
143+ first_name = "Rodrigo" ,
144+ last_name = "Farah" ,
145+ email = "rodrigo@example.com" ,
146+ phone = "(48) 98866-7447" ,
147+ cpf = "000.000.000-00" ,
148+ certificate = mock_certificate ,
149+ event = event_with_special_chars
150+ )
151+
152+ # Testa a função de sanitização diretamente
153+ sanitized = participant ._sanitize_filename ("87º Python Floripa × CODECON @ UNICESUSC" )
154+
155+ # Verifica se caracteres especiais foram sanitizados
156+ assert 'º' not in sanitized
157+ assert '×' not in sanitized
158+ assert '@' not in sanitized
159+ assert sanitized == "87o_Python_Floripa_x_CODECON_at_UNICESUSC"
160+
161+ def test_create_name_certificate_with_special_characters (mock_certificate ):
162+ """Testa se o nome do certificado é gerado corretamente com caracteres especiais"""
163+ # Cria um evento com nome contendo caracteres especiais (igual ao exemplo do usuário)
164+ event_with_special_chars = Event (
165+ order_id = 1397 ,
166+ product_id = 1324 ,
167+ product_name = "87º Python Floripa × CODECON @ UNICESUSC" ,
168+ date = datetime .strptime ("2025-06-19 11:15:31" , "%Y-%m-%d %H:%M:%S" ),
169+ time_checkin = datetime .strptime ("2025-06-19 11:15:31" , "%Y-%m-%d %H:%M:%S" ),
170+ checkin_latitude = - 27.5460492 ,
171+ checkin_longitude = - 48.6227075
172+ )
173+
174+ participant = Participant (
175+ first_name = "Rodrigo" ,
176+ last_name = "Farah" ,
177+ email = "rodrigo.farah@example.com" ,
178+ phone = "(48) 98866-7447" ,
179+ cpf = "000.000.000-00" ,
180+ certificate = mock_certificate ,
181+ event = event_with_special_chars
182+ )
183+
184+ name_certificate = participant .create_name_certificate ()
185+
186+ # Verifica se o nome do certificado não contém caracteres especiais problemáticos
187+ assert 'º' not in name_certificate
188+ assert '×' not in name_certificate
189+ assert '@' not in name_certificate
190+ assert name_certificate .endswith (".png" )
191+
192+ # Verifica se contém elementos esperados (sanitizados)
193+ assert "Rodrigo_Farah" in name_certificate
194+ assert "87o_Python_Floripa_x_CODECON_at_UNICESUSC" in name_certificate
195+
196+ # Verifica se o nome é válido para URL (não contém caracteres que precisam ser encoded)
197+ import re
198+ # Permite apenas caracteres alfanuméricos, hífens, underscores e pontos
199+ assert re .match (r'^[\w\-_.]+$' , name_certificate ), f"Nome do certificado contém caracteres inválidos: { name_certificate } "
200+
201+ def test_sanitize_filename_edge_cases (mock_certificate , mock_event ):
202+ """Testa casos extremos da função de sanitização"""
203+ participant = Participant (
204+ first_name = "Test" ,
205+ last_name = "User" ,
206+ email = "test@example.com" ,
207+ phone = "(48) 98866-7447" ,
208+ cpf = "000.000.000-00" ,
209+ certificate = mock_certificate ,
210+ event = mock_event
211+ )
212+
213+ # Testa strings com múltiplos caracteres especiais
214+ test_cases = {
215+ "" : "" , # String vazia
216+ " " : "" , # Apenas espaços
217+ "___" : "" , # Apenas underscores
218+ "Test @@@ Test" : "Test_at_at_at_Test" , # Múltiplos símbolos
219+ "Açaí & Café" : "Acai_and_Cafe" , # Acentos e símbolos
220+ "100% Success!!!" : "100_percent_Success" , # Porcentagem e exclamações
221+ "C++ Programming" : "C_plus_plus_Programming" , # Símbolos de programação
222+ "file/path\\ name" : "file_slash_path_backslash_name" , # Separadores de caminho
223+ }
224+
225+ for input_text , expected_output in test_cases .items ():
226+ result = participant ._sanitize_filename (input_text )
227+ assert result == expected_output , f"Para '{ input_text } ', esperado '{ expected_output } ', obtido '{ result } '"
128228
129229
0 commit comments