Example #1
0
    def time_offset(self, create, extracted, **kwargs):
        """
        On initialization of the Factory one can pass following argument:

            'set__fieldname=value'

        where fieldname is the name of the field to set (e.g. start) and value
        is the time offset in hours to set.

        To set start 4 hours into the past you would pass the following:

            'set__start=-4'

        """
        self.creation_date = now() - timedelta(
            hours=kwargs.get('creation_date') or 0)
        self.start = now() + timedelta(hours=kwargs.get('start') or 0)
        if kwargs.get('end') is not None:
            self.end = now() + timedelta(hours=kwargs.get('end'))
        else:
            self.end = now() + timedelta(hours=1)
        # note that this defaults to seven, because the default rule is daily
        # for one week, so 6 days after the current
        if self.rule:
            self.end_recurring_period = now() + timedelta(
                days=kwargs.get('end_recurring_period') or 6)
        else:
            self.end_recurring_period = None
        if create:
            self.save()
Example #2
0
    def time_offset(self, create, extracted, **kwargs):
        """
        On initialization of the Factory one can pass following argument:

            'set__fieldname=value'

        where fieldname is the name of the field to set (e.g. start) and value
        is the time offset in hours to set.

        To set start 4 hours into the past you would pass the following:

            'set__start=-4'

        """
        self.creation_date = now() - timedelta(
            hours=kwargs.get('creation_date') or 0)
        self.start = now() + timedelta(hours=kwargs.get('start') or 0)
        if kwargs.get('end') is not None:
            self.end = now() + timedelta(hours=kwargs.get('end'))
        else:
            self.end = now() + timedelta(hours=1)
        # note that this defaults to seven, because the default rule is daily
        # for one week, so 6 days after the current
        if self.rule:
            self.end_recurring_period = now() + timedelta(
                days=kwargs.get('end_recurring_period') or 6)
        else:
            self.end_recurring_period = None
        if create:
            self.save()
Example #3
0
class EventFactoryMixin(factory.DjangoModelFactory):
    """Mixin for the event models."""
    start = now()
    end = now() + timedelta(hours=1)
    title = factory.Sequence(lambda n: 'title{0}'.format(n))
    description = factory.Sequence(lambda n: 'description{0}'.format(n))
    creation_date = now()
Example #4
0
 def setUp(self):
     self.rule = RuleFactory(name='daily')
     self.start = now() - timedelta(days=1)
     self.end = now() + timedelta(days=5)
     self.event = EventFactory(rule=self.rule,
                               end_recurring_period=now() +
                               timedelta(days=2))
 def test_get_occurrences(self):
     occurrence_gen = self.event.get_occurrences(
         now(), now() + timedelta(days=7))
     occ_list = [occ for occ in occurrence_gen]
     self.assertEqual(len(occ_list), 7, msg=(
         'Method ``get_occurrences`` did not output the correct amount'
         ' of occurrences.'))
     occurrence_gen = self.event.get_occurrences(
         now(), now() + timedelta(days=7))
     self.assertEqual(occurrence_gen.next().title, 'foo_occurrence', msg=(
         'The persistent occurrence should have been first in the list.'))
Example #6
0
 def test_get_occurrences(self):
     occurrence_gen = self.event.get_occurrences(
         now(), now() + timedelta(days=7))
     occ_list = [occ for occ in occurrence_gen]
     self.assertEqual(len(occ_list), 7, msg=(
         'Method ``get_occurrences`` did not output the correct amount'
         ' of occurrences.'))
     occurrence_gen = self.event.get_occurrences(
         now(), now() + timedelta(days=7))
     self.assertEqual(occurrence_gen.next().title, 'foo_occurrence', msg=(
         'The persistent occurrence should have been first in the list.'))
    def test_get_occurrences(self):
        """Test for the ``get_occurrences`` manager method."""
        occurrences = Event.objects.get_occurrences(
            now(), now() + timedelta(days=7))
        self.assertEqual(len(occurrences), 8, msg=(
            '``get_occurrences`` should return the correct amount of'
            ' occurrences.'))

        occurrences = Event.objects.get_occurrences(now(), now())
        self.assertEqual(len(occurrences), 2, msg=(
            '``get_occurrences`` should return the correct amount of'
            ' occurrences for one day.'))
