Beispiel #1
0
    def test_to_data_object(self):
        """
        Test that we can create a NotificationMessage from a SQLNotificationMessage
        """
        orm_obj = SQLNotificationMessage(id=1, msg_type=SQLNotificationType())

        msg = orm_obj.to_data_object()
        self.assertIsNotNone(msg)
    def test_to_data_object(self):
        """
        Test that we can create a NotificationMessage from a SQLNotificationMessage
        """
        orm_obj = SQLNotificationMessage(
            id=1,
            msg_type=SQLNotificationType()
        )

        msg = orm_obj.to_data_object()
        self.assertIsNotNone(msg)
Beispiel #3
0
    def test_from_data_object(self):
        """
        Make sure we can hydrate a SQLNotificationMessage from a NotificationMessage
        """

        msg_type = NotificationType(
            name='foo.bar.baz',
            renderer='foo.renderer',
        )

        msg = NotificationMessage(id=2, msg_type=msg_type)

        orm_obj = SQLNotificationMessage.from_data_object(msg)

        self.assertEqual(orm_obj.id, msg.id)
    def test_from_data_object(self):
        """
        Make sure we can hydrate a SQLNotificationMessage from a NotificationMessage
        """

        msg_type = NotificationType(
            name='foo.bar.baz',
            renderer='foo.renderer',
        )

        msg = NotificationMessage(
            id=2,
            msg_type=msg_type
        )

        orm_obj = SQLNotificationMessage.from_data_object(msg)

        self.assertEqual(orm_obj.id, msg.id)
    def save_notification_message(self, msg):
        """
        Saves a passed in NotificationMsg data object. If 'id' is set by the caller
        it will try to update the object. If it does not exist it will throw an
        exception.

        If it is created, then the id property will be set on the NotificationMsg and returned
        """

        if msg.id:
            try:
                obj = SQLNotificationMessage.objects.get(id=msg.id)
                obj.load_from_data_object(msg)
            except ObjectDoesNotExist:
                msg = f"Could not SQLNotificationMessage with ID {msg.id}"
                raise ItemNotFoundError()
        else:
            obj = SQLNotificationMessage.from_data_object(msg)

        obj.save()
        return obj.to_data_object()
    def save_notification_message(self, msg):
        """
        Saves a passed in NotificationMsg data object. If 'id' is set by the caller
        it will try to update the object. If it does not exist it will throw an
        exception.

        If it is created, then the id property will be set on the NotificationMsg and returned
        """

        if msg.id:
            try:
                obj = SQLNotificationMessage.objects.get(id=msg.id)
                obj.load_from_data_object(msg)
            except ObjectDoesNotExist:
                msg = "Could not SQLNotificationMessage with ID {_id}".format(_id=msg.id)
                raise ItemNotFoundError()
        else:
            obj = SQLNotificationMessage.from_data_object(msg)

        obj.save()
        return obj.to_data_object()