-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/pdct 1628 handle slugs for documents with the same title (#237)
* Handle duplicate titles when creating slugs during bulk import * Refactor to surface commit errors better * Increase suffix length to 6 * Bump patch version * Update poetry.lock file
- Loading branch information
Showing
9 changed files
with
180 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "admin_backend" | ||
version = "2.17.3" | ||
version = "2.17.4" | ||
description = "" | ||
authors = ["CPR-dev-team <[email protected]>"] | ||
packages = [{ include = "app" }, { include = "tests" }] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import uuid | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from app.repository.helpers import generate_unique_slug | ||
|
||
|
||
def test_successfully_generates_a_slug_with_a_four_digit_suffix(): | ||
title = "Test title" | ||
generated_slug = generate_unique_slug(set(), title) | ||
|
||
expected_slugified_title = "test-title_" | ||
expected_suffix_length = 6 | ||
|
||
assert expected_slugified_title in generated_slug | ||
assert len(expected_slugified_title) + expected_suffix_length == len(generated_slug) | ||
|
||
|
||
def test_successfully_generates_a_unique_slug_if_one_already_exists(): | ||
title = "Test title" | ||
|
||
existing_slug = generate_unique_slug(set(), title) | ||
existing_suffix = existing_slug.split("_")[1] | ||
|
||
with patch( | ||
"app.repository.helpers.uuid4", | ||
side_effect=[existing_suffix, uuid.uuid4], | ||
): | ||
generated_slug = generate_unique_slug({existing_slug}, title) | ||
|
||
assert existing_slug != generated_slug | ||
|
||
|
||
def test_raises_error_if_a_unique_slug_cannot_be_created_in_a_specified_number_of_attempts(): | ||
title = "Test title" | ||
|
||
existing_slug = generate_unique_slug(set(), title) | ||
existing_suffix = existing_slug.split("_")[1] | ||
|
||
with ( | ||
patch( | ||
"app.repository.helpers.uuid4", | ||
return_value=existing_suffix, | ||
), | ||
pytest.raises(RuntimeError), | ||
): | ||
generate_unique_slug({existing_slug}, title, 2) |
Oops, something went wrong.