tests/edits

This commit is contained in:
Tobias Lindenberg 2021-01-10 14:23:52 +01:00
parent 61daf9d5c9
commit bc1f28eda6
3 changed files with 86 additions and 22 deletions

View File

@ -1,8 +1,7 @@
from django.contrib import auth
from django.urls import reverse
from cookbook.models import Comment, Recipe
from cookbook.tests.views.test_views import TestViews
from django.contrib import auth
from django.urls import reverse
class TestEditsComment(TestViews):
@ -25,7 +24,17 @@ class TestEditsComment(TestViews):
self.url = reverse('edit_comment', args=[self.comment.pk])
def test_new_comment(self):
r = self.user_client_1.post(reverse('view_recipe', args=[self.recipe.pk]), {'comment-text': 'Test Comment Text', 'comment-recipe': self.recipe.pk})
r = self.user_client_1.post(
reverse(
'view_recipe',
args=[self.recipe.pk]
),
{
'comment-text': 'Test Comment Text',
'comment-recipe': self.recipe.pk
}
)
self.assertEqual(r.status_code, 200)
def test_edit_comment_permissions(self):

View File

@ -1,9 +1,8 @@
from cookbook.models import Food, Recipe, Storage, Unit
from cookbook.tests.views.test_views import TestViews
from django.contrib import auth
from django.urls import reverse
from cookbook.models import Recipe, Ingredient, Unit, Storage, Food
from cookbook.tests.views.test_views import TestViews
class TestEditsRecipe(TestViews):
@ -70,7 +69,17 @@ class TestEditsRecipe(TestViews):
r = self.anonymous_client.get(url)
self.assertEqual(r.status_code, 403)
r = self.user_client_1.put(url, {'name': 'Changed', 'working_time': 15, 'waiting_time': 15, 'keywords': [], 'steps': []}, content_type='application/json')
r = self.user_client_1.put(
url,
{
'name': 'Changed',
'working_time': 15,
'waiting_time': 15,
'keywords': [],
'steps': []
},
content_type='application/json'
)
self.assertEqual(r.status_code, 200)
recipe = Recipe.objects.get(pk=recipe.pk)
@ -79,18 +88,39 @@ class TestEditsRecipe(TestViews):
Food.objects.create(name='Egg')
Unit.objects.create(name='g')
r = self.user_client_1.put(url, {'name': 'Changed', 'working_time': 15, 'waiting_time': 15, 'keywords': [],
'steps': [{'ingredients': [
{"food": {"name": "test food"}, "unit": {"name": "test unit"}, 'amount': 12, 'note': "test note"},
{"food": {"name": "test food 2"}, "unit": {"name": "test unit 2"}, 'amount': 42, 'note': "test note 2"}
]}]}, content_type='application/json')
r = self.user_client_1.put(
url,
{
'name': 'Changed',
'working_time': 15,
'waiting_time': 15,
'keywords': [],
'steps': [
{
'ingredients': [
{
'food': {'name': 'test food'},
'unit': {'name': 'test unit'},
'amount': 12, 'note': 'test note'
},
{
'food': {'name': 'test food 2'},
'unit': {'name': 'test unit 2'},
'amount': 42, 'note': 'test note 2'
}
]
}
]
},
content_type='application/json'
)
self.assertEqual(r.status_code, 200)
self.assertEqual(2, recipe.steps.first().ingredients.count())
with open('cookbook/tests/resources/image.jpg', 'rb') as file:
with open('cookbook/tests/resources/image.jpg', 'rb') as file: # noqa: E501,F841
pass # TODO new image tests
with open('cookbook/tests/resources/image.png', 'rb') as file:
with open('cookbook/tests/resources/image.png', 'rb') as file: # noqa: E501,F841
pass # TODO new image tests
def test_external_recipe_update(self):
@ -117,7 +147,10 @@ class TestEditsRecipe(TestViews):
r = self.anonymous_client.get(url)
self.assertEqual(r.status_code, 302)
r = self.user_client_1.post(url, {'name': 'Test', 'working_time': 15, 'waiting_time': 15, })
r = self.user_client_1.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)

View File

@ -1,8 +1,7 @@
from django.contrib import auth
from django.urls import reverse
from cookbook.models import Storage
from cookbook.tests.views.test_views import TestViews
from django.contrib import auth
from django.urls import reverse
class TestEditsRecipe(TestViews):
@ -21,13 +20,36 @@ class TestEditsRecipe(TestViews):
self.url = reverse('edit_storage', args=[self.storage.pk])
def test_edit_storage(self):
r = self.admin_client_1.post(self.url, {'name': 'NewStorage', 'password': '1234_pw', 'token': '1234_token', 'method': Storage.DROPBOX})
r = self.admin_client_1.post(
self.url,
{
'name': 'NewStorage',
'password': '1234_pw',
'token': '1234_token',
'method': Storage.DROPBOX
}
)
self.storage.refresh_from_db()
self.assertEqual(self.storage.password, '1234_pw')
self.assertEqual(self.storage.token, '1234_token')
r = self.admin_client_1.post(self.url, {'name': 'NewStorage', 'password': '1234_pw', 'token': '1234_token', 'method': 'not_a_valid_method'})
self.assertFormError(r, 'form', 'method', ['Select a valid choice. not_a_valid_method is not one of the available choices.'])
r = self.admin_client_1.post(
self.url,
{
'name': 'NewStorage',
'password': '1234_pw',
'token': '1234_token',
'method': 'not_a_valid_method'
}
)
self.assertFormError(
r,
'form',
'method',
[
'Select a valid choice. not_a_valid_method is not one of the available choices.' # noqa: E501
]
)
def test_edit_storage_permissions(self):
r = self.anonymous_client.get(self.url)