bottleneckcrm/backend/common/tests/test_csv_import_nul.py
Ashwin 794ff2dbd4 Refactor ticket and contact handling to improve visibility and access control
- Updated task views to utilize new access functions for accounts and contacts, ensuring users only see what they can access.
- Enhanced contact editing to maintain linked accounts even when not visible in the picker, preventing accidental unlinking.
- Introduced tests for contact form to verify linked account behavior.
- Implemented parent ticket handling to correctly display restricted tickets, ensuring hidden parents are represented accurately in the UI.
- Added tests for ticket parent visibility and interaction, confirming that restricted parents do not allow navigation.
- Improved ticket tree structure to handle restricted nodes, ensuring proper functionality during close operations.
2026-09-26 12:17:45 +05:30

41 lines
1.4 KiB
Python

"""A NUL byte in an import CSV is a header_error, not a Postgres 500.
Python's csv module accepts NUL since 3.11 and Postgres rejects it in any
string parameter. SQLite stores it happily, so an endpoint test would pass on
the default test database; these call the parsers directly instead.
"""
import pytest
from cases.services.csv_import import parse_and_validate as parse_tickets
from contacts.services.csv_import import parse_and_validate as parse_contacts
pytestmark = pytest.mark.django_db
@pytest.mark.parametrize(
"parse, csv_bytes",
[
(parse_contacts, b"first_name,last_name,email\nAda,Love\x00lace,a@x.com\n"),
(parse_tickets, b"name,status,priority\nBro\x00ken,New,High\n"),
],
ids=["contacts", "tickets"],
)
def test_nul_character_is_a_header_error(parse, csv_bytes, org_a, admin_profile):
result = parse(csv_bytes, org_a, admin_profile)
assert result.valid == []
assert "NUL" in (result.header_error or "")
@pytest.mark.parametrize(
"parse, csv_bytes",
[
(parse_contacts, b"first_name,last_name,email\nAda,Lovelace,a@x.com\n"),
(parse_tickets, b"name,status,priority\nBroken,New,High\n"),
],
ids=["contacts", "tickets"],
)
def test_clean_file_still_parses(parse, csv_bytes, org_a, admin_profile):
result = parse(csv_bytes, org_a, admin_profile)
assert result.header_error is None
assert len(result.valid) == 1