Skip to content

Commit

Permalink
issue #113 use today to create example data
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed May 21, 2015
1 parent 1f7241c commit 0ab5ade
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 54 deletions.
43 changes: 22 additions & 21 deletions schedule/management/commands/load_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ def handle_noargs(self, **options):
rule.save()
print("Daily recurrence created")
print("Rules installed.")
today = datetime.date.today()

print("Create some events")
rule=Rule.objects.get(frequency="WEEKLY")
data={
'title': 'Exercise',
'start': datetime.datetime(2008, 11, 3, 8, 0),
'end': datetime.datetime(2008, 11, 3, 9, 0),
'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
'start': datetime.datetime(today.year, 11, 3, 8, 0),
'end': datetime.datetime(today.year, 11, 3, 9, 0),
'end_recurring_period': datetime.datetime(today.year + 30, 6, 1, 0, 0),
'rule': rule,
'calendar': cal
}
Expand All @@ -58,9 +59,9 @@ def handle_noargs(self, **options):

data={
'title': 'Exercise',
'start': datetime.datetime(2008, 11, 5, 15, 0),
'end': datetime.datetime(2008, 11, 5, 16, 30),
'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
'start': datetime.datetime(today.year, 11, 5, 15, 0),
'end': datetime.datetime(today.year, 11, 5, 16, 30),
'end_recurring_period': datetime.datetime(today.year + 20, 6, 1, 0, 0),
'rule': rule,
'calendar': cal
}
Expand All @@ -69,9 +70,9 @@ def handle_noargs(self, **options):

data={
'title': 'Exercise',
'start': datetime.datetime(2008, 11, 7, 8, 0),
'end': datetime.datetime(2008, 11, 7, 9, 30),
'end_recurring_period': datetime.datetime(2009, 6, 1, 0, 0),
'start': datetime.datetime(today.year, 11, 7, 8, 0),
'end': datetime.datetime(today.year, 11, 7, 9, 30),
'end_recurring_period': datetime.datetime(today.year + 20, 6, 1, 0, 0),
'rule': rule,
'calendar': cal
}
Expand All @@ -81,9 +82,9 @@ def handle_noargs(self, **options):
rule=Rule.objects.get(frequency="MONTHLY")
data={
'title': 'Pay Mortgage',
'start': datetime.datetime(2008, 11, 1, 14, 0),
'end': datetime.datetime(2008, 11, 1, 14, 30),
'end_recurring_period': datetime.datetime(2009, 10, 2, 0, 0),
'start': datetime.datetime(today.year, today.month, today.day, 14, 0),
'end': datetime.datetime(today.year, today.month, today.day, 14, 30),
'end_recurring_period': datetime.datetime(today.year, today.month, today.day, 0, 0) + datetime.timedelta(days=1),
'rule': rule,
'calendar': cal
}
Expand All @@ -93,9 +94,9 @@ def handle_noargs(self, **options):
rule=Rule.objects.get(frequency="YEARLY")
data={
'title': "Rock's Birthday Party",
'start': datetime.datetime(2008, 12, 11, 19, 0),
'end': datetime.datetime(2008, 12, 11, 23, 59),
'end_recurring_period': datetime.datetime(2009, 12, 22, 0, 0),
'start': datetime.datetime(today.year, today.month, today.day, 19, 0),
'end': datetime.datetime(today.year, today.month, today.day, 23, 59),
'end_recurring_period': datetime.datetime(today.year, today.month, today.day, 0, 0) + datetime.timedelta(days=1),
'rule': rule,
'calendar': cal
}
Expand All @@ -104,9 +105,9 @@ def handle_noargs(self, **options):

data={
'title': 'Christmas Party',
'start': datetime.datetime(2008, 12, 25, 19, 30),
'end': datetime.datetime(2008, 12, 25, 23, 59),
'end_recurring_period': datetime.datetime(2010, 12, 31, 0, 0),
'start': datetime.datetime(today.year, 12, 25, 19, 30),
'end': datetime.datetime(today.year, 12, 25, 23, 59),
'end_recurring_period': datetime.datetime(today.year + 2, 12, 31, 0, 0),
'rule': rule,
'calendar': cal
}
Expand All @@ -115,9 +116,9 @@ def handle_noargs(self, **options):

data={
'title': 'New Pinax site goes live',
'start': datetime.datetime(2009, 1, 6, 11, 0),
'end': datetime.datetime(2009, 1, 6, 12, 00),
'end_recurring_period': datetime.datetime(2009, 1, 7, 0, 0),
'start': datetime.datetime(today.year + 1, 1, 6, 11, 0),
'end': datetime.datetime(today.year + 1, 1, 6, 12, 00),
'end_recurring_period': datetime.datetime(today.year + 2, 1, 7, 0, 0),
'calendar': cal
}
event=Event(**data)
Expand Down
45 changes: 22 additions & 23 deletions schedule/management/commands/load_sample_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.core.management.base import NoArgsCommand

from django.core.management.color import no_style

class Command(NoArgsCommand):
help = "Load some sample data into the db"
help="Load some sample data into the db"

