Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated settings #3034

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Python Debugger: Django",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["runserver"],
"django": true,
"justMyCode": true
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Django",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
},
{
"name": "Python: Debug Tests",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"env": {
// coverage and pytest can't both be running at the same time
"PYTEST_ADDOPTS": "--no-cov",
"DATABASES": "{'default': {'ENGINE': 'django.db.backends.sqlite3'}}"
},
"django": true,
"justMyCode": true
},
]
}
17 changes: 9 additions & 8 deletions cookbook/tests/api/test_api_meal_plan.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
from datetime import datetime, timedelta
from datetime import timedelta

import pytest
from django.contrib import auth
from django.urls import reverse
from django_scopes import scope, scopes_disabled
from django.utils import timezone

from cookbook.models import MealPlan, MealType
from cookbook.tests.factories import RecipeFactory
Expand All @@ -23,13 +24,13 @@ def meal_type(space_1, u1_s1):

@pytest.fixture()
def obj_1(space_1, recipe_1_s1, meal_type, u1_s1):
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=datetime.now(), to_date=datetime.now(),
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=timezone.now(), to_date=timezone.now(),
created_by=auth.get_user(u1_s1))


@pytest.fixture
def obj_2(space_1, recipe_1_s1, meal_type, u1_s1):
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=datetime.now(), to_date=datetime.now(),
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=timezone.now(), to_date=timezone.now(),
created_by=auth.get_user(u1_s1))


Expand Down Expand Up @@ -68,15 +69,15 @@ def test_list_filter(obj_1, u1_s1):
assert len(response) == 0

response = json.loads(
u1_s1.get(f'{reverse(LIST_URL)}?from_date={(datetime.now() + timedelta(days=2)).strftime("%Y-%m-%d")}').content)
u1_s1.get(f'{reverse(LIST_URL)}?from_date={(timezone.now() + timedelta(days=2)).strftime("%Y-%m-%d")}').content)
assert len(response) == 0

response = json.loads(
u1_s1.get(f'{reverse(LIST_URL)}?to_date={(datetime.now() - timedelta(days=2)).strftime("%Y-%m-%d")}').content)
u1_s1.get(f'{reverse(LIST_URL)}?to_date={(timezone.now() - timedelta(days=2)).strftime("%Y-%m-%d")}').content)
assert len(response) == 0

response = json.loads(u1_s1.get(
f'{reverse(LIST_URL)}?from_date={(datetime.now() - timedelta(days=2)).strftime("%Y-%m-%d")}&to_date={(datetime.now() + timedelta(days=2)).strftime("%Y-%m-%d")}').content)
f'{reverse(LIST_URL)}?from_date={(timezone.now() - timedelta(days=2)).strftime("%Y-%m-%d")}&to_date={(timezone.now() + timedelta(days=2)).strftime("%Y-%m-%d")}').content)
assert len(response) == 1


Expand Down Expand Up @@ -116,7 +117,7 @@ def test_add(arg, request, u1_s2, recipe_1_s1, meal_type):
r = c.post(
reverse(LIST_URL),
{'recipe': {'id': recipe_1_s1.id, 'name': recipe_1_s1.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': []},
'from_date': (timezone.now()).strftime("%Y-%m-%d"), 'to_date': (timezone.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test', 'shared': []},
content_type='application/json'
)
response = json.loads(r.content)
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_add_with_shopping(u1_s1, meal_type):
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},
'from_date': (timezone.now()).strftime("%Y-%m-%d"), 'to_date': (timezone.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test', 'shared': [], 'addshopping': True},
content_type='application/json'
)

Expand Down
44 changes: 26 additions & 18 deletions cookbook/tests/api/test_api_plan_ical.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, timedelta
from datetime import timedelta

import pytest
from django.contrib import auth
from django.urls import reverse
from django.utils import timezone
from icalendar import Calendar

from cookbook.models import MealPlan, MealType
Expand All @@ -19,31 +20,35 @@ def meal_type(space_1, u1_s1):

@pytest.fixture()
def obj_1(space_1, recipe_1_s1, meal_type, u1_s1):
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=datetime.now(), to_date=datetime.now(),
created_by=auth.get_user(u1_s1))
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=timezone.now(), to_date=timezone.now(), created_by=auth.get_user(u1_s1))


@pytest.fixture
def obj_2(space_1, recipe_1_s1, meal_type, u1_s1):
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=datetime.now()+timedelta(days=30), to_date=datetime.now()+timedelta(days=30),
return MealPlan.objects.create(recipe=recipe_1_s1,
space=space_1,
meal_type=meal_type,
from_date=timezone.now() + timedelta(days=30),
to_date=timezone.now() + timedelta(days=30),
created_by=auth.get_user(u1_s1))


