Self hosted FLOSS fitness/workout, nutrition and weight tracker
Formatting
Roland Geider44ba8e6cede4
diff --git a/wger/nutrition/management/commands/import-off-products.py b/wger/nutrition/management/commands/import-off-products.pyindex 49a625e42..d5d5062ab 100644--- a/wger/nutrition/management/commands/import-off-products.py+++ b/wger/nutrition/management/commands/import-off-products.py@@ -21,8 +21,8 @@ import requests# wgerfrom wger.core.models import Language-from wger.nutrition.extract_info.off import extract_info_from_offfrom wger.nutrition.consts import SyncMode+from wger.nutrition.extract_info.off import extract_info_from_offfrom wger.nutrition.management.products import ImportProductCommanddiff --git a/wger/nutrition/management/commands/import-usda-products.py b/wger/nutrition/management/commands/import-usda-products.pyindex ff3498355..a7b85f7ea 100644--- a/wger/nutrition/management/commands/import-usda-products.py+++ b/wger/nutrition/management/commands/import-usda-products.py@@ -21,8 +21,8 @@ from zipfile import ZipFile# wgerfrom wger.core.models import Language-from wger.nutrition.extract_info.usda import extract_info_from_usdafrom wger.nutrition.consts import SyncMode+from wger.nutrition.extract_info.usda import extract_info_from_usdafrom wger.nutrition.management.products import ImportProductCommandfrom wger.utils.constants import ENGLISH_SHORT_NAMEdiff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.pyindex c430cf23c..22356c4c5 100644--- a/wger/nutrition/sync.py+++ b/wger/nutrition/sync.py@@ -43,11 +43,11 @@ from tqdm import tqdm# wgerfrom wger.core.models.language import Language-from wger.nutrition.consts import SyncModefrom wger.nutrition.api.endpoints import (IMAGE_ENDPOINT,INGREDIENTS_ENDPOINT,)+from wger.nutrition.consts import SyncModefrom wger.nutrition.extract_info.wger import extract_info_from_wger_apifrom wger.nutrition.models import (Image,@@ -379,9 +379,11 @@ def export_ingredient_dump("""# Import here to avoid circular imports+ # Djangofrom django.core.files.base import Filefrom django.core.files.storage import default_storage+ # wgerfrom wger.nutrition.api.endpoints import INGREDIENT_BULK_EXPORT_PATHfrom wger.nutrition.api.serializers import IngredientSerializer@@ -529,6 +531,7 @@ def download_ingredient_dump(Returns the path to the downloaded file."""+ # wgerfrom wger.nutrition.api.endpoints import INGREDIENT_BULK_EXPORT_PATHdump_url = f'{remote_url}{settings.MEDIA_URL}{INGREDIENT_BULK_EXPORT_PATH}'diff --git a/wger/nutrition/tasks.py b/wger/nutrition/tasks.pyindex 03edf0ef2..aa1174ac2 100644--- a/wger/nutrition/tasks.py+++ b/wger/nutrition/tasks.py@@ -30,8 +30,8 @@ from celery.schedules import crontabfrom wger.celery_configuration import appfrom wger.nutrition.api.endpoints import INGREDIENTS_ENDPOINTfrom wger.nutrition.sync import (- download_ingredient_images,download_ingredient_dump,+ download_ingredient_images,export_ingredient_dump,fetch_ingredient_image,sync_ingredients,diff --git a/wger/nutrition/tests/test_sync_bulk.py b/wger/nutrition/tests/test_sync_bulk.pyindex aa2205dde..822bad795 100644--- a/wger/nutrition/tests/test_sync_bulk.py+++ b/wger/nutrition/tests/test_sync_bulk.py@@ -31,8 +31,8 @@ from django.test import SimpleTestCase# wgerfrom wger.core.tests.base_testcase import WgerTestCase-from wger.nutrition.models import Ingredientfrom wger.nutrition.consts import SyncMode+from wger.nutrition.models import Ingredientfrom wger.nutrition.sync import (_open_jsonl,download_ingredient_dump,@@ -141,6 +141,7 @@ class TestExportIngredientDump(WgerTestCase):self.tmp_media = tempfile.mkdtemp()def tearDown(self):+ # Standard Libraryimport shutilshutil.rmtree(self.tmp_media, ignore_errors=True)@@ -155,6 +156,7 @@ class TestExportIngredientDump(WgerTestCase):with self.settings(MEDIA_ROOT=self.tmp_media):saved_name = self._export()+ # Djangofrom django.core.files.storage import default_storageself.assertTrue(default_storage.exists(saved_name))@@ -192,6 +194,7 @@ class TestExportIngredientDump(WgerTestCase):self.assertEqual(saved_name_1, saved_name_2)with self.settings(MEDIA_ROOT=self.tmp_media):+ # Djangofrom django.core.files.storage import default_storageself.assertTrue(default_storage.exists(saved_name_2))@@ -405,11 +408,10 @@ class TestBulkSyncManagementCommands(WgerTestCase):def _get_command_module(self):"""Get the bulk-sync-ingredients command module (hyphenated name needs importlib)."""+ # Standard Libraryimport importlib- return importlib.import_module(- 'wger.nutrition.management.commands.bulk-sync-ingredients'- )+ return importlib.import_module('wger.nutrition.management.commands.bulk-sync-ingredients')@patch('wger.core.api.min_server_version.check_min_server_version')def test_bulk_sync_command_calls_functions(self, mock_version_check: MagicMock):@@ -417,13 +419,16 @@ class TestBulkSyncManagementCommands(WgerTestCase):mod = self._get_command_module()with (- patch.object(mod, 'download_ingredient_dump', return_value='/tmp/fake.jsonl.gz') as mock_download,+ patch.object(+ mod, 'download_ingredient_dump', return_value='/tmp/fake.jsonl.gz'+ ) as mock_download,patch.object(mod, 'sync_ingredients_from_dump') as mock_sync,):out = StringIO()call_command('bulk-sync-ingredients',- '--remote-url', 'https://example.com',+ '--remote-url',+ 'https://example.com',stdout=out,)@@ -436,13 +441,15 @@ class TestBulkSyncManagementCommands(WgerTestCase):mod = self._get_command_module()with patch.object(- mod, 'download_ingredient_dump',+ mod,+ 'download_ingredient_dump',side_effect=FileNotFoundError('Bulk ingredient dump not found'),):out = StringIO()with self.assertRaises(CommandError):call_command('bulk-sync-ingredients',- '--remote-url', 'https://example.com',+ '--remote-url',+ 'https://example.com',stdout=out,)