Пример #1
0
    def test__calculate_homogeneous_price(self, mock_is_between_time):
        start_date = parse_datetime("2018-02-28T10:00:13Z")
        end_date = parse_datetime("2018-02-28T10:03:12Z")

        with self.subTest("when appear in first cycle"):
            charge = MOCK_CHARGES[0]
            cycle = (charge["start"], charge["end"])

            mock_is_between_time.side_effect = mock_is_between_time_return(
                cycle)

            expected = billing.DEFAULT_FIXED_CHARGE + 18
            actual = billing._calculate_homogeneous_price(start_date, end_date)

            self.assertEqual(actual, expected)

        with self.subTest("when appear in seccond cycle"):
            charge = MOCK_CHARGES[1]
            cycle = (charge["start"], charge["end"])

            mock_is_between_time.side_effect = mock_is_between_time_return(
                cycle)

            expected = billing.DEFAULT_FIXED_CHARGE + 2
            actual = billing._calculate_homogeneous_price(start_date, end_date)

            self.assertEqual(actual, expected)
    def test_get_grade_display_stage(self, expected_result, grade_display_dates):
        stages = []
        for display_datetime in grade_display_dates:
            stage_mock = mock.create_autospec(BaseGroupActivityStage)
            stage_mock.open_date = parse_datetime(display_datetime)
            stages.append(stage_mock)

        with mock.patch.object(self.block, 'get_children_by_category', mock.Mock()) as get_stages:
            get_stages.return_value = stages
            self.assertEqual(
                getattr(self.block.get_grade_display_stage(), "open_date", None), parse_datetime(expected_result)
            )
    def test_get_grade_display_stage(self, expected_result, grade_display_dates):
        stages = []
        for display_datetime in grade_display_dates:
            stage_mock = mock.create_autospec(BaseGroupActivityStage)
            stage_mock.open_date = parse_datetime(display_datetime)
            stages.append(stage_mock)

        with mock.patch.object(self.block, 'get_children_by_category', mock.Mock()) as get_stages:
            get_stages.return_value = stages
            self.assertEqual(
                getattr(self.block.get_grade_display_stage(), "open_date", None), parse_datetime(expected_result)
            )
    def test_grades_posted_success_scenario(self, group_id, course_id, location, ignore_if_past_due, send_at):
        activity = mock.Mock(course_id=course_id, display_name='Activity Name')
        block = StageNotificationsGuineaPig(activity, location, open_date=parse_datetime(send_at))

        with mock.patch('edx_notifications.data.NotificationMessage.add_click_link_params') as patched_link_params:
            block.fire_grades_posted_notification(group_id, self.notifications_service_mock)

            self.notifications_service_mock.get_notification_type.assert_called_once_with(
                NotificationMessageTypes.GRADES_POSTED
            )

            args, kwargs = self._get_call_args(
                self.notifications_service_mock.publish_timed_notification,
                including_kwargs=True,
            )

            self.assertEquals(args, ())  # no positional arguments
            self.assertEqual(kwargs['scope_name'], NotificationScopes.WORKGROUP)
            self.assertEqual(kwargs['scope_context'], {'workgroup_id': group_id})
            self.assertIsNotNone(kwargs['send_at'])
            self.assertEqual(kwargs['ignore_if_past_due'], ignore_if_past_due)
            message = kwargs['msg']
            self.assertEqual(message.msg_type.name, NotificationMessageTypes.GRADES_POSTED)
            self.assertEqual(message.namespace, unicode(course_id))
            self.assertEqual(message.payload['activity_name'], 'Activity Name')

            patched_link_params.assert_called_once_with(
                {'course_id': unicode(course_id), 'location': unicode(block.location)}
            )
Пример #5
0
    def test_is_between_time(self):
        start_time = parse_time("22:00")
        end_time = parse_time("06:00")

        self.assertFalse(
            datetime.is_between_time(parse_datetime("2018-02-28T21:57:13Z"),
                                     start_time, end_time))
        self.assertTrue(
            datetime.is_between_time(parse_datetime("2018-02-28T22:00:00Z"),
                                     start_time, end_time))
        self.assertTrue(
            datetime.is_between_time(parse_datetime("2018-02-28T00:00:00Z"),
                                     start_time, end_time))
        self.assertTrue(
            datetime.is_between_time(parse_datetime("2018-02-28T06:00:00Z"),
                                     start_time, end_time))
        self.assertFalse(
            datetime.is_between_time(parse_datetime("2018-02-28T06:01:00Z"),
                                     start_time, end_time))
