Пример #1
0
class TestSchedulesViews(LoggedInTestCase):
    def setUp(self):
        super(TestSchedulesViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()

    def tearDown(self):
        super(TestSchedulesViews, self).tearDown()
        try:
            self.cal.delete()
        except Exception:
            pass

    @pytest.mark.skip(reason="TO Be Fixed")
    def test_schedule_detail_view_works_with_query_args(self):
        assert self.cal.id
        response = self.client.get(
            reverse('calendar_details', args=[self.cal.slug]),
            {
                'month': '11',
                'year': '2014'
            },
        )
        self.assertEqual(response.status_code, 200)
Пример #2
0
class TestSchedulesViews(LoggedInTestCase):
    def setUp(self):
        super(TestSchedulesViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()

    def tearDown(self):
        super(TestSchedulesViews, self).tearDown()
        try:
            self.cal.delete()
        except:
            pass

    def test_schedule_detail_view_works_with_query_args(self):
        response = self.client.get(
            reverse('openduty.schedules.details', args=[self.cal.id]),
            {
                'month': '11',
                'year': '2014'
            },
        )
        self.assertEqual(response.status_code, 200)
Пример #3
0
class TestEventViews(LoggedInTestCase):

    def setUp(self):
        super(TestEventViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.event = Event(
            start=timezone.now(),
            end=timezone.now() + timedelta(weeks=6),
            title=random_string(),
            calendar=self.cal,
        )
        self.event.save()

    def tearDown(self):
        super(TestEventViews, self).tearDown()
        try:
            self.cal.delete()
            self.event.delete()
        except:
            pass

    def test_event_can_be_recurring(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        try:
            url = reverse(
                'openduty.events.create_or_edit_event',
                kwargs = {
                    'calendar_slug': self.cal.slug,
                    'event_id': str(self.event.id),
                },
            )
            response = self.client.post(
                path = url,
                data = {
                    "start_0": self.event.start.strftime('%Y-%m-%d'),
                    "start_1": "09:00",
                    "end_0": self.event.end.strftime('%Y-%m-%d'),
                    "end_1": "23:00",
                    "description": "desc",
                    "rule": str(rule.id),
                    "oncall": "foo",
                    "fallback": "bar",
                },
            )
            self.assertEqual(302, response.status_code)
            e = Event.objects.get(id=self.event.id)
            self.assertEqual(rule, e.rule)
        finally:
            rule.delete()
Пример #4
0
class TestEventViews(LoggedInTestCase):

    def setUp(self):
        super(TestEventViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.event = Event(
            start=timezone.now(),
            end=timezone.now() + timedelta(weeks=6),
            title=random_string(),
            calendar=self.cal,
        )
        self.event.save()

    def tearDown(self):
        super(TestEventViews, self).tearDown()
        try:
            self.cal.delete()
            self.event.delete()
        except:
            pass

    def test_event_can_be_recurring(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        try:
            url = reverse(
                'edit_event',
                kwargs={
                    'calendar_slug': self.cal.slug,
                    'event_id': str(self.event.id),
                },
            )
            response = self.client.post(
                path=url,
                data={
                    "start_0": self.event.start.strftime('%Y-%m-%d'),
                    "start_1": "09:00",
                    "end_0": self.event.end.strftime('%Y-%m-%d'),
                    "end_1": "23:00",
                    "description": "desc",
                    "rule": str(rule.id),
                    "oncall": "foo",
                    "fallback": "bar",
                },
            )
            self.assertEqual(302, response.status_code)
            e = Event.objects.get(id=self.event.id)
            self.assertEqual(rule, e.rule)
        finally:
            rule.delete()
Пример #5
0
class TestSchedulesViews(LoggedInTestCase):

    def setUp(self):
        super(TestSchedulesViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()

    def tearDown(self):
        super(TestSchedulesViews, self).tearDown()
        try:
            self.cal.delete()
        except:
            pass

    def test_schedule_detail_view_works_with_query_args(self):
        response = self.client.get(
            reverse('openduty.schedules.details', args=[self.cal.slug]),
            {'month': '11', 'year': '2014'},
        )
        self.assertEqual(response.status_code, 200)
Пример #6
0
class TestGetEscalation(BaseTestCase):

    def setUp(self):
        super(TestGetEscalation, self).setUp()
        self.sp = SchedulePolicy(name=random_string(), repeat_times=1)
        self.sp.save()
        self.service = Service(name=random_string(), policy=self.sp)
        self.service.save()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.spr = SchedulePolicyRule(
            schedule_policy=self.sp,
            position=0,
            schedule=self.cal,
            escalate_after=1,
        )
        self.spr.save()

    def tearDown(self):
        super(TestGetEscalation, self).tearDown()
        try:
            self.spr.delete()
            self.cal.delete()
            self.service.delete()
            self.sp.delete()
        except:
            pass

    @pytest.mark.skip(reason="TO Be Fixed")
    def test_get_escalation_works_with_no_recurrence(self):
        event = Event(
            start=timezone.now() - timedelta(days=1),
            end=timezone.now() + timedelta(days=1),
            title='{username},{username}'.format(username=self.username),
            calendar=self.cal,
        )
        event.save()
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(2, len(events))
        finally:
            event.delete()

    def test_get_escalation_fails_with_no_recurrence_after_event_end(self):
        event = Event(
            start = timezone.now() - timedelta(days=2),
            end = timezone.now() - timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
        )
        event.save()
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(0, len(events))
        finally:
            event.delete()

    def test_get_escalation_empty_when_recurrance_is_not_now(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        # Active yesterday, and 1 week from now, but not today
        event = Event(
            start = timezone.now() - timedelta(days=2),
            end = timezone.now() - timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
            rule = rule,
        )
        event.save()
        events = get_escalation_for_service(self.service)
        self.assertEqual(0, len(events))

    @pytest.mark.skip(reason="TO Be Fixed")
    def test_get_escalation_works_when_recurrance_is_now(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        # Active last week at this time, recurring now
        event = Event(
            start = timezone.now() - timedelta(days=7, hours=5),
            end = timezone.now() + timedelta(hours=4) - timedelta(days=7),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
            rule = rule,
        )
        event.save()
        events = get_escalation_for_service(self.service)
        self.assertEqual(2, len(events))

    def test_get_escalation_returns_empty_for_muted_services(self):
        event = Event(
            start = timezone.now() - timedelta(days=1),
            end = timezone.now() + timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
        )
        event.save()
        self.service.notifications_disabled = True
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(0, len(events))
        finally:
            event.delete()
Пример #7
0
class TestGetEscalation(BaseTestCase):

    def setUp(self):
        super(TestGetEscalation, self).setUp()
        self.sp = SchedulePolicy(name=random_string(), repeat_times=1)
        self.sp.save()
        self.service = Service(name=random_string(), policy=self.sp)
        self.service.save()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.spr = SchedulePolicyRule(
            schedule_policy=self.sp,
            position=0,
            schedule=self.cal,
            escalate_after=1,
        )
        self.spr.save()

    def tearDown(self):
        super(TestGetEscalation, self).tearDown()
        try:
            self.spr.delete()
            self.cal.delete()
            self.service.delete()
            self.sp.delete()
        except:
            pass

    def test_get_escalation_works_with_no_recurrence(self):
        event = Event(
            start = timezone.now() - timedelta(days=1),
            end = timezone.now() + timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
        )
        event.save()
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(2, len(events))
        finally:
            event.delete()

    def test_get_escalation_fails_with_no_recurrence_after_event_end(self):
        event = Event(
            start = timezone.now() - timedelta(days=2),
            end = timezone.now() - timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
        )
        event.save()
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(0, len(events))
        finally:
            event.delete()

    def test_get_escalation_empty_when_recurrance_is_not_now(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        # Active yesterday, and 1 week from now, but not today
        event = Event(
            start = timezone.now() - timedelta(days=2),
            end = timezone.now() - timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
            rule = rule,
        )
        event.save()
        events = get_escalation_for_service(self.service)
        self.assertEqual(0, len(events))

    def test_get_escalation_works_when_recurrance_is_now(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        # Active last week at this time, recurring now
        event = Event(
            start = timezone.now() - timedelta(days=7, hours=5),
            end = timezone.now() + timedelta(hours=4) - timedelta(days=7),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
            rule = rule,
        )
        event.save()
        events = get_escalation_for_service(self.service)
        self.assertEqual(2, len(events))

    def test_get_escalation_returns_empty_for_muted_services(self):
        event = Event(
            start = timezone.now() - timedelta(days=1),
            end = timezone.now() + timedelta(days=1),
            title = '{username},{username}'.format(username=self.username),
            calendar = self.cal,
        )
        event.save()
        self.service.notifications_disabled = True
        try:
            events = get_escalation_for_service(self.service)
            self.assertEqual(0, len(events))
        finally:
            event.delete()