Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hardcover_sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def find_sync_from_changes(
current_progress_pct = hc_book.current_progress_percent
if sync_progress and progress_percent_col and current_progress_pct is not None:
current = get_calibre_value(calibre_id, progress_percent_col)
new_progress_pct = round(current_progress_pct, 1)
new_progress_pct = round(current_progress_pct / 100, 3)
current_rounded = round(float(current), 1) if current else None
if current_rounded != new_progress_pct:
changes.append(
Expand Down
3 changes: 3 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,16 @@ def test_create_user_book_read(self):
finished_at="2024-01-30",
progress_pages=250,
edition_id=456,
progress=0.34,
)

assert read.id == 100
assert read.started_at == "2024-01-15"
assert read.finished_at == "2024-01-30"
assert read.progress_pages == 250
assert read.edition_id == 456
assert read.progress == 0.34
assert read.progress_percent == 34

def test_user_book_read_with_none_values(self):
"""Test UserBookRead with missing/None values."""
Expand Down
33 changes: 29 additions & 4 deletions test/test_sync_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def test_progress_percent_change(self):

def get_value(calibre_id, col):
if col == "progress_pct_col":
return 50.0 # Current is 50%, should change to 75%
return 0.50 # Current is 50%, should change to 75%
return None

def get_title(calibre_id):
Expand All @@ -759,8 +759,8 @@ def get_title(calibre_id):

assert len(changes) == 1
assert changes[0].field == "progress_percent"
assert "50.0%" in changes[0].old_value
assert "75.0%" in changes[0].new_value
assert "0.5%" in changes[0].old_value
assert "0.75%" in changes[0].new_value

def test_progress_percent_empty_to_value(self):
"""Test progress percent change from empty to value."""
Expand All @@ -784,7 +784,32 @@ def get_title(calibre_id):
assert len(changes) == 1
assert changes[0].field == "progress_percent"
assert changes[0].old_value == "(empty)"
assert "25.0%" in changes[0].new_value
assert "0.25" in changes[0].new_value

def test_progress_percent_valid(self):
"""Test detecting progress percent changes and is a valid percentage."""
hc_books = [self.create_user_book_with_reads(100, progress=0.75)] # 75%
hc_to_calibre = {"test-book": 1}

def get_value(calibre_id, col):
if col == "progress_pct_col":
return 50.0 # Current is 50%, should change to 75%
return None

def get_title(calibre_id):
return "Test Book"

prefs = {
"status_column": "",
"progress_percent_column": "progress_pct_col",
"sync_progress": True,
}

changes = find_sync_from_changes(hc_books, hc_to_calibre, get_value, get_title, prefs)

assert len(changes) == 1
assert changes[0].field == "progress_percent"
assert changes[0].raw_value == str(0.75)


class TestFindSyncFromChangesDates:
Expand Down
Loading