mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-24 02:39:20 -05:00
remove unused imports, variables and commented code
from tests
This commit is contained in:
@@ -7,8 +7,6 @@ from django.utils import timezone
|
||||
from django_scopes import scopes_disabled
|
||||
from oauth2_provider.models import AccessToken
|
||||
|
||||
from cookbook.models import ViewLog
|
||||
|
||||
LIST_URL = 'api:accesstoken-list'
|
||||
DETAIL_URL = 'api:accesstoken-detail'
|
||||
|
||||
|
||||
@@ -35,11 +35,6 @@ register(FoodFactory, 'obj_3', space=LazyFixture('space_2'))
|
||||
register(SupermarketCategoryFactory, 'cat_1', space=LazyFixture('space_1'))
|
||||
|
||||
|
||||
# @pytest.fixture
|
||||
# def true():
|
||||
# return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def false():
|
||||
return False
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
# test create
|
||||
# test create units
|
||||
# test amounts
|
||||
# test create wrong space
|
||||
# test sharing
|
||||
# test delete
|
||||
# test delete checked (nothing should happen)
|
||||
# test delete not shared (nothing happens)
|
||||
# test delete shared
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
@@ -15,7 +5,6 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scope, scopes_disabled
|
||||
|
||||
from cookbook.models import Food, ShoppingListEntry
|
||||
from cookbook.tests.factories import FoodFactory
|
||||
|
||||
SHOPPING_LIST_URL = 'api:shoppinglistentry-list'
|
||||
@@ -80,8 +69,8 @@ def test_shopping_food_share(u1_s1, u2_s1, food, space_1):
|
||||
user1 = auth.get_user(u1_s1)
|
||||
user2 = auth.get_user(u2_s1)
|
||||
food2 = FoodFactory(space=space_1)
|
||||
r = u1_s1.put(reverse(SHOPPING_FOOD_URL, args={food.id}))
|
||||
r = u2_s1.put(reverse(SHOPPING_FOOD_URL, args={food2.id}))
|
||||
u1_s1.put(reverse(SHOPPING_FOOD_URL, args={food.id}))
|
||||
u2_s1.put(reverse(SHOPPING_FOOD_URL, args={food2.id}))
|
||||
sl_1 = json.loads(u1_s1.get(reverse(SHOPPING_LIST_URL)).content)
|
||||
sl_2 = json.loads(u2_s1.get(reverse(SHOPPING_LIST_URL)).content)
|
||||
assert len(sl_1) == 1
|
||||
|
||||
@@ -2,13 +2,10 @@ import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.helper.permission_helper import switch_user_active_space
|
||||
from cookbook.models import Ingredient, Step, InviteLink, UserSpace
|
||||
from cookbook.models import InviteLink
|
||||
|
||||
LIST_URL = 'api:invitelink-list'
|
||||
DETAIL_URL = 'api:invitelink-detail'
|
||||
|
||||
@@ -25,6 +25,7 @@ if (Keyword.node_order_by):
|
||||
else:
|
||||
node_location = 'last-child'
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def obj_1(space_1):
|
||||
return Keyword.objects.get_or_create(name='test_1', space=space_1)[0]
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scope, scopes_disabled
|
||||
|
||||
from cookbook.models import Food, MealPlan, MealType
|
||||
from cookbook.models import MealPlan, MealType
|
||||
from cookbook.tests.factories import RecipeFactory
|
||||
|
||||
LIST_URL = 'api:mealplan-list'
|
||||
@@ -149,7 +149,7 @@ def test_add_with_shopping(u1_s1, meal_type):
|
||||
space = meal_type.space
|
||||
with scope(space=space):
|
||||
recipe = RecipeFactory.create(space=space)
|
||||
r = u1_s1.post(
|
||||
u1_s1.post(
|
||||
reverse(LIST_URL),
|
||||
{'recipe': {'id': recipe.id, 'name': recipe.name, 'keywords': []}, 'meal_type': {'id': meal_type.id, 'name': meal_type.name},
|
||||
'from_date': (datetime.now()).strftime("%Y-%m-%d"), 'to_date': (datetime.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test', 'shared': [], 'addshopping': True},
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Food, MealType
|
||||
from cookbook.models import MealType
|
||||
|
||||
LIST_URL = 'api:mealtype-list'
|
||||
DETAIL_URL = 'api:mealtype-detail'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Food, MealType, PropertyType, Property
|
||||
from cookbook.models import MealType, Property, PropertyType
|
||||
|
||||
LIST_URL = 'api:property-list'
|
||||
DETAIL_URL = 'api:property-detail'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Food, MealType, PropertyType
|
||||
from cookbook.models import MealType, PropertyType
|
||||
|
||||
LIST_URL = 'api:propertytype-list'
|
||||
DETAIL_URL = 'api:propertytype-detail'
|
||||
|
||||
@@ -67,7 +67,8 @@ def test_share_permission(recipe_1_s1, u1_s1, u1_s2, u2_s1, a_u):
|
||||
share = ShareLink.objects.filter(recipe=recipe_1_s1).first()
|
||||
assert a_u.get(reverse(DETAIL_URL, args=[recipe_1_s1.pk]) + f'?share={share.uuid}').status_code == 200
|
||||
assert u1_s1.get(reverse(DETAIL_URL, args=[recipe_1_s1.pk]) + f'?share={share.uuid}').status_code == 200
|
||||
assert u1_s2.get(reverse(DETAIL_URL, args=[recipe_1_s1.pk]) + f'?share={share.uuid}').status_code == 404 # TODO fix in https://github.com/TandoorRecipes/recipes/issues/1238
|
||||
# TODO fix in https://github.com/TandoorRecipes/recipes/issues/1238
|
||||
assert u1_s2.get(reverse(DETAIL_URL, args=[recipe_1_s1.pk]) + f'?share={share.uuid}').status_code == 404
|
||||
|
||||
recipe_1_s1.created_by = auth.get_user(u1_s1)
|
||||
recipe_1_s1.private = True
|
||||
@@ -100,7 +101,6 @@ def test_update(arg, request, recipe_1_s1):
|
||||
j,
|
||||
content_type='application/json'
|
||||
)
|
||||
response = json.loads(r.content)
|
||||
assert r.status_code == arg[1]
|
||||
if r.status_code == 200:
|
||||
validate_recipe(j, json.loads(r.content))
|
||||
|
||||
@@ -48,8 +48,6 @@ def test_list_filter(obj_1, obj_2, u1_s1):
|
||||
assert r.status_code == 200
|
||||
response = json.loads(r.content)
|
||||
assert len(response) == 2
|
||||
# RecipeBooks model is unsorted - this isn't a reliable test
|
||||
# assert response[0]['name'] == obj_1.name
|
||||
|
||||
response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?limit=1').content)
|
||||
assert len(response) == 1
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import json
|
||||
|
||||
import factory
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
from pytest_factoryboy import LazyFixture, register
|
||||
|
||||
from cookbook.tests.factories import RecipeFactory
|
||||
|
||||
@@ -18,7 +16,7 @@ def recipe(request, space_1, u1_s1):
|
||||
params = request.param # request.param is a magic variable
|
||||
except AttributeError:
|
||||
params = {}
|
||||
step_recipe = params.get('steps__count', 1)
|
||||
# step_recipe = params.get('steps__count', 1) # TODO add tests for step recipes
|
||||
steps__recipe_count = params.get('steps__recipe_count', 0)
|
||||
steps__food_recipe_count = params.get('steps__food_recipe_count', {})
|
||||
created_by = params.get('created_by', auth.get_user(u1_s1))
|
||||
@@ -26,6 +24,7 @@ def recipe(request, space_1, u1_s1):
|
||||
return RecipeFactory.create(
|
||||
steps__recipe_count=steps__recipe_count,
|
||||
steps__food_recipe_count=steps__food_recipe_count,
|
||||
# steps__step_recipe=step_recipe, # TODO add tests for step recipes
|
||||
created_by=created_by,
|
||||
space=space_1,
|
||||
)
|
||||
@@ -56,7 +55,7 @@ def test_get_related_recipes(request, arg, recipe, related_count, u1_s1, space_2
|
||||
({'steps__food_recipe_count': {'step': 0, 'count': 1}}), # shopping list from recipe with food recipe
|
||||
({'steps__food_recipe_count': {'step': 0, 'count': 1}, 'steps__recipe_count': 1}), # shopping list from recipe with StepRecipe and food recipe
|
||||
], indirect=['recipe'])
|
||||
def test_related_mixed_space(request, recipe, u1_s2, space_2):
|
||||
def test_related_mixed_space(request, recipe, u1_s2, space_2):
|
||||
with scopes_disabled():
|
||||
recipe.space = space_2
|
||||
recipe.save()
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, ShoppingList, Storage, Sync, SyncLog
|
||||
from cookbook.models import ShoppingList
|
||||
|
||||
LIST_URL = 'api:shoppinglist-list'
|
||||
DETAIL_URL = 'api:shoppinglist-detail'
|
||||
|
||||
@@ -2,7 +2,6 @@ import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.forms import model_to_dict
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import json
|
||||
from datetime import timedelta
|
||||
|
||||
import factory
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.forms import model_to_dict
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django_scopes import scopes_disabled
|
||||
from pytest_factoryboy import LazyFixture, register
|
||||
|
||||
from cookbook.models import ShoppingListEntry
|
||||
from cookbook.tests.factories import ShoppingListEntryFactory
|
||||
@@ -46,7 +43,7 @@ def test_list_permission(arg, request):
|
||||
assert c.get(reverse(LIST_URL)).status_code == arg[1]
|
||||
|
||||
|
||||
def test_list_space(sle, u1_s1, u1_s2, space_2):
|
||||
def test_list_space(sle, u1_s1, u1_s2, space_2):
|
||||
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 10
|
||||
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 0
|
||||
|
||||
@@ -169,7 +166,7 @@ def test_sharing(request, shared, count, sle_2, sle, u1_s1):
|
||||
assert len(r) == count
|
||||
# count unchecked entries
|
||||
if not x.status_code == 404:
|
||||
count = count-1
|
||||
count = count - 1
|
||||
assert [x['checked'] for x in r].count(False) == count
|
||||
# test shared user can delete
|
||||
x = shared_client.delete(
|
||||
@@ -182,13 +179,12 @@ def test_sharing(request, shared, count, sle_2, sle, u1_s1):
|
||||
assert len(r) == count
|
||||
# count unchecked entries
|
||||
if not x.status_code == 404:
|
||||
count = count-1
|
||||
count = count - 1
|
||||
assert [x['checked'] for x in r].count(False) == count
|
||||
|
||||
|
||||
def test_completed(sle, u1_s1):
|
||||
# check 1 entry
|
||||
#
|
||||
u1_s1.patch(
|
||||
reverse(DETAIL_URL, args={sle[0].id}),
|
||||
{'checked': True},
|
||||
@@ -199,7 +195,7 @@ def test_completed(sle, u1_s1):
|
||||
# count unchecked entries
|
||||
assert [x['checked'] for x in r].count(False) == 9
|
||||
# confirm completed_at is populated
|
||||
assert [(x['completed_at'] != None) for x in r if x['checked']].count(True) == 1
|
||||
assert [(x['completed_at'] is not None) for x in r if x['checked']].count(True) == 1
|
||||
|
||||
assert len(json.loads(u1_s1.get(f'{reverse(LIST_URL)}?checked=0').content)) == 9
|
||||
assert len(json.loads(u1_s1.get(f'{reverse(LIST_URL)}?checked=1').content)) == 1
|
||||
@@ -213,7 +209,7 @@ def test_completed(sle, u1_s1):
|
||||
r = json.loads(u1_s1.get(reverse(LIST_URL)).content)
|
||||
assert [x['checked'] for x in r].count(False) == 10
|
||||
# confirm completed_at value cleared
|
||||
assert [(x['completed_at'] != None) for x in r if x['checked']].count(True) == 0
|
||||
assert [(x['completed_at'] is not None) for x in r if x['checked']].count(True) == 0
|
||||
|
||||
|
||||
def test_recent(sle, u1_s1):
|
||||
|
||||
@@ -2,11 +2,10 @@ import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.forms import model_to_dict
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, Storage, Sync, SyncLog, ShoppingList, ShoppingListEntry, Food, ShoppingListRecipe
|
||||
from cookbook.models import ShoppingList, ShoppingListRecipe
|
||||
|
||||
LIST_URL = 'api:shoppinglistrecipe-list'
|
||||
DETAIL_URL = 'api:shoppinglistrecipe-detail'
|
||||
@@ -21,7 +20,7 @@ def obj_1(space_1, u1_s1, recipe_1_s1):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def obj_2(space_1, u1_s1,recipe_1_s1):
|
||||
def obj_2(space_1, u1_s1, recipe_1_s1):
|
||||
r = ShoppingListRecipe.objects.create(recipe=recipe_1_s1, servings=1)
|
||||
s = ShoppingList.objects.create(created_by=auth.get_user(u1_s1), space=space_1, )
|
||||
s.recipes.add(r)
|
||||
|
||||
@@ -246,8 +246,6 @@ def test_shopping_recipe_mixed_authors(u1_s1, u2_s1, space_1):
|
||||
|
||||
@pytest.mark.parametrize("recipe", [{'steps__ingredients__header': 1}], indirect=['recipe'])
|
||||
def test_shopping_with_header_ingredient(u1_s1, recipe):
|
||||
# with scope(space=recipe.space):
|
||||
# recipe.step_set.first().ingredient_set.add(IngredientFactory(ingredients__header=1))
|
||||
u1_s1.put(reverse(SHOPPING_RECIPE_URL, args={recipe.id}))
|
||||
assert len(json.loads(u1_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 10
|
||||
assert len(json.loads(
|
||||
|
||||
@@ -2,12 +2,9 @@ import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Ingredient, Step
|
||||
|
||||
LIST_URL = 'api:space-list'
|
||||
DETAIL_URL = 'api:space-detail'
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, Storage, Sync
|
||||
from cookbook.models import Storage
|
||||
|
||||
LIST_URL = 'api:storage-list'
|
||||
DETAIL_URL = 'api:storage-detail'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, Supermarket
|
||||
from cookbook.models import Supermarket
|
||||
|
||||
LIST_URL = 'api:supermarket-list'
|
||||
DETAIL_URL = 'api:supermarket-detail'
|
||||
@@ -48,7 +47,6 @@ def test_list_filter(obj_1, obj_2, u1_s1):
|
||||
assert r.status_code == 200
|
||||
response = json.loads(r.content)
|
||||
assert len(response) == 2
|
||||
# assert response[0]['name'] == obj_1.name # assuming an order when it's not always valid
|
||||
|
||||
response = json.loads(u1_s1.get(f'{reverse(LIST_URL)}?limit=1').content)
|
||||
assert len(response) == 1
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import RecipeBook, Storage, Sync
|
||||
from cookbook.models import Storage, Sync
|
||||
|
||||
LIST_URL = 'api:sync-list'
|
||||
DETAIL_URL = 'api:sync-detail'
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Food, MealType, UnitConversion
|
||||
from cookbook.models import MealType, UnitConversion
|
||||
from cookbook.tests.conftest import get_random_food, get_random_unit
|
||||
|
||||
LIST_URL = 'api:unitconversion-list'
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
||||
@@ -77,7 +76,7 @@ def test_user_retrieve(arg, request, u1_s1):
|
||||
assert r.status_code == arg[1]
|
||||
|
||||
|
||||
def test_user_update(u1_s1, u2_s1,u1_s2):
|
||||
def test_user_update(u1_s1, u2_s1, u1_s2):
|
||||
# can update own user
|
||||
r = u1_s1.patch(
|
||||
reverse(
|
||||
|
||||
@@ -120,7 +120,6 @@ def test_default_inherit_fields(u1_s1, u1_s2, space_1, space_2):
|
||||
r = u1_s1.get(
|
||||
reverse(DETAIL_URL, args={auth.get_user(u1_s1).id}),
|
||||
)
|
||||
#assert len([x['field'] for x in json.loads(r.content)['food_inherit_default']]) == 0
|
||||
|
||||
# inherit all possible fields
|
||||
with scope(space=space_1):
|
||||
|
||||
@@ -2,12 +2,9 @@ import json
|
||||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Ingredient, Step
|
||||
|
||||
LIST_URL = 'api:userspace-list'
|
||||
DETAIL_URL = 'api:userspace-detail'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user