88 lines
3.6 KiB
Python
88 lines
3.6 KiB
Python
from core.sheerka.services.SheerkaFunctionsParametersHistory import SheerkaFunctionsParametersHistory, \
|
|
FunctionParametersObj
|
|
|
|
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
|
|
class TestSheerkaFunctionsParametersHistory(TestUsingMemoryBasedSheerka):
|
|
def test_i_can_add_a_parameter_value(self):
|
|
sheerka, context = self.init_concepts(cache_only=False)
|
|
service = SheerkaFunctionsParametersHistory(sheerka).initialize()
|
|
|
|
service.record_function_parameter(context, "function", 1, "10")
|
|
service.record_function_parameter(context, "function", 2, "True")
|
|
service.record_function_parameter(context, "function", 3, "'string value'")
|
|
|
|
assert service.cache.copy() == {"function": FunctionParametersObj(
|
|
context.event.get_digest(),
|
|
"function",
|
|
{
|
|
1: [('10', 1)],
|
|
2: [('True', 1)],
|
|
3: [("'string value'", 1)]
|
|
})}
|
|
|
|
# and i can serialize
|
|
sheerka.cache_manager.commit(context)
|
|
from_db = sheerka.sdp.get(SheerkaFunctionsParametersHistory.FUNCTIONS_PARAMETERS_ENTRY, "function")
|
|
assert from_db.event_id == context.event.get_digest()
|
|
assert from_db.name == "function"
|
|
assert from_db.params == {
|
|
1: [('10', 1)],
|
|
2: [('True', 1)],
|
|
3: [("'string value'", 1)]
|
|
}
|
|
|
|
def test_i_can_add_the_same_value_multiple_times(self):
|
|
sheerka, context = self.init_concepts(cache_only=True)
|
|
service = SheerkaFunctionsParametersHistory(sheerka)
|
|
|
|
service.record_function_parameter(context, "function", 1, "10")
|
|
service.record_function_parameter(context, "function", 1, "20")
|
|
service.record_function_parameter(context, "function", 2, "True")
|
|
service.record_function_parameter(context, "function", 1, "20")
|
|
|
|
assert service.cache.copy() == {"function": FunctionParametersObj(
|
|
context.event.get_digest(),
|
|
"function",
|
|
{
|
|
1: [('10', 1), ('20', 2)],
|
|
2: [('True', 1)],
|
|
})}
|
|
|
|
def test_i_can_specify_parameter_in_any_order(self):
|
|
sheerka, context = self.init_concepts()
|
|
service = SheerkaFunctionsParametersHistory(sheerka)
|
|
|
|
service.record_function_parameter(context, "function", 3, "'string value'")
|
|
service.record_function_parameter(context, "function", 2, "True")
|
|
|
|
assert service.cache.copy() == {"function": FunctionParametersObj(
|
|
context.event.get_digest(),
|
|
"function",
|
|
{
|
|
2: [('True', 1)],
|
|
3: [("'string value'", 1)]
|
|
})}
|
|
|
|
def test_no_value_is_managed(self):
|
|
sheerka, context = self.init_concepts()
|
|
service = SheerkaFunctionsParametersHistory(sheerka)
|
|
|
|
# no entry for the function
|
|
assert service.get_function_parameters("function", 2) == []
|
|
|
|
# no entry for the parameter number
|
|
service.record_function_parameter(context, "function", 1, "'string value'")
|
|
assert service.get_function_parameters("function", 2) == []
|
|
|
|
def test_i_can_get_sorted_parameters(self):
|
|
sheerka, context = self.init_concepts()
|
|
service = SheerkaFunctionsParametersHistory(sheerka)
|
|
|
|
service.record_function_parameter(context, "function", 2, "'string value'")
|
|
service.record_function_parameter(context, "function", 2, "True")
|
|
service.record_function_parameter(context, "function", 2, "True")
|
|
|
|
assert service.get_function_parameters("function", 2) == ["True", "'string value'"]
|