all tests migrated and improved
This commit is contained in:
parent
ad0d802e41
commit
76eeed1a77
@ -14,7 +14,7 @@
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/pytest/resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
|
@ -2,7 +2,6 @@ import json
|
||||
|
||||
import pytest
|
||||
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
@ -1,9 +1,4 @@
|
||||
import json
|
||||
|
||||
from cookbook.models import UserPreference
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
||||
import json
|
||||
|
||||
@ -12,8 +7,6 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, RecipeBookEntry
|
||||
|
||||
LIST_URL = 'api:userpreference-list'
|
||||
DETAIL_URL = 'api:userpreference-detail'
|
||||
|
@ -7,7 +7,7 @@ from django.contrib import auth
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Space, Recipe, Step, Ingredient, Food, Unit
|
||||
from cookbook.models import Space, Recipe, Step, Ingredient, Food, Unit, Storage
|
||||
|
||||
|
||||
# hack from https://github.com/raphaelm/django-scopes to disable scopes for all fixtures
|
||||
@ -61,8 +61,8 @@ def get_random_recipe(space_1, u1_s1):
|
||||
s1.ingredients.add(
|
||||
Ingredient.objects.create(
|
||||
amount=1,
|
||||
food=Food.objects.create(name=uuid.uuid4(), space=space_1,),
|
||||
unit=Unit.objects.create(name=uuid.uuid4(), space=space_1,),
|
||||
food=Food.objects.create(name=uuid.uuid4(), space=space_1, ),
|
||||
unit=Unit.objects.create(name=uuid.uuid4(), space=space_1, ),
|
||||
note=uuid.uuid4(),
|
||||
)
|
||||
)
|
||||
@ -70,8 +70,8 @@ def get_random_recipe(space_1, u1_s1):
|
||||
s2.ingredients.add(
|
||||
Ingredient.objects.create(
|
||||
amount=1,
|
||||
food=Food.objects.create(name=uuid.uuid4(), space=space_1,),
|
||||
unit=Unit.objects.create(name=uuid.uuid4(), space=space_1,),
|
||||
food=Food.objects.create(name=uuid.uuid4(), space=space_1, ),
|
||||
unit=Unit.objects.create(name=uuid.uuid4(), space=space_1, ),
|
||||
note=uuid.uuid4(),
|
||||
)
|
||||
)
|
||||
@ -89,6 +89,15 @@ def recipe_2_s1(space_1, u1_s1):
|
||||
return get_random_recipe(space_1, u1_s1)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ext_recipe_1_s1(space_1, u1_s1):
|
||||
r = get_random_recipe(space_1, u1_s1)
|
||||
r.internal = False
|
||||
r.link = 'test'
|
||||
r.save()
|
||||
return r
|
||||
|
||||
|
||||
# ---------------------- USER FIXTURES -----------------------
|
||||
# maybe better with factories but this is very explict so ...
|
||||
|
@ -0,0 +1,7 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
@ -1,57 +0,0 @@
|
||||
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):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEditsComment, self).setUp()
|
||||
|
||||
self.recipe = Recipe.objects.create(
|
||||
internal=True,
|
||||
working_time=1,
|
||||
waiting_time=1,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
self.comment = Comment.objects.create(
|
||||
text='TestStorage',
|
||||
created_by=auth.get_user(self.guest_client_1),
|
||||
recipe=self.recipe
|
||||
)
|
||||
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
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_edit_comment_permissions(self):
|
||||
r = self.anonymous_client.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.guest_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
r = self.guest_client_2.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.user_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.admin_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.superuser_client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
@ -1,5 +1,4 @@
|
||||
from cookbook.models import Food, Recipe, Storage, Unit
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from cookbook.models import Recipe, Storage
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from pytest_django.asserts import assertTemplateUsed
|
@ -1,68 +1,58 @@
|
||||
from cookbook.models import Storage
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
import pytest
|
||||
|
||||
|
||||
class TestEditsRecipe(TestViews):
|
||||
@pytest.fixture
|
||||
def storage_obj(a1_s1, space_1):
|
||||
return Storage.objects.create(
|
||||
name='TestStorage',
|
||||
method=Storage.DROPBOX,
|
||||
created_by=auth.get_user(a1_s1),
|
||||
token='test',
|
||||
username='test',
|
||||
password='test',
|
||||
space=space_1,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestEditsRecipe, self).setUp()
|
||||
|
||||
self.storage = Storage.objects.create(
|
||||
name='TestStorage',
|
||||
method=Storage.DROPBOX,
|
||||
created_by=auth.get_user(self.admin_client_1),
|
||||
token='test',
|
||||
username='test',
|
||||
password='test',
|
||||
)
|
||||
self.url = reverse('edit_storage', args=[self.storage.pk])
|
||||
def test_edit_storage(storage_obj, a1_s1, a1_s2):
|
||||
r = a1_s1.post(
|
||||
reverse('edit_storage', args={storage_obj.pk}),
|
||||
{
|
||||
'name': 'NewStorage',
|
||||
'password': '1234_pw',
|
||||
'token': '1234_token',
|
||||
'method': Storage.DROPBOX
|
||||
}
|
||||
)
|
||||
storage_obj.refresh_from_db()
|
||||
assert r.status_code == 200
|
||||
assert storage_obj.password == '1234_pw'
|
||||
assert storage_obj.token == '1234_token'
|
||||
|
||||
def test_edit_storage(self):
|
||||
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 = a1_s2.post(
|
||||
reverse('edit_storage', args={storage_obj.pk}),
|
||||
{
|
||||
'name': 'NewStorage',
|
||||
'password': '1234_pw',
|
||||
'token': '1234_token',
|
||||
'method': Storage.DROPBOX
|
||||
}
|
||||
)
|
||||
assert r.status_code == 404
|
||||
|
||||
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)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.guest_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.user_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.admin_client_1.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
r = self.superuser_client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 302],
|
||||
['a1_s1', 200],
|
||||
['g1_s2', 302],
|
||||
['u1_s2', 302],
|
||||
['a1_s2', 404],
|
||||
])
|
||||
def test_view_permission(arg, request, storage_obj):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('edit_storage', args={storage_obj.pk})).status_code == arg[1]
|
||||
|
28
cookbook/tests/other/test_url_import.py
Normal file
28
cookbook/tests/other/test_url_import.py
Normal file
@ -0,0 +1,28 @@
|
||||
import json
|
||||
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
|
||||
# TODO this test is really bad, need to find a better solution, also pytest does not like those paths
|
||||
# def test_ld_json():
|
||||
# with scopes_disabled():
|
||||
# test_list = [
|
||||
# {'file': 'resources/websites/ld_json_1.html', 'result_length': 3237},
|
||||
# {'file': 'resources/websites/ld_json_2.html', 'result_length': 1525},
|
||||
# {'file': 'resources/websites/ld_json_3.html', 'result_length': 1644},
|
||||
# {'file': 'resources/websites/ld_json_4.html', 'result_length': 1744},
|
||||
# {'file': 'resources/websites/ld_json_itemList.html', 'result_length': 3222},
|
||||
# {'file': 'resources/websites/ld_json_multiple.html', 'result_length': 1621},
|
||||
# {'file': 'resources/websites/micro_data_1.html', 'result_length': 1094},
|
||||
# {'file': 'resources/websites/micro_data_2.html', 'result_length': 1453},
|
||||
# {'file': 'resources/websites/micro_data_3.html', 'result_length': 1163},
|
||||
# {'file': 'resources/websites/micro_data_4.html', 'result_length': 4411},
|
||||
# ]
|
||||
#
|
||||
# for test in test_list:
|
||||
# with open(test['file'], 'rb') as file:
|
||||
# print(f'Testing {test["file"]} expecting length {test["result_length"]}')
|
||||
# parsed_content = json.loads(get_from_html(file.read(), 'test_url', None).content)
|
||||
# assert len(str(parsed_content)) == test['result_length']
|
||||
# file.close()
|
@ -1,7 +0,0 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
@ -1,7 +0,0 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
@ -1,30 +0,0 @@
|
||||
import json
|
||||
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
from cookbook.tests.test_setup import TestBase
|
||||
|
||||
|
||||
def test_ld_json():
|
||||
with scopes_disabled():
|
||||
test_list = [
|
||||
{'file': '../resources/websites/ld_json_1.html', 'result_length': 3237},
|
||||
{'file': '../resources/websites/ld_json_2.html', 'result_length': 1525},
|
||||
{'file': '../resources/websites/ld_json_3.html', 'result_length': 1644},
|
||||
{'file': '../resources/websites/ld_json_4.html', 'result_length': 1744},
|
||||
{'file': '../resources/websites/ld_json_itemList.html', 'result_length': 3222},
|
||||
{'file': '../resources/websites/ld_json_multiple.html', 'result_length': 1621},
|
||||
{'file': '../resources/websites/micro_data_1.html', 'result_length': 1094},
|
||||
{'file': '../resources/websites/micro_data_2.html', 'result_length': 1453},
|
||||
{'file': '../resources/websites/micro_data_3.html', 'result_length': 1163},
|
||||
{'file': '../resources/websites/micro_data_4.html', 'result_length': 4411},
|
||||
]
|
||||
|
||||
for test in test_list:
|
||||
with open(test['file'], 'rb') as file:
|
||||
print(f'Testing {test["file"]} expecting length {test["result_length"]}')
|
||||
parsed_content = json.loads(get_from_html(file.read(), 'test_url', None).content)
|
||||
assert len(str(parsed_content)) == test['result_length']
|
||||
file.close()
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@ -1,70 +0,0 @@
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from cookbook.models import Space
|
||||
|
||||
|
||||
class TestBase(TestCase):
|
||||
superuser_client = None
|
||||
anonymous_client = None
|
||||
|
||||
guest_client_1 = None
|
||||
guest_client_2 = None
|
||||
user_client_1 = None
|
||||
user_client_2 = None
|
||||
admin_client_1 = None
|
||||
admin_client_2 = None
|
||||
|
||||
s2_guest_client_1 = None
|
||||
s2_user_client_1 = None
|
||||
s2_admin_client_1 = None
|
||||
s2_superuser_client = None
|
||||
|
||||
def create_login_user(self, name, group, space, superuser=False):
|
||||
client = Client()
|
||||
setattr(self, name, client)
|
||||
client.force_login(User.objects.get_or_create(username=name)[0])
|
||||
user = auth.get_user(getattr(self, name))
|
||||
user.groups.add(Group.objects.get(name=group))
|
||||
self.assertTrue(user.is_authenticated)
|
||||
if superuser:
|
||||
user.is_superuser = True
|
||||
|
||||
user.userpreference.space = space
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def setUp(self):
|
||||
# users for space 1
|
||||
space_1 = Space.objects.create(name='space 1')
|
||||
|
||||
self.create_login_user('admin_client_1', 'admin', space_1)
|
||||
self.create_login_user('admin_client_2', 'admin', space_1)
|
||||
|
||||
self.create_login_user('user_client_1', 'user', space_1)
|
||||
self.create_login_user('user_client_2', 'user', space_1)
|
||||
|
||||
self.create_login_user('guest_client_1', 'guest', space_1)
|
||||
self.create_login_user('guest_client_2', 'guest', space_1)
|
||||
|
||||
self.anonymous_client = Client()
|
||||
|
||||
self.create_login_user('superuser_client', 'admin', space_1, superuser=True)
|
||||
|
||||
# users for space 2
|
||||
space_2 = Space.objects.create(name='space 2')
|
||||
self.create_login_user('s2_admin_client_1', 'admin', space_2)
|
||||
self.create_login_user('s2_user_client_1', 'user', space_2)
|
||||
self.create_login_user('s2_guest_client_1', 'guest', space_2)
|
||||
self.create_login_user('s2_superuser_client', 'admin', space_2, superuser=True)
|
||||
|
||||
def batch_requests(self, clients, url, method='get', payload={}, content_type=''):
|
||||
for c in clients:
|
||||
if method == 'get':
|
||||
r = c[0].get(url)
|
||||
self.assertEqual(
|
||||
r.status_code,
|
||||
c[1],
|
||||
msg=f'GET request failed for user {auth.get_user(c[0])} when testing url {url}' # noqa: E501
|
||||
)
|
@ -0,0 +1,7 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
@ -1,5 +0,0 @@
|
||||
from cookbook.tests.test_setup import TestBase
|
||||
|
||||
|
||||
class TestViews(TestBase):
|
||||
pass
|
@ -1,43 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from cookbook.models import Recipe
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class TestViewsApi(TestViews):
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
['g1_s2', 302],
|
||||
['u1_s2', 404],
|
||||
['a1_s2', 404],
|
||||
])
|
||||
def test_external_link_permission(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('api_get_external_file_link', args=[ext_recipe_1_s1.pk])).status_code == arg[1]
|
||||
|
||||
def test_external_link_permission(self):
|
||||
recipe = Recipe.objects.create(
|
||||
internal=False,
|
||||
link='test',
|
||||
working_time=1,
|
||||
waiting_time=1,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
url = reverse('api_get_external_file_link', args=[recipe.pk])
|
||||
|
||||
self.assertEqual(self.anonymous_client.get(url).status_code, 302)
|
||||
self.assertEqual(self.guest_client_1.get(url).status_code, 302)
|
||||
self.assertEqual(self.user_client_1.get(url).status_code, 200)
|
||||
self.assertEqual(self.admin_client_1.get(url).status_code, 200)
|
||||
self.assertEqual(self.superuser_client.get(url).status_code, 200)
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 200],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
['g1_s2', 404],
|
||||
['u1_s2', 404],
|
||||
['a1_s2', 404],
|
||||
])
|
||||
def test_external_link_permission(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('api_get_recipe_file', args=[ext_recipe_1_s1.pk])).status_code == arg[1]
|
||||
|
||||
def test_file_permission(self):
|
||||
recipe = Recipe.objects.create(
|
||||
internal=False,
|
||||
link='test',
|
||||
working_time=1,
|
||||
waiting_time=1,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
url = reverse('api_get_recipe_file', args=[recipe.pk])
|
||||
|
||||
self.assertEqual(self.anonymous_client.get(url).status_code, 302)
|
||||
self.assertEqual(self.guest_client_1.get(url).status_code, 200)
|
||||
|
||||
def test_sync_permission(self):
|
||||
url = reverse('api_sync')
|
||||
|
||||
self.assertEqual(self.anonymous_client.get(url).status_code, 302)
|
||||
self.assertEqual(self.guest_client_1.get(url).status_code, 302)
|
||||
|
@ -1,138 +1,121 @@
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class TestViewsGeneral(TestViews):
|
||||
def test_index():
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_index(self):
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_search(self):
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
def test_search():
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_view(self):
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_books(self):
|
||||
url = reverse('view_books')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 302),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
def test_view():
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_plan(self):
|
||||
url = reverse('view_plan')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 302),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
|
||||
def test_plan_entry(self):
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_books(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_books')).status_code == arg[1]
|
||||
|
||||
def test_shopping(self):
|
||||
url = reverse('view_shopping')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 302),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
|
||||
def test_settings(self):
|
||||
url = reverse('view_settings')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 200),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_plan(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_plan')).status_code == arg[1]
|
||||
|
||||
def test_history(self):
|
||||
url = reverse('view_history')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 200),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
|
||||
def test_system(self):
|
||||
url = reverse('view_system')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 302),
|
||||
(self.user_client_1, 302),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
def test_plan_entry():
|
||||
# TODO add appropriate test
|
||||
pass
|
||||
|
||||
def test_setup(self):
|
||||
url = reverse('view_setup')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 302),
|
||||
(self.user_client_1, 302),
|
||||
(self.admin_client_1, 302),
|
||||
(self.superuser_client, 302)
|
||||
],
|
||||
url
|
||||
)
|
||||
|
||||
def test_markdown_info(self):
|
||||
url = reverse('docs_markdown')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 200),
|
||||
(self.guest_client_1, 200),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_shopping(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_shopping')).status_code == arg[1]
|
||||
|
||||
def test_api_info(self):
|
||||
url = reverse('docs_api')
|
||||
self.batch_requests(
|
||||
[
|
||||
(self.anonymous_client, 302),
|
||||
(self.guest_client_1, 200),
|
||||
(self.user_client_1, 200),
|
||||
(self.admin_client_1, 200),
|
||||
(self.superuser_client, 200)
|
||||
],
|
||||
url
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 200],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_settings(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_settings')).status_code == arg[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 200],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_history(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_history')).status_code == arg[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 302],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_system(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_system')).status_code == arg[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 302],
|
||||
['u1_s1', 302],
|
||||
['a1_s1', 302],
|
||||
])
|
||||
def test_setup(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('view_setup')).status_code == arg[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 200],
|
||||
['g1_s1', 200],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_markdown_doc(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('docs_markdown')).status_code == arg[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 302],
|
||||
['g1_s1', 200],
|
||||
['u1_s1', 200],
|
||||
['a1_s1', 200],
|
||||
])
|
||||
def test_api_info(arg, request, ext_recipe_1_s1):
|
||||
c = request.getfixturevalue(arg[0])
|
||||
assert c.get(reverse('docs_api')).status_code == arg[1]
|
||||
|
@ -1,52 +1,45 @@
|
||||
import uuid
|
||||
|
||||
from cookbook.helper.permission_helper import share_link_valid
|
||||
from cookbook.models import Recipe, ShareLink
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.helper.permission_helper import share_link_valid
|
||||
from cookbook.models import ShareLink
|
||||
|
||||
|
||||
class TestViewsGeneral(TestViews):
|
||||
def test_share(recipe_1_s1, u1_s1, a_u):
|
||||
with scopes_disabled():
|
||||
url = reverse('view_recipe', kwargs={'pk': recipe_1_s1.pk})
|
||||
r = u1_s1.get(url)
|
||||
assert r.status_code == 200
|
||||
|
||||
def test_share(self):
|
||||
internal_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=True,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
r = a_u.get(url)
|
||||
assert r.status_code == 302
|
||||
|
||||
url = reverse('view_recipe', kwargs={'pk': internal_recipe.pk})
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
url = reverse('new_share_link', kwargs={'pk': internal_recipe.pk})
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
share = ShareLink.objects.filter(recipe=internal_recipe).first()
|
||||
self.assertIsNotNone(share)
|
||||
self.assertTrue(share_link_valid(internal_recipe, share.uuid))
|
||||
url = reverse('new_share_link', kwargs={'pk': recipe_1_s1.pk})
|
||||
r = u1_s1.get(url)
|
||||
assert r.status_code == 302
|
||||
share = ShareLink.objects.filter(recipe=recipe_1_s1).first()
|
||||
assert share
|
||||
assert share_link_valid(recipe_1_s1, share.uuid)
|
||||
|
||||
url = reverse(
|
||||
'view_recipe',
|
||||
kwargs={'pk': internal_recipe.pk, 'share': share.uuid}
|
||||
kwargs={'pk': recipe_1_s1.pk, 'share': share.uuid}
|
||||
)
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
r = a_u.get(url)
|
||||
assert r.status_code == 200
|
||||
|
||||
url = reverse(
|
||||
'view_recipe',
|
||||
kwargs={'pk': (internal_recipe.pk + 1), 'share': share.uuid}
|
||||
kwargs={'pk': (recipe_1_s1.pk + 1), 'share': share.uuid}
|
||||
)
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 404)
|
||||
r = a_u.get(url)
|
||||
assert r.status_code == 404
|
||||
|
||||
url = reverse(
|
||||
'view_recipe',
|
||||
kwargs={'pk': internal_recipe.pk, 'share': uuid.uuid4()}
|
||||
kwargs={'pk': recipe_1_s1.pk, 'share': uuid.uuid4()}
|
||||
)
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
r = a_u.get(url)
|
||||
assert r.status_code == 302
|
||||
|
@ -13,7 +13,7 @@ from django.core.exceptions import FieldError, ValidationError
|
||||
from django.core.files import File
|
||||
from django.db.models import Q
|
||||
from django.http import FileResponse, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.utils.translation import gettext as _
|
||||
from icalendar import Calendar, Event
|
||||
from rest_framework import decorators, viewsets, status
|
||||
@ -416,7 +416,7 @@ def update_recipe_links(recipe):
|
||||
|
||||
@group_required('user')
|
||||
def get_external_file_link(request, recipe_id):
|
||||
recipe = Recipe.objects.filter(space=request.user.userpreference.space).get(id=recipe_id)
|
||||
recipe = get_object_or_404(Recipe, pk=recipe_id, space=request.space)
|
||||
if not recipe.link:
|
||||
update_recipe_links(recipe)
|
||||
|
||||
@ -425,7 +425,7 @@ def get_external_file_link(request, recipe_id):
|
||||
|
||||
@group_required('guest')
|
||||
def get_recipe_file(request, recipe_id):
|
||||
recipe = Recipe.objects.filter(space=request.user.userpreference.space).get(id=recipe_id)
|
||||
recipe = get_object_or_404(Recipe, pk=recipe_id, space=request.space)
|
||||
if recipe.storage:
|
||||
return FileResponse(get_recipe_provider(recipe).get_file(recipe))
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user