Example #8
0
    def test_get_occurrences(self):
        """Test for the ``get_occurrences`` manager method."""
        occurrences = Event.objects.get_occurrences(
            now(), now() + timedelta(days=7))
        self.assertEqual(len(occurrences), 8, msg=(
            '``get_occurrences`` should return the correct amount of'
            ' occurrences.'))

        occurrences = Event.objects.get_occurrences(now(), now())
        self.assertEqual(len(occurrences), 2, msg=(
            '``get_occurrences`` should return the correct amount of'
            ' occurrences for one day.'))
    def test_get_occurrence_gen(self):
        """Test for the ``_get_occurrence_gen`` method"""
        occurrence_gen = self.event._get_occurrence_gen(
            now(), now() + timedelta(days=8))
        occ_list = [occ for occ in occurrence_gen]
        self.assertEqual(len(occ_list), 7, msg=(
            'The method ``_get_occurrence_list`` did not return the expected'
            ' amount of items.'))

        occurrence_gen = self.not_found_event._get_occurrence_gen(
            now(), now() + timedelta(days=8))
        occ_list = [occ for occ in occurrence_gen]
        self.assertEqual(len(occ_list), 0, msg=(
            'The method ``_get_occurrence_list`` did not return the expected'
            ' amount of items.'))
Example #10
0
    def test_get_occurrence_gen(self):
        """Test for the ``_get_occurrence_gen`` method"""
        occurrence_gen = self.event._get_occurrence_gen(
            now(), now() + timedelta(days=8))
        occ_list = [occ for occ in occurrence_gen]
        self.assertEqual(len(occ_list), 7, msg=(
            'The method ``_get_occurrence_list`` did not return the expected'
            ' amount of items.'))

        occurrence_gen = self.not_found_event._get_occurrence_gen(
            now(), now() + timedelta(days=8))
        occ_list = [occ for occ in occurrence_gen]
        self.assertEqual(len(occ_list), 0, msg=(
            'The method ``_get_occurrence_list`` did not return the expected'
            ' amount of items.'))
Example #11
0
 def test_create_occurrence(self):
     """Test for ``_create_occurrence`` method."""
     occurrence = self.event._create_occurrence(now())
     self.assertEqual(
         type(occurrence),
         Occurrence,
         msg=('Method ``_create_occurrence`` did not output the right type.'
              ))
Example #12
0
    def time_offset(self, create, extracted, **kwargs):
        """
        On initialization of the Factory one can pass following argument:

            'set__fieldname=value'

        where fieldname is the name of the field to set (e.g. start) and value
        is the time offset in hours to set.

        To set start 4 hours into the past you would pass the following:

            'set__start=-4'

        """
        self.creation_date = now() + timedelta(
            hours=kwargs.get('creation_date') or 0)
        self.start = now() + timedelta(hours=kwargs.get('start') or 0)
        self.end = now() + timedelta(hours=kwargs.get('end') or 0)
        self.original_start = now() + timedelta(
            hours=kwargs.get('original_start') or 0)
        if kwargs.get('original_end') is not None:
            self.original_end = now() + timedelta(
                hours=kwargs.get('original_end'))
        else:
            self.original_end = now() + timedelta(hours=1)
        if create:
            self.save()
Example #13
0
    def time_offset(self, create, extracted, **kwargs):
        """
        On initialization of the Factory one can pass following argument:

            'set__fieldname=value'

        where fieldname is the name of the field to set (e.g. start) and value
        is the time offset in hours to set.

        To set start 4 hours into the past you would pass the following:

            'set__start=-4'

        """
        self.creation_date = now() + timedelta(
            hours=kwargs.get('creation_date') or 0)
        self.start = now() + timedelta(
            hours=kwargs.get('start') or 0)
        self.end = now() + timedelta(
            hours=kwargs.get('end') or 0)
        self.original_start = now() + timedelta(
            hours=kwargs.get('original_start') or 0)
        if kwargs.get('original_end') is not None:
            self.original_end = now() + timedelta(hours=kwargs.get(
                'original_end'))
        else:
            self.original_end = now() + timedelta(hours=1)
        if create:
            self.save()
Example #14
0
class OccurrenceFactory(EventFactoryMixin):
    """Factory for the ``Occurrence`` model."""
    event = factory.SubFactory(EventFactory)
    original_start = now()
    original_end = now() + timedelta(days=1)
    cancelled = False

    class Meta:
        model = Occurrence

    @factory.post_generation
    def set(self, create, extracted, **kwargs):
        """
        On initialization of the Factory one can pass following argument:

            'set__fieldname=value'

        where fieldname is the name of the field to set (e.g. start) and value
        is the time offset in hours to set.

        To set start 4 hours into the past you would pass the following:

            'set__start=-4'

        """
        self.creation_date = now() + timedelta(
            hours=kwargs.get('creation_date') or 0)
        self.start = now() + timedelta(hours=kwargs.get('start') or 0)
        self.end = now() + timedelta(hours=kwargs.get('end') or 0)
        self.original_start = now() + timedelta(
            hours=kwargs.get('original_start') or 0)
        if kwargs.get('original_end') is not None:
            self.original_end = now() + timedelta(
                hours=kwargs.get('original_end'))
        else:
            self.original_end = now() + timedelta(hours=1)
        if create:
            self.save()
    def setUp(self):
        # single, not recurring event
        self.event = EventFactory(rule=None, end_recurring_period=None)
        self.event_occurrence = self.event.get_occurrences(
            self.event.start).next()

        # recurring event weekly on mondays over 6 weeks
        self.rule = RuleFactory(
            name='weekly', frequency=FREQUENCIES['WEEKLY'],
            params=json.dumps({'byweekday': 0}))
        self.rec_event = EventFactory(
            rule=self.rule, start=now(),
            set__end_recurring_period=41)
        self.rec_occurrence_list = [
            occ for occ in self.rec_event.get_occurrences(
                self.rec_event.start, self.rec_event.end_recurring_period)]
        self.rec_occurrence = self.rec_occurrence_list[2]
