Skip to content

Commit

Permalink
some improvements and add unit tests after review of issue #82
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed Nov 11, 2016
1 parent 84d5b03 commit edcf2c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 2 additions & 5 deletions schedule/feeds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.utils.six.moves.builtins import str
from schedule.models import Calendar
from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from schedule.feeds.ical import ICalendarFeed
import itertools
Expand All @@ -14,10 +13,8 @@ class UpcomingEventsFeed(Feed):
def feed_title(self, obj):
return "Upcoming Events for %s" % obj.name

def get_object(self, request, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
return Calendar.objects.get(pk=bits[0])
def get_object(self, request, calendar_id):
return Calendar.objects.get(pk=calendar_id)

def link(self, obj):
if not obj:
Expand Down
8 changes: 4 additions & 4 deletions schedule/templates/schedule/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<h1>{% trans "Calendar metadata" %}</h1>

<p>{% blocktrans with calendar_name=calendar.name %}Name: {{calendar_name}}{% endblocktrans %}</p>
<p>{% blocktrans with calendar_slug=calendar.slug %}Slug: {{calendar_slug}}{% endblocktrans %}</p>
<p>{% blocktrans with events_count %}Event count: {{events_count}}{% endblocktrans %}</p>
<p>{% trans "Name:" %} {{calendar_name}} </p>
<p>{% trans "Slug:" %} {{calendar_slug}} </p>
<p>{% trans "Event count:" %} {{events_count}} </p>

<div>
<p>{% trans "See as:" %}</p>
Expand All @@ -19,7 +19,7 @@ <h1>{% trans "Calendar metadata" %}</h1>
<li><a href="{% url "year_calendar" calendar.slug %}">{% trans "This Year" %}</a></li>
<li><a href="{% url "week_calendar" calendar.slug %}">{% trans "Weekly" %}</a></li>
<li><a href="{% url "day_calendar" calendar.slug %}">{% trans "Daily" %}</a></li>
<li><a href="/schedule/feed/calendar/upcoming/{{ calendar.id }}/">{% trans "Feed" %}</a></li>
<li><a href="{% url "upcoming_events_feed" calendar_id=calendar.id %}">{% trans "Feed" %}</a></li>
</ul>
</div>

Expand Down
2 changes: 1 addition & 1 deletion schedule/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
name="edit_occurrence_by_date"),

# feed urls
url(r'^feed/calendar/upcoming/(.*)/$', UpcomingEventsFeed(), name='upcoming_events_feed'),
url(r'^feed/calendar/upcoming/(?P<calendar_id>\d+)/$', UpcomingEventsFeed(), name='upcoming_events_feed'),
url(r'^ical/calendar/(.*)/$', CalendarICalendar(), name='calendar_ical'),

# api urls
Expand Down
18 changes: 16 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import pytz

from django.test.utils import override_settings
from django.test import TestCase
from django.test import override_settings
from django.core.urlresolvers import reverse
from django.test import TestCase

from schedule.models.calendars import Calendar
from schedule.models.events import Event, Occurrence
Expand Down Expand Up @@ -291,3 +291,17 @@ def test_check_next_url_invalid_case(self):
self.assertEquals(expected, res)
res = check_next_url(None)
self.assertEquals(expected, res)

@override_settings(SITE_ID=1)
def test_feed_link(self):
feed_url = reverse('upcoming_events_feed', kwargs={'calendar_id': 1})
response = self.client.get(feed_url)
self.assertEquals(response.status_code, 200)
expected_feed = '<?xml version="1.0" encoding="utf-8"?>\n<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title></title><link>http://example.com/calendar/example/</link><description></description><atom:link href="http://example.com/feed/calendar/upcoming/1/" rel="self"></atom:link><language>en-us</language><lastBuildDate>'
self.assertTrue(expected_feed in response.content)

def test_calendar_view_home(self):
calendar_view_url = reverse('calendar_home', kwargs={'calendar_slug': 'example'})
response = self.client.get(calendar_view_url)
self.assertEquals(response.status_code, 200)
self.assertTrue('<a href="/feed/calendar/upcoming/1/">Feed</a>' in response.content)

0 comments on commit edcf2c0

Please sign in to comment.