Skip to content

Commit

Permalink
feat: fix deleted value test
Browse files Browse the repository at this point in the history
wrong specification
  • Loading branch information
agritheory committed Aug 4, 2024
1 parent b7fddc2 commit fc27225
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def get_applicable_specification(doc):

@frappe.whitelist()
def get_specification_values(reference_doctype, reference_name, specification=None):
_r = []
if not specification:
specs = get_applicable_specification(frappe.get_doc(reference_doctype, reference_name))
_r = []
else:
specs = [specification]
for s in specs:
Expand Down
4 changes: 4 additions & 0 deletions inventory_tools/tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ def create_specifications(settings=None):


def create_demo_specification_values():
"""
run this if you need to manually create data for demoing faceted search
bench execute 'inventory_tools.tests.setup.create_demo_specification_values'
"""
from inventory_tools.tests.test_faceted_search import (
test_values_updated_on_item_save,
test_generate_values,
Expand Down
20 changes: 11 additions & 9 deletions inventory_tools/tests/test_faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def test_manual_attribute_addition():
_args = {
"reference_doctype": "Item",
"reference_name": item,
"specification": "Baked Goods",
"specification": "Items",

}
values = frappe.call(
"inventory_tools.inventory_tools.doctype.specification.specification.get_specification_values",
Expand All @@ -128,20 +129,20 @@ def test_manual_attribute_addition():
if isinstance(manual_values, list):
for v in manual_values:
values.append(
{"row_name": "", "attribute": attribute, "value": v, "specification": "Baked Goods"}
{"row_name": "", "attribute": attribute, "value": v, "specification": "Items"}
)
else:
values.append(
{
"row_name": "",
"attribute": attribute,
"value": manual_values,
"specification": "Baked Goods",
"specification": "Items",
}
)
# print(existing_values)
args = {
"spec": "Baked Goods",
"spec": "Items",
"specifications": frappe.as_json(values),
"reference_doctype": "Item",
"reference_name": item,
Expand All @@ -152,7 +153,7 @@ def test_manual_attribute_addition():
)
assert (
len(
frappe.get_all("Specification Value", {"specification": "Baked Goods", "attribute": "Color"})
frappe.get_all("Specification Value", {"specification": "Items", "attribute": "Color"})
)
== 25
) # all colors in baked goods items from fixtures
Expand All @@ -164,14 +165,15 @@ def test_delete_of_specification_value():
_args = {
"reference_doctype": "Item",
"reference_name": "Ambrosia Pie",
"specification": "Baked Goods",
"specification": "Items",
}
values = frappe.call(
"inventory_tools.inventory_tools.doctype.specification.specification.get_specification_values",
**_args
)
assert "Blue" in [v.value for v in values if v.attribute == "Color"]
assert len(values) == 11
colors = [v.value for v in values if v.attribute == "Color"]
assert "Blue" in colors
assert len(colors) == 2

for v in values:
if v.attribute == "Color" and v.value == "Blue":
Expand All @@ -192,7 +194,7 @@ def test_delete_of_specification_value():
frappe.get_all(
"Specification Value",
{
"specification": "Baked Goods",
"specification": "Items",
"attribute": "Color",
"reference_name": _args.get("reference_name"),
},
Expand Down

0 comments on commit fc27225

Please sign in to comment.