Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
index 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
# wger
from wger.core.models import Language
-from wger.nutrition.extract_info.off import extract_info_from_off
from wger.nutrition.consts import SyncMode
+from wger.nutrition.extract_info.off import extract_info_from_off
from wger.nutrition.management.products import ImportProductCommand
diff --git a/wger/nutrition/management/commands/import-usda-products.py b/wger/nutrition/management/commands/import-usda-products.py
index 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
# wger
from wger.core.models import Language
-from wger.nutrition.extract_info.usda import extract_info_from_usda
from wger.nutrition.consts import SyncMode
+from wger.nutrition.extract_info.usda import extract_info_from_usda
from wger.nutrition.management.products import ImportProductCommand
from wger.utils.constants import ENGLISH_SHORT_NAME
diff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.py
index c430cf23c..22356c4c5 100644
--- a/wger/nutrition/sync.py
+++ b/wger/nutrition/sync.py
@@ -43,11 +43,11 @@ from tqdm import tqdm
# wger
from wger.core.models.language import Language
-from wger.nutrition.consts import SyncMode
from wger.nutrition.api.endpoints import (
IMAGE_ENDPOINT,
INGREDIENTS_ENDPOINT,
)
+from wger.nutrition.consts import SyncMode
from wger.nutrition.extract_info.wger import extract_info_from_wger_api
from wger.nutrition.models import (
Image,
@@ -379,9 +379,11 @@ def export_ingredient_dump(
"""
# Import here to avoid circular imports
+ # Django
from django.core.files.base import File
from django.core.files.storage import default_storage
+ # wger
from wger.nutrition.api.endpoints import INGREDIENT_BULK_EXPORT_PATH
from wger.nutrition.api.serializers import IngredientSerializer
@@ -529,6 +531,7 @@ def download_ingredient_dump(
Returns the path to the downloaded file.
"""
+ # wger
from wger.nutrition.api.endpoints import INGREDIENT_BULK_EXPORT_PATH
dump_url = f'{remote_url}{settings.MEDIA_URL}{INGREDIENT_BULK_EXPORT_PATH}'
diff --git a/wger/nutrition/tasks.py b/wger/nutrition/tasks.py
index 03edf0ef2..aa1174ac2 100644
--- a/wger/nutrition/tasks.py
+++ b/wger/nutrition/tasks.py
@@ -30,8 +30,8 @@ from celery.schedules import crontab
from wger.celery_configuration import app
from wger.nutrition.api.endpoints import INGREDIENTS_ENDPOINT
from 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.py
index 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
# wger
from wger.core.tests.base_testcase import WgerTestCase
-from wger.nutrition.models import Ingredient
from wger.nutrition.consts import SyncMode
+from wger.nutrition.models import Ingredient
from 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 Library
import shutil
shutil.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()
+ # Django
from django.core.files.storage import default_storage
self.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):
+ # Django
from django.core.files.storage import default_storage
self.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 Library
import 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,
)