def handle_noargs(self, **options):
import datetime
Expand All @@ -13,60 +12,60 @@ def handle_noargs(self, **options):

print("checking for existing data ...")
try:
cal = Calendar.objects.get(name="yml_cal")
Calendar.objects.get(name="yml_cal")
print("It looks like you already have loaded the sample data, quitting.")
import sys
sys.exit(1)
except Calendar.DoesNotExist:
print("Sample data not found in db.")
print("Install it...")


print("Create 2 calendars : tony_cal, yml_cal")
yml_cal = Calendar(name="yml_cal",slug="yml")
yml_cal=Calendar(name="yml_cal", slug="yml")
yml_cal.save()
print("First calendar is created")
tony_cal = Calendar(name="tony_cal",slug="tony")
tony_cal=Calendar(name="tony_cal", slug="tony")
tony_cal.save()
print("Second calendar is created")
print("Do we need to create the most common rules?")
try:
rule = Rule.objects.get(name="Daily")
rule=Rule.objects.get(name="Daily")
except Rule.DoesNotExist:
rule = Rule(frequency = "YEARLY", name = "Yearly", description = "will recur once every Year")
rule=Rule(frequency="YEARLY", name="Yearly", description="will recur once every Year")
rule.save()
print("YEARLY recurrence created")
rule = Rule(frequency = "MONTHLY", name = "Monthly", description = "will recur once every Month")
rule=Rule(frequency="MONTHLY", name="Monthly", description="will recur once every Month")
rule.save()
print("Monthly recurrence created")
rule = Rule(frequency = "WEEKLY", name = "Weekly", description = "will recur once every Week")
rule=Rule(frequency="WEEKLY", name="Weekly", description="will recur once every Week")
rule.save()
print("Weekly recurrence created")
rule = Rule(frequency = "DAILY", name = "Daily", description = "will recur once every Day")
rule=Rule(frequency="DAILY", name="Daily", description="will recur once every Day")
rule.save()
print("Daily recurrence created")
print("The common rules are installed.")
today=datetime.date.today()

print("Create some events")
rule = Rule.objects.get(frequency="WEEKLY")
data = {
rule=Rule.objects.get(frequency="WEEKLY")
data={
'title': 'Ping pong',
'start': datetime.datetime(2008, 11, 1, 8, 0),
'end': datetime.datetime(2008, 11, 1, 9, 0),
'end_recurring_period' : datetime.datetime(2010, 5, 5, 0, 0),
'start': datetime.datetime(today.year, today.month, today.day, 8, 0),
'end': datetime.datetime(today.year, today.month, today.day, 9, 0),
'end_recurring_period': datetime.datetime(today.year + 2, 5, 5, 0, 0),
'rule': rule,
'calendar': tony_cal
}
event = Event(**data)
event=Event(**data)
event.save()
rule = Rule.objects.get(frequency="DAILY")
data = {
rule=Rule.objects.get(frequency="DAILY")
data={
'title': 'Home work',
'start': datetime.datetime(2008, 11, 1, 18, 0),
'end': datetime.datetime(2008, 11, 1, 19, 0),
'end_recurring_period' : datetime.datetime(2010, 5, 5, 0, 0),
'start': datetime.datetime(today.year, today.month, today.day, 18, 0),
'end': datetime.datetime(today.year, today.month, today.day, 19, 0),
'end_recurring_period': datetime.datetime(today.year + 10, 5, 5, 0, 0),
'rule': rule,
'calendar': tony_cal
}
event = Event(**data)
event=Event(**data)
event.save()
16 changes: 6 additions & 10 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import pytz
import datetime

from django.contrib.auth.models import User
from django.test.utils import override_settings
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.test import Client

from schedule.models.calendars import Calendar
from schedule.models.events import Event
from schedule.models.rules import Rule
from schedule import utils

from schedule.views import check_next_url, coerce_date_dict

Expand Down Expand Up @@ -109,13 +106,12 @@ def test_event_creation_authenticated_user(self):

self.response = self.client.post(reverse("calendar_create_event",
kwargs={"calendar_slug": 'example'}),
{'description': 'description',
'title': 'title',
'end_recurring_period_1': '10:22:00', 'end_recurring_period_0': '2008-10-30',
'end_recurring_period_2': 'AM',
'end_1': '10:22:00', 'end_0': '2008-10-30', 'end_2': 'AM',
'start_0': '2008-10-30', 'start_1': '09:21:57', 'start_2': 'AM'
})
{'description': 'description',
'title': 'title',
'end_recurring_period_1': '10:22:00', 'end_recurring_period_0': '2008-10-30',
'end_recurring_period_2': 'AM',
'end_1': '10:22:00', 'end_0': '2008-10-30', 'end_2': 'AM',
'start_0': '2008-10-30', 'start_1': '09:21:57', 'start_2': 'AM'})
self.assertEqual(self.response.status_code, 302)

highest_event_id = self.highest_event_id
Expand Down

0 comments on commit 0ab5ade

Please sign in to comment.