From 2f1bc91d448cf4d7140caf0eb4443e013fe6c903 Mon Sep 17 00:00:00 2001 From: Devan Agrawal Date: Tue, 10 Sep 2024 09:14:59 -0700 Subject: [PATCH] TST: add working tag search test --- superscore/tests/test_backend.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/superscore/tests/test_backend.py b/superscore/tests/test_backend.py index 6b7fb07..01afe98 100644 --- a/superscore/tests/test_backend.py +++ b/superscore/tests/test_backend.py @@ -1,3 +1,4 @@ +from enum import Flag, auto from uuid import UUID import pytest @@ -127,6 +128,33 @@ def test_fuzzy_search(backends: _Backend): assert len(results) == 2 +@pytest.mark.parametrize('backends', [0], indirect=True) +def test_tag_search(backends: _Backend): + results = list(backends.search( + SearchTerm('tags', 'gt', set()) + )) + assert len(results) == 2 # only the Collection and Snapshot have .tags + + class Tag(Flag): + T1 = auto() + T2 = auto() + + results[0].tags = {Tag.T1} + results[1].tags = {Tag.T1, Tag.T2} + backends.update_entry(results[0]) + backends.update_entry(results[1]) + + results = list(backends.search( + SearchTerm('tags', 'gt', {Tag.T1}) + )) + assert len(results) == 2 + + results = list(backends.search( + SearchTerm('tags', 'gt', {Tag.T1, Tag.T2}) + )) + assert len(results) == 1 + + @pytest.mark.parametrize('backends', [0], indirect=True) def test_update_entry(backends: _Backend): # grab an entry from the database and modify it.