diff --git a/cookbook/tests/edits/test_edits_recipe.py b/cookbook/tests/edits/test_edits_recipe.py index bc6af029..724023e4 100644 --- a/cookbook/tests/edits/test_edits_recipe.py +++ b/cookbook/tests/edits/test_edits_recipe.py @@ -1,7 +1,7 @@ from django.contrib import auth from django.urls import reverse -from cookbook.models import Recipe, RecipeIngredient, Ingredient, Unit +from cookbook.models import Recipe, RecipeIngredient, Ingredient, Unit, Storage from cookbook.tests.views.test_views import TestViews @@ -97,3 +97,32 @@ class TestEditsRecipe(TestViews): with open('cookbook/tests/resources/image.png', 'rb') as file: r = self.client.post(url, {'name': "Changed", 'working_time': 15, 'waiting_time': 15, 'image': file}) self.assertEqual(r.status_code, 200) + + def test_external_recipe_update(self): + storage = Storage.objects.create( + name='TestStorage', + method=Storage.DROPBOX, + created_by=auth.get_user(self.client), + token='test', + username='test', + password='test', + ) + + recipe = Recipe.objects.create( + name='Test', + created_by=auth.get_user(self.client), + storage=storage, + ) + + url = reverse('edit_external_recipe', args=[recipe.pk]) + + r = self.client.get(url) + self.assertEqual(r.status_code, 200) + + r = self.anonymous_client.get(url) + self.assertEqual(r.status_code, 302) + + r = self.client.post(url, {'name': 'Test', 'working_time': 15, 'waiting_time': 15, }) + recipe.refresh_from_db() + self.assertEqual(recipe.working_time, 15) + self.assertEqual(recipe.waiting_time, 15) diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 780acdbd..b933d728 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -277,13 +277,11 @@ class ExternalRecipeUpdate(LoginRequiredMixin, UpdateView): old_recipe = Recipe.objects.get(pk=self.object.pk) if not old_recipe.name == self.object.name: if self.object.storage.method == Storage.DROPBOX: - Dropbox.rename_file(old_recipe, - self.object.name) # TODO central location to handle storage type switches + Dropbox.rename_file(old_recipe, self.object.name) # TODO central location to handle storage type switches if self.object.storage.method == Storage.NEXTCLOUD: Nextcloud.rename_file(old_recipe, self.object.name) - self.object.file_path = os.path.dirname(self.object.file_path) + '/' + self.object.name + \ - os.path.splitext(self.object.file_path)[1] + self.object.file_path = os.path.dirname(self.object.file_path) + '/' + self.object.name + os.path.splitext(self.object.file_path)[1] messages.add_message(self.request, messages.SUCCESS, _('Changes saved!')) return super(ExternalRecipeUpdate, self).form_valid(form)