Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bitmapist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ class MixinEventsMisc:

def has_events_marked(self):
cli = get_redis(self.system)
return bool(cli.exists(self.redis_key))
# Note: bitcount() returns 0 if the key doesn't exist
# https://redis.io/docs/latest/commands/bitcount/
return cli.bitcount(self.redis_key) > 0

def delete(self):
cli = get_redis(self.system)
Expand Down
19 changes: 17 additions & 2 deletions test/test_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ def events():
@pytest.mark.parametrize(
("select1", "select1b", "select2", "select2b", "expected"),
[
# Basic tests without select1b/select2b
("active", None, "active", None, [2, 100, 50]),
("active", None, "unknown", None, [2, "", ""]),
("unknown", None, "active", None, [0, "", ""]),

# Tests with select1b (AND conditions for select1)
("signup", "active", "active", None, [2, 100, 50]),
("signup", "active", "active", "signup", [2, 100, 0]),

# Tests with both select1b and select2b
("task1", "task2", "task2", "task1", [2, 100, 100]),
("task1", "task2", "task1", "task2", [2, 100, 100]),

# When select1 has no events but select1b has events, result should be 0
("unknown", "active", "active", None, [0, "", ""]),

# When select1 has events but select2 AND select2b results in 0
("active", None, "unknown", "active", [2, "", ""]),

# When select1 has events but select1b has no events (no overlap)
("active", "unknown", "active", None, [0, "", ""]),

# When select2 has events but select2b has no events (no overlap)
("active", None, "active", "unknown", [2, "", ""]),
],
)
def test_cohort(select1, select1b, select2, select2b, expected, events):
Expand Down