-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3038 from c0mputerguru/ical-default-dates-new-api
Add ical action on MealPlanViewSet to expose filterable ical API in restful manner
- Loading branch information
Showing
6 changed files
with
124 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,55 @@ | ||
# from datetime import datetime, timedelta | ||
# | ||
# import pytest | ||
# from django.contrib import auth | ||
# from django.urls import reverse | ||
# from icalendar import Calendar | ||
# | ||
# from cookbook.models import MealPlan, MealType | ||
# | ||
# BOUND_URL = 'api_get_plan_ical' | ||
# FROM_URL = 'api_get_plan_ical' | ||
# FUTURE_URL = 'api_get_plan_ical' | ||
# | ||
# | ||
# @pytest.fixture() | ||
# def meal_type(space_1, u1_s1): | ||
# return MealType.objects.get_or_create(name='test', space=space_1, created_by=auth.get_user(u1_s1))[0] | ||
# | ||
# | ||
# @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)) | ||
# | ||
# | ||
# @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), | ||
# 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), | ||
# created_by=auth.get_user(u1_s1)) | ||
# | ||
# | ||
# @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 | ||
# | ||
# cal = Calendar.from_ical(r.getvalue().decode('UTF-8')) | ||
# 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") | ||
# 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") | ||
# 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") | ||
# 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')) | ||
# events = cal.walk('VEVENT') | ||
# assert len(events) == 1 | ||
# | ||
# event = events[0] | ||
# 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() | ||
from datetime import datetime, timedelta | ||
|
||
import pytest | ||
from django.contrib import auth | ||
from django.urls import reverse | ||
from icalendar import Calendar | ||
|
||
from cookbook.models import MealPlan, MealType | ||
|
||
BOUND_URL = 'api_get_plan_ical' | ||
|
||
|
||
@pytest.fixture() | ||
def meal_type(space_1, u1_s1): | ||
return MealType.objects.get_or_create(name='test', space=space_1, created_by=auth.get_user(u1_s1))[0] | ||
|
||
|
||
@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)) | ||
|
||
|
||
@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), | ||
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), | ||
created_by=auth.get_user(u1_s1)) | ||
|
||
|
||
@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]) | ||
from_date_slug = (datetime.now()+timedelta(days=-1)).strftime("%Y-%m-%d") | ||
to_date_slug = (datetime.now()+timedelta(days=1)).strftime("%Y-%m-%d") | ||
assert c.get(reverse(BOUND_URL, kwargs={'from_date': from_date_slug, 'to_date': to_date_slug})).status_code == arg[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") | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ pytest-cov===4.1.0 | |
pytest-factoryboy==2.6.0 | ||
pytest-html==4.1.1 | ||
pytest-asyncio==0.23.5 | ||
|
||
pytest-xdist==3.5.0 |