12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/usr/bin/env python3
- """
- Bench command to test customer abbreviation generation
- Usage: bench --site <site> test-abbr
- """
- import click
- import frappe
- from frappe import _
- @click.command('test-abbr')
- def test_abbr():
- """Test customer abbreviation generation"""
- try:
- # Import and run the test
- from upsystem.customer_abbr import (
- _get_base_abbreviation,
- _generate_unique_abbreviation,
- _is_abbreviation_unique
- )
-
- click.echo("Testing customer abbreviation generation...")
-
- # Test base abbreviation generation
- test_cases = [
- ("ACME Corporation", "AC"),
- ("Microsoft Inc", "MI"),
- ("Apple", "AP"),
- ("IBM", "IB"),
- ("A", "AC"),
- ("", "C")
- ]
-
- click.echo("\n1. Testing base abbreviation generation:")
- for customer_name, expected in test_cases:
- result = _get_base_abbreviation(customer_name)
- status = "✓" if result == expected else "✗"
- click.echo(f" {status} '{customer_name}' -> '{result}' (expected: '{expected}')")
-
- # Test unique abbreviation generation
- click.echo("\n2. Testing unique abbreviation generation:")
- test_base = "AC"
- result = _generate_unique_abbreviation(test_base, "test_customer")
- click.echo(f" Base '{test_base}' -> Unique '{result}'")
-
- # Test uniqueness check
- click.echo("\n3. Testing uniqueness check:")
- is_unique = _is_abbreviation_unique("TEST", "current_customer")
- click.echo(f" 'TEST' is unique: {is_unique}")
-
- click.echo("\nTest completed successfully!")
-
- except Exception as e:
- click.echo(f"Error during testing: {str(e)}")
- frappe.log_error(f"Test abbreviation error: {str(e)}")
- if __name__ == '__main__':
- test_abbr()
|