tests/edits
This commit is contained in:
parent
61daf9d5c9
commit
bc1f28eda6
@ -1,8 +1,7 @@
|
|||||||
from django.contrib import auth
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from cookbook.models import Comment, Recipe
|
from cookbook.models import Comment, Recipe
|
||||||
from cookbook.tests.views.test_views import TestViews
|
from cookbook.tests.views.test_views import TestViews
|
||||||
|
from django.contrib import auth
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
class TestEditsComment(TestViews):
|
class TestEditsComment(TestViews):
|
||||||
@ -25,7 +24,17 @@ class TestEditsComment(TestViews):
|
|||||||
self.url = reverse('edit_comment', args=[self.comment.pk])
|
self.url = reverse('edit_comment', args=[self.comment.pk])
|
||||||
|
|
||||||
def test_new_comment(self):
|
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)
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
def test_edit_comment_permissions(self):
|
def test_edit_comment_permissions(self):
|
||||||
|
@ -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.contrib import auth
|
||||||
from django.urls import reverse
|
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):
|
class TestEditsRecipe(TestViews):
|
||||||
|
|
||||||
@ -70,7 +69,17 @@ class TestEditsRecipe(TestViews):
|
|||||||
r = self.anonymous_client.get(url)
|
r = self.anonymous_client.get(url)
|
||||||
self.assertEqual(r.status_code, 403)
|
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)
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
recipe = Recipe.objects.get(pk=recipe.pk)
|
recipe = Recipe.objects.get(pk=recipe.pk)
|
||||||
@ -79,18 +88,39 @@ class TestEditsRecipe(TestViews):
|
|||||||
Food.objects.create(name='Egg')
|
Food.objects.create(name='Egg')
|
||||||
Unit.objects.create(name='g')
|
Unit.objects.create(name='g')
|
||||||
|
|
||||||
r = self.user_client_1.put(url, {'name': 'Changed', 'working_time': 15, 'waiting_time': 15, 'keywords': [],
|
r = self.user_client_1.put(
|
||||||
'steps': [{'ingredients': [
|
url,
|
||||||
{"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"}
|
'name': 'Changed',
|
||||||
]}]}, content_type='application/json')
|
'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(r.status_code, 200)
|
||||||
self.assertEqual(2, recipe.steps.first().ingredients.count())
|
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
|
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
|
pass # TODO new image tests
|
||||||
|
|
||||||
def test_external_recipe_update(self):
|
def test_external_recipe_update(self):
|
||||||
@ -117,7 +147,10 @@ class TestEditsRecipe(TestViews):
|
|||||||
r = self.anonymous_client.get(url)
|
r = self.anonymous_client.get(url)
|
||||||
self.assertEqual(r.status_code, 302)
|
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()
|
recipe.refresh_from_db()
|
||||||
self.assertEqual(recipe.working_time, 15)
|
self.assertEqual(recipe.working_time, 15)
|
||||||
self.assertEqual(recipe.waiting_time, 15)
|
self.assertEqual(recipe.waiting_time, 15)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from django.contrib import auth
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from cookbook.models import Storage
|
from cookbook.models import Storage
|
||||||
from cookbook.tests.views.test_views import TestViews
|
from cookbook.tests.views.test_views import TestViews
|
||||||
|
from django.contrib import auth
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
class TestEditsRecipe(TestViews):
|
class TestEditsRecipe(TestViews):
|
||||||
@ -21,13 +20,36 @@ class TestEditsRecipe(TestViews):
|
|||||||
self.url = reverse('edit_storage', args=[self.storage.pk])
|
self.url = reverse('edit_storage', args=[self.storage.pk])
|
||||||
|
|
||||||
def test_edit_storage(self):
|
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.storage.refresh_from_db()
|
||||||
self.assertEqual(self.storage.password, '1234_pw')
|
self.assertEqual(self.storage.password, '1234_pw')
|
||||||
self.assertEqual(self.storage.token, '1234_token')
|
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'})
|
r = self.admin_client_1.post(
|
||||||
self.assertFormError(r, 'form', 'method', ['Select a valid choice. not_a_valid_method is not one of the available choices.'])
|
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):
|
def test_edit_storage_permissions(self):
|
||||||
r = self.anonymous_client.get(self.url)
|
r = self.anonymous_client.get(self.url)
|
||||||
|
Loading…
Reference in New Issue
Block a user