Skip to content

Commit 46bdc0d

Browse files
Copilotnijel
andcommitted
Changes before error encountered
Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
1 parent 083db8d commit 46bdc0d

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

test/test_dummy.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
#
2121

22+
import contextlib
2223
import contextlib
2324
import datetime
2425
import os.path
@@ -387,12 +388,27 @@ def test_getnextfile(self) -> None:
387388

388389
def test_save_ringtone_permissions(self) -> None:
389390
"""Test that SaveRingtone creates files with restrictive permissions."""
390-
# Create a simple ringtone dictionary
391-
ringtone = {"Name": "Test", "Notes": [{"Note": "C", "Duration": 4, "Scale": 1}]}
391+
# Create a complete ringtone dictionary with all required fields
392+
ringtone = {
393+
"Name": "TestRingtone",
394+
"Notes": [
395+
{
396+
"Type": "Note",
397+
"Value": 113, # Note value
398+
"Tempo": 120,
399+
"Scale": 1,
400+
"Style": "Natural",
401+
"Note": "C",
402+
"Duration": "1/4",
403+
"DurationSpec": "NoSpecialDuration",
404+
}
405+
],
406+
}
392407

393-
# Create a unique temporary file path using a secure method
394-
# We need to close and delete it so SaveRingtone can create it
395-
with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".rttl") as f:
408+
# Test 1: Save using string filename
409+
with tempfile.NamedTemporaryFile(
410+
mode="wb", delete=False, suffix=".rttl"
411+
) as f:
396412
temp_file = f.name
397413
os.unlink(temp_file) # Remove it so SaveRingtone can create it fresh
398414

@@ -430,6 +446,33 @@ def test_save_ringtone_permissions(self) -> None:
430446
with contextlib.suppress(FileNotFoundError):
431447
os.unlink(temp_file)
432448

449+
# Test 2: Test multiple formats to ensure comprehensive coverage
450+
formats_to_test = ["rttl", "ott", "imy"]
451+
for fmt in formats_to_test:
452+
with tempfile.NamedTemporaryFile(
453+
mode="wb", delete=False, suffix=f".{fmt}"
454+
) as f:
455+
temp_file = f.name
456+
os.unlink(temp_file)
457+
458+
try:
459+
gammu.SaveRingtone(temp_file, ringtone, fmt)
460+
assert os.path.exists(temp_file), f"File not created for format {fmt}"
461+
462+
# Verify permissions for each format
463+
if platform.system() != "Windows":
464+
file_stat = os.stat(temp_file)
465+
file_mode = stat.S_IMODE(file_stat.st_mode)
466+
assert (file_mode & stat.S_IRWXG) == 0, (
467+
f"Format {fmt}: Group has permissions"
468+
)
469+
assert (file_mode & stat.S_IRWXO) == 0, (
470+
f"Format {fmt}: Others have permissions"
471+
)
472+
finally:
473+
with contextlib.suppress(FileNotFoundError):
474+
os.unlink(temp_file)
475+
433476
def test_incoming_call(self) -> None:
434477
self.check_incoming_call()
435478
self._called = False

0 commit comments

Comments
 (0)