def test_generate_unique_slug_with_slugable_field(product_type, product_name, slug_result): product_names_and_slugs = [ ("Paint", "paint"), ("Paint blue", "paint-blue"), ("Paint test", "paint-2"), ("405", "405"), ("FM1", "fm1"), ] for name, slug in product_names_and_slugs: ProductType.objects.create(name=name, slug=slug) instance, _ = ProductType.objects.get_or_create(name=product_name) result = generate_unique_slug(instance, instance.name) assert result == slug_result
def test_generate_unique_slug_non_slugable_value_and_slugable_field(category): with pytest.raises(Exception): generate_unique_slug(category)
def test_generate_unique_slug_for_slug_with_max_characters_number(category): slug = "a" * 256 result = generate_unique_slug(category, slug) category.slug = result with pytest.raises(DataError): category.save()