Exemple #1
0
class EventTestCase(TestCase):
    """Tests for the ``Event`` model."""
    longMessage = True

    def setUp(self):
        self.not_found_event = EventFactory(set__start=-24,
                                            set__end=-24,
                                            set__creation_date=-24,
                                            rule=None)
        self.event = EventFactory()
        self.occurrence = OccurrenceFactory(event=self.event,
                                            title='foo_occurrence')
        self.single_time_event = EventFactory(rule=None)

    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.'
                 ))

    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.'))

    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_parent_category(self):
        """Tests for the ``get_parent_category`` method."""
        result = self.event.get_parent_category()
        self.assertEqual(
            result,
            self.event.category,
            msg=("If the event's category has no parent, it should return the"
                 " category"))

        cat2 = EventCategoryFactory()
        self.event.category.parent = cat2
        self.event.save()
        result = self.event.get_parent_category()
        self.assertEqual(
            result,
            self.event.category.parent,
            msg=("If the event's category has a parent, it should return that"
                 " parent"))

    def test_save_autocorrection(self):
        event = EventFactory(rule=None)
        event.end = event.end - timedelta(hours=2)
        event.save()
        self.assertEqual(event.start, event.end)
class EventTestCase(TestCase):
    """Tests for the ``Event`` model."""
    longMessage = True

    def setUp(self):
        self.not_found_event = EventFactory(
            set__start=-24, set__end=-24, set__creation_date=-24,
            rule=None)
        self.event = EventFactory()
        self.occurrence = OccurrenceFactory(
            event=self.event, title='foo_occurrence')
        self.single_time_event = EventFactory(rule=None)

    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.'))

    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.'))

    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_parent_category(self):
        """Tests for the ``get_parent_category`` method."""
        result = self.event.get_parent_category()
        self.assertEqual(result, self.event.category, msg=(
            "If the event's category has no parent, it should return the"
            " category"))

        cat2 = EventCategoryFactory()
        self.event.category.parent = cat2
        self.event.save()
        result = self.event.get_parent_category()
        self.assertEqual(result, self.event.category.parent, msg=(
            "If the event's category has a parent, it should return that"
            " parent"))

    def test_save_autocorrection(self):
        event = EventFactory(rule=None)
        event.end = event.end - timedelta(hours=2)
        event.save()
        self.assertEqual(event.start, event.end)
Exemple #3
0
 def test_save_autocorrection(self):
     event = EventFactory(rule=None)
     event.end = event.end - timedelta(hours=2)
     event.save()
     self.assertEqual(event.start, event.end)
 def test_save_autocorrection(self):
     event = EventFactory(rule=None)
     event.end = event.end - timedelta(hours=2)
     event.save()
     self.assertEqual(event.start, event.end)