Skip to content

Commit

Permalink
Added InvenTree category tree to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Feb 23, 2023
1 parent 909dc16 commit 8b579fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
24 changes: 13 additions & 11 deletions kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,18 @@ def set_enable_flag(key: str, value: bool):
global CONFIG_GENERAL

user_settings = CONFIG_GENERAL
if key == 'kicad':
user_settings['ENABLE_KICAD'] = value
elif key == 'inventree':
user_settings['ENABLE_INVENTREE'] = value
elif key == 'alternate':
user_settings['ENABLE_ALTERNATE'] = value
else:
print(f'[INFO] Key {key} does not exist')

# Save
config_interface.dump_file(user_settings, os.path.join(CONFIG_USER_FILES, 'general.yaml'))
if key in ['kicad', 'inventree', 'alternate']:
if key == 'kicad':
user_settings['ENABLE_KICAD'] = value
elif key == 'inventree':
user_settings['ENABLE_INVENTREE'] = value
elif key == 'alternate':
user_settings['ENABLE_ALTERNATE'] = value

# Save
config_interface.dump_file(
data=user_settings,
file_path=os.path.join(CONFIG_USER_FILES, 'general.yaml'),
)

return reload_enable_flags()
6 changes: 4 additions & 2 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def build_tree(tree, left_to_go, level) -> list:

if not reload:
categories = category_data.get('CATEGORIES', {})
if category:
categories = categories.get(category, {})
else:
categories = inventree_api.get_categories(category)
category_data['CATEGORIES'] = categories
config_interface.dump_file(category_data, settings.CONFIG_CATEGORIES)

# Get branch
if category:
categories = {category: categories.get(category, {})}

inventree_categories = []
# Build category tree
build_tree(inventree_categories, categories, 0)
Expand Down
18 changes: 18 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def check_result(status: str, new_part: bool) -> bool:
'Add invalid alternate supplier part using part IPN',
'Save InvenTree settings',
'Load configuration files with incorrect paths',
'Build InvenTree category tree (file, db and branch)',
]
method_success = True
# Line return
Expand Down Expand Up @@ -411,6 +412,23 @@ def check_result(status: str, new_part: bool) -> bool:
if config_interface.load_user_config_files('', ''):
method_success = False

elif method_idx == 15:
# Reload categories from file
cat_from_file = inventree_interface.build_category_tree(reload=False)
if type(cat_from_file) != list:
method_success = False
break
# Reload categories from InvenTree database
cat_from_db = inventree_interface.build_category_tree(reload=True)
if len(cat_from_db) != len(cat_from_file):
method_success = False
break
# Reload category branch
cat_branch = inventree_interface.build_category_tree(category='Crystals and Oscillators')
if len(cat_branch) != 3:
method_success = False
break

if method_success:
cprint('[ PASS ]')
else:
Expand Down

0 comments on commit 8b579fd

Please sign in to comment.