@pytest.fixture
def obj_3(space_1, recipe_1_s1, meal_type, u1_s1):
return MealPlan.objects.create(recipe=recipe_1_s1, space=space_1, meal_type=meal_type, from_date=datetime.now()+timedelta(days=-30), to_date=datetime.now()+timedelta(days=-1),
return MealPlan.objects.create(recipe=recipe_1_s1,
space=space_1,
meal_type=meal_type,
from_date=timezone.now() + timedelta(days=-30),
to_date=timezone.now() + timedelta(days=-1),
created_by=auth.get_user(u1_s1))


@pytest.mark.parametrize("arg", [
['a_u', 403],
['g1_s1', 403],
['u1_s1', 200],
['a1_s1', 200],
])
@pytest.mark.parametrize("arg", [['a_u', 403], ['g1_s1', 403], ['u1_s1', 200], ['a1_s1', 200], ])
def test_permissions(arg, request):
c = request.getfixturevalue(arg[0])
assert c.get(reverse(FUTURE_URL)).status_code == arg[1]


def test_future(obj_1, obj_2, obj_3, u1_s1):
r = u1_s1.get(reverse(FUTURE_URL))
assert r.status_code == 200
Expand All @@ -52,28 +57,31 @@ def test_future(obj_1, obj_2, obj_3, u1_s1):
events = cal.walk('VEVENT')
assert len(events) == 2


def test_from(obj_1, obj_2, obj_3, u1_s1):
from_date_slug = (datetime.now()+timedelta(days=1)).strftime("%Y-%m-%d")
from_date_slug = (timezone.now() + timedelta(days=1)).strftime("%Y-%m-%d")
r = u1_s1.get(reverse(FROM_URL, kwargs={'from_date': from_date_slug}))
assert r.status_code == 200

cal = Calendar.from_ical(r.getvalue().decode('UTF-8'))
events = cal.walk('VEVENT')
assert len(events) == 1


def test_bound(obj_1, obj_2, obj_3, u1_s1):
from_date_slug = (datetime.now()+timedelta(days=-1)).strftime("%Y-%m-%d")
to_date_slug = (datetime.now()+timedelta(days=1)).strftime("%Y-%m-%d")
from_date_slug = (timezone.now() + timedelta(days=-1)).strftime("%Y-%m-%d")
to_date_slug = (timezone.now() + timedelta(days=1)).strftime("%Y-%m-%d")
r = u1_s1.get(reverse(BOUND_URL, kwargs={'from_date': from_date_slug, 'to_date': to_date_slug}))
assert r.status_code == 200

cal = Calendar.from_ical(r.getvalue().decode('UTF-8'))
events = cal.walk('VEVENT')
assert len(events) == 1


def test_event(obj_1, u1_s1):
from_date_slug = (datetime.now()+timedelta(days=-1)).strftime("%Y-%m-%d")
to_date_slug = (datetime.now()+timedelta(days=1)).strftime("%Y-%m-%d")
from_date_slug = (timezone.now() + timedelta(days=-1)).strftime("%Y-%m-%d")
to_date_slug = (timezone.now() + timedelta(days=1)).strftime("%Y-%m-%d")
r = u1_s1.get(reverse(BOUND_URL, kwargs={'from_date': from_date_slug, 'to_date': to_date_slug}))

cal = Calendar.from_ical(r.getvalue().decode('UTF-8'))
Expand All @@ -84,5 +92,5 @@ def test_event(obj_1, u1_s1):
assert int(event['uid']) == obj_1.id
assert event['summary'] == f'{obj_1.meal_type.name}: {obj_1.get_label()}'
assert event['description'] == obj_1.note
assert event.decoded('dtstart') == datetime.now().date()
assert event.decoded('dtend') == datetime.now().date()
assert event.decoded('dtstart') == timezone.now().date()
assert event.decoded('dtend') == timezone.now().date()
2 changes: 1 addition & 1 deletion cookbook/tests/api/test_api_shopping_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.urls import reverse
from django_scopes import scopes_disabled

from cookbook.models import Food, Ingredient, ShoppingListRecipe, ShoppingListEntry
from cookbook.models import Food, Ingredient, ShoppingListEntry
from cookbook.tests.factories import MealPlanFactory, RecipeFactory, StepFactory, UserFactory

if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql':
Expand Down
Loading