Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Dec 7, 2022
1 parent 5df6659 commit b96f1f2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion test/test_reserve_task_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
acquire_reserve_task_lock,
release_reserve_task_lock_by_keys,
release_reserve_task_lock_by_id,
get_reserve_task_key
get_reserve_task_key,
get_reserved_categories_cache_keys
)
from pybossa.util import (
cached_keys_to_reserved_categories,
Expand Down Expand Up @@ -334,6 +335,32 @@ def test_get_reserve_task_key(self):
reserve_key = get_reserve_task_key(task.id)
assert reserve_key == expected_key, "reserve key expected to be {}".format(expected_key)

@with_context
@patch("pybossa.redis_lock.LockManager.get_task_category_lock")
def test_get_reserved_categories_cache_keys(self, mock_get_task_category_lock):
"""Test get_reserved_categories_cache_keys returns reserved categories from cache"""
from flask import current_app

reserved_task_config = ["name1", "name2"]
project_id = 1
timeout = 30
user_id = 1

# ensure reserved task category disabled for private instance
current_app.config["PRIVATE_INSTANCE"] = True
user_category_keys, other_user_category_keys, all_user_category_keys = get_reserved_categories_cache_keys(
reserved_task_config, project_id, timeout, user_id)
assert not (user_category_keys or other_user_category_keys or all_user_category_keys)

current_app.config["PRIVATE_INSTANCE"] = False
category = "name1:*:name2:*"
mock_get_task_category_lock.return_value = [], [], []
user_category_keys, other_user_category_keys, all_user_category_keys = get_reserved_categories_cache_keys(
reserved_task_config, project_id, timeout, user_id)
mock_get_task_category_lock.assert_called_once_with(project_id, user_id, category)



@with_context
def test_cached_keys_to_reserved_categories(self):
"""Test cached_keys_to_reserved_categories returns correct reserved categories from cached keys"""
Expand Down

0 comments on commit b96f1f2

Please sign in to comment.