コード例 #1
0
ファイル: test_utils.py プロジェクト: jgj-magenta-aps/os2mo
    def test_get_valid_from(self):
        ts = '2018-03-21T00:00:00+01:00'
        dt = datetime.datetime(2018,
                               3,
                               21,
                               tzinfo=dateutil.tz.tzoffset(None, 3600))

        self.assertEqual(dt, util.get_valid_from({'validity': {
            'from': ts,
        }}, ))

        self.assertEqual(
            dt,
            util.get_valid_from({
                'validity': {},
            }, {'validity': {
                'from': ts,
            }}))

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {
                'validity': {},
            },
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {'validity': {}},
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {'validity': {}},
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {'validity': {
                'from': None,
            }},
        )
コード例 #2
0
def amqp_sender(trigger_dict):
    request = trigger_dict[Trigger.REQUEST]
    if trigger_dict[Trigger.REQUEST_TYPE] == Trigger.RequestType.EDIT:
        request = request['data']

    try:  # date = from or to
        date = util.get_valid_from(request)
    except exceptions.HTTPException:
        date = util.get_valid_to(request)
    action = {
        Trigger.RequestType.CREATE: "create",
        Trigger.RequestType.EDIT: "update",
        Trigger.RequestType.TERMINATE: "delete",
    }[trigger_dict[Trigger.REQUEST_TYPE]]

    amqp_messages = []

    if trigger_dict.get(Trigger.EMPLOYEE_UUID):
        amqp_messages.append((
            'employee',
            trigger_dict[Trigger.ROLE_TYPE],
            action,
            trigger_dict[Trigger.EMPLOYEE_UUID],
            date
        ))

    if trigger_dict.get(Trigger.ORG_UNIT_UUID):
        amqp_messages.append((
            'org_unit',
            trigger_dict[Trigger.ROLE_TYPE],
            action,
            trigger_dict[Trigger.ORG_UNIT_UUID],
            date
        ))

    for message in amqp_messages:
        publish_message(*message)
コード例 #3
0
ファイル: test_utils.py プロジェクト: jgj-magenta-aps/os2mo
    def test_get_validities(self):
        # start time required
        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {},
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {
                'validity': None,
            },
        )

        self.assertRaises(
            exceptions.HTTPException,
            util.get_valid_from,
            {},
            {
                'validity': {
                    'from': None,
                },
            },
        )

        # still nothing
        self.assertEqual(
            util.get_valid_to({}, {}),
            util.POSITIVE_INFINITY,
        )

        self.assertEqual(
            util.get_valid_to({}, {
                'validity': None,
            }),
            util.POSITIVE_INFINITY,
        )

        self.assertEqual(
            util.POSITIVE_INFINITY,
            util.get_valid_to({}, {
                'validity': {
                    'to': None,
                },
            }),
        )

        # actually set
        self.assertEqual(
            datetime.datetime(2018, 3, 5, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_from({
                'validity': {
                    'from': '2018-03-05',
                },
            }),
        )

        self.assertEqual(
            datetime.datetime(2018, 3, 5, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_from({
                'validity': {
                    'from': '2018-03-05',
                },
            }),
        )

        self.assertEqual(
            datetime.datetime(2018, 3, 6, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_to({
                'validity': {
                    'to': '2018-03-05',
                },
            }),
        )

        # actually set in the fallback
        self.assertEqual(
            datetime.datetime(2018, 3, 5, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_from({}, {
                'validity': {
                    'from': '2018-03-05',
                },
            }),
        )

        self.assertEqual(
            datetime.datetime(2018, 3, 6, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_to({}, {
                'validity': {
                    'to': '2018-03-05',
                },
            }),
        )

        self.assertEqual(
            datetime.datetime(2018, 3, 6, tzinfo=util.DEFAULT_TIMEZONE),
            util.get_valid_to({}, {
                'validity': {
                    'to': '2018-03-05',
                },
            }),
        )

        self.assertEqual(
            (datetime.datetime(2018, 3, 5, tzinfo=util.DEFAULT_TIMEZONE),
             datetime.datetime(2018, 4, 5, tzinfo=util.DEFAULT_TIMEZONE)),
            util.get_validities({
                'validity': {
                    'from': '2018-03-05',
                    'to': '2018-04-04',
                },
            }),
        )

        self.assertEqual(
            (datetime.datetime(2018, 3, 5, tzinfo=util.DEFAULT_TIMEZONE),
             util.POSITIVE_INFINITY),
            util.get_validities({
                'validity': {
                    'from': '2018-03-05'
                },
            }),
        )

        with self.assertRaisesRegex(exceptions.HTTPException,
                                    "End date is before start date"):
            util.get_validities({
                'validity': {
                    'from': '2019-03-05',
                    'to': '2018-03-05',
                },
            })