Пример #6
0
    def test__calculate_heterogeneous_price(self, mock_cycle_calculator: Mock):
        start_date = "start_date"
        end_date = "end_date"

        with self.subTest("when appear in first cycle"):
            charge = MOCK_CHARGES[0]
            cycles = [(charge["start"], charge["end"])]

            return_value = [(parse_datetime("2018-02-28T10:00:13Z"),
                             parse_datetime("2018-02-28T10:03:12Z"))]

            mock_cycle_calculator.side_effect = mock_cycle_calculator_return(
                cycles, return_value)

            expected = billing.DEFAULT_FIXED_CHARGE + 18
            actual = billing._calculate_heterogeneous_price(
                start_date, end_date)

            self.assertEqual(actual, expected)

        with self.subTest("when appear in second cycle"):
            charge = MOCK_CHARGES[1]
            cycles = [(charge["start"], charge["end"])]

            return_value = [(parse_datetime("2018-02-28T23:59:13Z"),
                             parse_datetime("2018-03-01T00:02:12Z"))]

            mock_cycle_calculator.side_effect = mock_cycle_calculator_return(
                cycles, return_value)

            expected = billing.DEFAULT_FIXED_CHARGE + 2
            actual = billing._calculate_heterogeneous_price(
                start_date, end_date)

            self.assertEqual(actual, expected)

        with self.subTest("when appear in both cycles"):
            cycles = []
            for charge in MOCK_CHARGES:
                cycles.append((charge["start"], charge["end"]))

            return_value = [
                (parse_datetime("2018-02-28T10:00:13Z"),
                 parse_datetime("2018-02-28T10:03:12Z")),
            ]

            mock_cycle_calculator.side_effect = mock_cycle_calculator_return(
                cycles, return_value)

            expected = billing.DEFAULT_FIXED_CHARGE + 20
            actual = billing._calculate_heterogeneous_price(
                start_date, end_date)

            self.assertEqual(actual, expected)
    def test_grades_posted_success_scenario(self, group_id, course_id,
                                            location, ignore_if_past_due,
                                            send_at):
        activity = mock.Mock(course_id=course_id, display_name='Activity Name')
        block = StageNotificationsGuineaPig(activity,
                                            location,
                                            open_date=parse_datetime(send_at))

        with mock.patch(
                'edx_notifications.data.NotificationMessage.add_click_link_params'
        ) as patched_link_params:
            block.fire_grades_posted_notification(
                group_id, self.notifications_service_mock)

            self.notifications_service_mock.get_notification_type.assert_called_once_with(
                NotificationMessageTypes.GRADES_POSTED)

            args, kwargs = self._get_call_args(
                self.notifications_service_mock.publish_timed_notification,
                including_kwargs=True,
            )

            self.assertEquals(args, ())  # no positional arguments
            self.assertEqual(kwargs['scope_name'],
                             NotificationScopes.WORKGROUP)
            self.assertEqual(kwargs['scope_context'],
                             {'workgroup_id': group_id})
            self.assertIsNotNone(kwargs['send_at'])
            self.assertEqual(kwargs['ignore_if_past_due'], ignore_if_past_due)
            message = kwargs['msg']
            self.assertEqual(message.msg_type.name,
                             NotificationMessageTypes.GRADES_POSTED)
            self.assertEqual(message.namespace, unicode(course_id))
            self.assertEqual(message.payload['activity_name'], 'Activity Name')

            patched_link_params.assert_called_once_with({
                'course_id':
                unicode(course_id),
                'location':
                unicode(block.location)
            })
Пример #8
0
from tests.utils import parse_time, parse_datetime

START_RANGE = parse_datetime("2018-02-28T21:57:13Z")
END_RANGE = parse_datetime("2018-03-01T22:10:56Z")

STANDARD_CYCLE = {
    "start": parse_time("06:00"),
    "end": parse_time("22:00"),
    "ocurrencies": [
        (parse_datetime("2018-02-28T21:57:13Z"),
         parse_datetime("2018-02-28T22:00:00Z")),
        (parse_datetime("2018-03-01T06:00:00Z"),
         parse_datetime("2018-03-01T22:00:00Z"))
    ]
}

REDUCED_CYCLE = {
    "start": parse_time("22:00"),
    "end": parse_time("06:00"),
    "ocurrencies": [
        (parse_datetime("2018-02-28T22:00:00Z"),
         parse_datetime("2018-03-01T06:00:00Z")),
        (parse_datetime("2018-03-01T22:00:00Z"),
         parse_datetime("2018-03-01T22:10:56Z"))
    ]
}