mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-11 20:28:01 +00:00
Trims tests I don't think cover our logic or code or are redundant
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
from whoosh_compat import FieldKind
|
||||
|
||||
from documents.search._fields import PUBLIC_FIELDS
|
||||
|
||||
|
||||
class TestPublicFields:
|
||||
def test_json_fields_have_subpaths(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- PUBLIC_FIELDS, the canonical query-syntax field table
|
||||
WHEN:
|
||||
- A field declares FieldKind.JSON
|
||||
THEN:
|
||||
- That field also declares at least one subpath
|
||||
"""
|
||||
for field in PUBLIC_FIELDS:
|
||||
if field.kind is FieldKind.JSON:
|
||||
assert field.subpaths, f"{field.name} is JSON but has no subpaths"
|
||||
@@ -60,17 +60,3 @@ class TestKeywordPatternNormalizer:
|
||||
"""
|
||||
normalize = _normalizer(get_field_registry("en"), "checksum")
|
||||
assert normalize(run) == run
|
||||
|
||||
def test_text_runs_still_offer_their_stem(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The "title" field's registered pattern normalizer (TEXT kind,
|
||||
"en" registry)
|
||||
WHEN:
|
||||
- A wildcard pattern run is normalized
|
||||
THEN:
|
||||
- Both the folded run and its stem are offered, so a term
|
||||
matching either one is reachable
|
||||
"""
|
||||
normalize = _normalizer(get_field_registry("en"), "title")
|
||||
assert tuple(normalize("Running")) == ("running", "run")
|
||||
|
||||
@@ -32,29 +32,6 @@ def _distinct_forms(result: str | Sequence[str]) -> tuple[str, ...]:
|
||||
|
||||
|
||||
class TestFieldRegistry:
|
||||
def test_internal_id_fields_are_not_registered(
|
||||
self,
|
||||
registry: FieldRegistry,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The field registry built from PUBLIC_FIELDS
|
||||
WHEN:
|
||||
- An internal *_id column name (e.g. "tag_id") is looked up
|
||||
THEN:
|
||||
- The registry does not recognize it as a queryable field
|
||||
"""
|
||||
for name in (
|
||||
"tag_id",
|
||||
"owner_id",
|
||||
"viewer_id",
|
||||
"correspondent_id",
|
||||
"document_type_id",
|
||||
"storage_path_id",
|
||||
"viewer_group_id",
|
||||
):
|
||||
assert name not in registry
|
||||
|
||||
def test_no_queryable_field_name_ends_in_id(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
@@ -121,22 +98,6 @@ class TestFieldRegistry:
|
||||
for raw in ("custom_fields.name", "custom_fields.value"):
|
||||
_resolve(registry, raw)
|
||||
|
||||
def test_unregistered_json_subpath_does_not_resolve(
|
||||
self,
|
||||
registry: FieldRegistry,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The field registry
|
||||
WHEN:
|
||||
- A dotted name naming an unregistered subpath ("notes.bogus")
|
||||
is turned into a FieldRef
|
||||
THEN:
|
||||
- make_ref returns None (it is not even a valid ref for
|
||||
resolve() to then reject)
|
||||
"""
|
||||
assert registry.make_ref("notes.bogus") is None
|
||||
|
||||
def test_tag_is_comma_values(self, registry: FieldRegistry) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import UTC
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
import tantivy
|
||||
|
||||
from documents.search._fields import PUBLIC_FIELDS
|
||||
from documents.search._schema import SCHEMA_VERSION
|
||||
@@ -14,11 +11,11 @@ from documents.search._schema import build_schema
|
||||
from documents.search._schema import field_descriptors
|
||||
from documents.search._schema import needs_rebuild
|
||||
from documents.search._schema import schema_fingerprint
|
||||
from documents.search._tokenizer import register_tokenizers
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
import tantivy
|
||||
from pytest_django.fixtures import Settings
|
||||
|
||||
|
||||
@@ -123,37 +120,6 @@ class TestSchemaMatchesPublicFields:
|
||||
f"{field.name} is in PUBLIC_FIELDS but missing from build_schema()"
|
||||
)
|
||||
|
||||
def test_asn_page_count_num_notes_are_fast_unsigned_fields(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A document with asn/page_count/num_notes values, indexed
|
||||
against the schema built by build_schema()
|
||||
WHEN:
|
||||
- A term query on the fast "asn" field is run
|
||||
THEN:
|
||||
- The document is found, spot-checking kind-derived
|
||||
construction for the U64 fields
|
||||
"""
|
||||
schema = build_schema()
|
||||
doc = tantivy.Document()
|
||||
doc.add_unsigned("id", 1)
|
||||
doc.add_text("checksum", "x")
|
||||
doc.add_unsigned("asn", 42)
|
||||
doc.add_unsigned("page_count", 3)
|
||||
doc.add_unsigned("num_notes", 0)
|
||||
doc.add_date("created", datetime(2020, 1, 1, tzinfo=UTC))
|
||||
doc.add_date("modified", datetime(2020, 1, 1, tzinfo=UTC))
|
||||
doc.add_date("added", datetime(2020, 1, 1, tzinfo=UTC))
|
||||
index = tantivy.Index(schema)
|
||||
register_tokenizers(index, None)
|
||||
writer = index.writer()
|
||||
writer.add_document(doc)
|
||||
writer.commit()
|
||||
index.reload()
|
||||
searcher = index.searcher()
|
||||
results = searcher.search(tantivy.Query.term_query(schema, "asn", 42), limit=1)
|
||||
assert len(results.hits) == 1
|
||||
|
||||
|
||||
class TestFastFlagAgreement:
|
||||
def test_every_public_field_fast_flag_matches_the_built_schema(self) -> None:
|
||||
|
||||
@@ -136,25 +136,6 @@ class TestUpgradeFromReleasedV1Index:
|
||||
"""
|
||||
assert needs_rebuild(released_v1_index) is True
|
||||
|
||||
def test_v1_index_rejects_writes_against_the_current_schema(
|
||||
self,
|
||||
released_v1_index: Path,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A v1 index directory and the current build_schema()
|
||||
WHEN:
|
||||
- A new tantivy.Index is opened against that directory with
|
||||
the current schema
|
||||
THEN:
|
||||
- It raises ValueError("schema does not match ..."), the
|
||||
exact failure mode WriteBatch.__enter__ hits on every index
|
||||
write, which the version bump exists to prevent
|
||||
"""
|
||||
schema = build_schema()
|
||||
with pytest.raises(ValueError, match="schema does not match"):
|
||||
tantivy.Index(schema, path=str(released_v1_index))
|
||||
|
||||
def test_opening_a_v1_index_leaves_it_writable(
|
||||
self,
|
||||
released_v1_index: Path,
|
||||
@@ -168,9 +149,10 @@ class TestUpgradeFromReleasedV1Index:
|
||||
- The directory can be reopened with the current schema
|
||||
without raising; end to end, open_or_rebuild_index must
|
||||
hand back an index the write path can reopen. Before the
|
||||
version bump, needs_rebuild() returned False here, the
|
||||
stale directory survived untouched, and every subsequent
|
||||
write raised the ValueError from the test above
|
||||
version bump, needs_rebuild() returned False here, and the
|
||||
stale directory survived untouched, so every subsequent
|
||||
write against it raised tantivy's own schema-mismatch
|
||||
ValueError
|
||||
"""
|
||||
open_or_rebuild_index(released_v1_index)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user