Example #16
0
    def setUp(self):
        # single, not recurring event
        self.event = EventFactory(rule=None, end_recurring_period=None)
        self.event_occurrence = next(self.event.get_occurrences(
            self.event.start))

        # recurring event weekly on mondays over 6 weeks
        self.rule = RuleFactory(
            name='weekly', frequency=FREQUENCIES['WEEKLY'],
            params=json.dumps({'byweekday': 0}))
        self.rec_event = EventFactory(
            rule=self.rule, start=now(),
            set__end_recurring_period=41,
            created_by=mixer.blend('auth.User'),
        )
        self.rec_occurrence_list = [
            occ for occ in self.rec_event.get_occurrences(
                self.rec_event.start, self.rec_event.end_recurring_period)]
        self.rec_occurrence = self.rec_occurrence_list[1]
Example #17
0
    def test_deletion(self):
        self.is_callable(method='post')

        self.is_callable(kwargs={
            'pk': self.event.pk,
            'year': self.event.start.date().year,
            'month': self.event.start.date().month,
            'day': self.event.start.date().day + 1,
        },
                         message=('Should be callable, if date in period.'))

        self.is_not_callable(kwargs={
            'pk': 5,
            'year': self.event.start.date().year,
            'month': self.event.start.date().month,
            'day': self.event.start.date().day,
        },
                             message=('Wrong event pk.'))

        self.is_not_callable(kwargs={
            'pk': self.event.pk,
            'year': self.event.start.date().year,
            'month': '999',
            'day': self.event.start.date().day,
        },
                             message=('Wrong dates.'))

        new_rule = RuleFactory(name='weekly', frequency='WEEKLY')
        new_event = EventFactory(
            rule=new_rule,
            end_recurring_period=now() + timedelta(days=200),
            set__start=-5,
        )
        test_date = self.event.start.date() - timedelta(days=5)
        self.is_not_callable(kwargs={
            'pk': new_event.pk,
            'year': test_date.year,
            'month': test_date.month,
            'day': test_date.day,
        },
                             message=('No occurrence available for this day.'))
Example #18
0
    def test_deletion(self):
        self.is_callable(method='post')

        self.is_callable(kwargs={
            'pk': self.event.pk,
            'year': self.event.start.date().year,
            'month': self.event.start.date().month,
            'day': self.event.start.date().day + 1,
        }, message=('Should be callable, if date in period.'))

        self.is_not_callable(kwargs={
            'pk': 5,
            'year': self.event.start.date().year,
            'month': self.event.start.date().month,
            'day': self.event.start.date().day,
        }, message=('Wrong event pk.'))

        self.is_not_callable(kwargs={
            'pk': self.event.pk,
            'year': self.event.start.date().year,
            'month': '999',
            'day': self.event.start.date().day,
        }, message=('Wrong dates.'))

        new_rule = RuleFactory(name='weekly', frequency='WEEKLY')
        new_event = EventFactory(
            rule=new_rule,
            end_recurring_period=now() + timedelta(days=200),
            set__start=-5,
        )
        test_date = self.event.start.date() - timedelta(days=5)
        self.is_not_callable(kwargs={
            'pk': new_event.pk,
            'year': test_date.year,
            'month': test_date.month,
            'day': test_date.day,
        }, message=('No occurrence available for this day.'))
 def test_create_occurrence(self):
     """Test for ``_create_occurrence`` method."""
     occurrence = self.event._create_occurrence(now())
     self.assertEqual(type(occurrence), Occurrence, msg=(
         'Method ``_create_occurrence`` did not output the right type.'))
Example #20
0
 def setUp(self):
     self.rule = RuleFactory(name='daily')
     self.start = now() - timedelta(days=1)
     self.end = now() + timedelta(days=5)
     self.event = EventFactory(
         rule=self.rule, end_recurring_period=now() + timedelta(days=2))
Example #21
0
 def setUp(self):
     self.year = now().year
     # current week number
     self.week = now().date().isocalendar()[1]
Example #22
0
 def setUp(self):
     self.year = now().year
     self.month = now().month
Example #23
0
 def setUp(self):
     self.year = now().year
     # current week number
     self.week = now().date().isocalendar()[1]
Example #24
0
 def setUp(self):
     self.year = now().year
     self.month = now().month