Esempio n. 1
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
from dasbus.server.container import DBusContainer
from pyanaconda.core.dbus import DBus
from pyanaconda.modules.common.constants.namespaces import ANACONDA_NAMESPACE, \
    DEVICE_TREE_NAMESPACE, PARTITIONING_NAMESPACE, SOURCE_NAMESPACE, PAYLOAD_NAMESPACE

TaskContainer = DBusContainer(
    namespace=ANACONDA_NAMESPACE,
    basename="Task",
    message_bus=DBus
)

DeviceTreeContainer = DBusContainer(
    namespace=DEVICE_TREE_NAMESPACE,
    message_bus=DBus
)

PartitioningContainer = DBusContainer(
    namespace=PARTITIONING_NAMESPACE,
    message_bus=DBus
)

PayloadContainer = DBusContainer(
    namespace=PAYLOAD_NAMESPACE,
Esempio n. 2
0
class DBusContainerTestCase(unittest.TestCase):
    """Test DBus containers."""
    def setUp(self):
        self.message_bus = Mock()
        self.container = DBusContainer(namespace=("org", "Project"),
                                       basename="Object",
                                       message_bus=self.message_bus)

    def test_set_namespace(self):
        """Test set_namespace."""
        self.container.set_namespace(("org", "Another", "Project"))

        path = self.container.to_object_path(MyObject())
        self.assertEqual(path, "/org/Another/Project/Object/1")

        path = self.container.to_object_path(MyObject())
        self.assertEqual(path, "/org/Another/Project/Object/2")

    def test_to_object_path_failed(self):
        """Test failed to_object_path."""
        with self.assertRaises(TypeError) as cm:
            self.container.to_object_path(MyUnpublishable())

        self.assertEqual("Type 'MyUnpublishable' is not publishable.",
                         str(cm.exception))

        with self.assertRaises(DBusContainerError) as cm:
            self.container._find_object_path(MyObject())

        self.assertEqual("No object path found.", str(cm.exception))

    def test_to_object_path(self):
        """Test to_object_path."""
        obj = MyObject()
        path = self.container.to_object_path(obj)

        self.message_bus.publish_object.assert_called_once()
        published_path, published_obj = \
            self.message_bus.publish_object.call_args[0]

        self.assertEqual(path, "/org/Project/Object/1")
        self.assertEqual(path, published_path)
        self.assertIsInstance(published_obj, MyInterface)
        self.assertEqual(obj, published_obj.implementation)

        self.message_bus.reset_mock()

        self.assertEqual(self.container.to_object_path(obj), path)
        self.message_bus.publish_object.assert_not_called()

        self.assertEqual(self.container.to_object_path(obj), path)
        self.message_bus.publish_object.assert_not_called()

    def test_to_object_path_list(self):
        """Test to_object_path_list."""
        objects = [MyObject(), MyObject(), MyObject()]
        paths = self.container.to_object_path_list(objects)

        self.assertEqual(self.message_bus.publish_object.call_count, 3)

        self.assertEqual(paths, [
            "/org/Project/Object/1", "/org/Project/Object/2",
            "/org/Project/Object/3"
        ])

        self.message_bus.reset_mock()

        self.assertEqual(paths, self.container.to_object_path_list(objects))
        self.message_bus.publish_object.assert_not_called()

        self.assertEqual(paths, self.container.to_object_path_list(objects))
        self.message_bus.publish_object.assert_not_called()

    def test_from_object_path_failed(self):
        """Test failures."""
        with self.assertRaises(DBusContainerError) as cm:
            self.container.from_object_path(ObjPath("/org/Project/Object/1"))

        self.assertEqual("Unknown object path '/org/Project/Object/1'.",
                         str(cm.exception))

    def test_from_object_path(self):
        """Test from_object_path."""
        obj = MyObject()
        path = self.container.to_object_path(obj)

        self.assertEqual(obj, self.container.from_object_path(path))
        self.assertEqual(path, self.container.to_object_path(obj))

        self.assertEqual(obj, self.container.from_object_path(path))
        self.assertEqual(path, self.container.to_object_path(obj))

    def test_from_object_path_list(self):
        """Test from_object_path_list."""
        objects = [MyObject(), MyObject(), MyObject()]
        paths = self.container.to_object_path_list(objects)

        self.assertEqual(objects, self.container.from_object_path_list(paths))
        self.assertEqual(paths, self.container.to_object_path_list(objects))

        self.assertEqual(objects, self.container.from_object_path_list(paths))
        self.assertEqual(paths, self.container.to_object_path_list(objects))

    def test_multiple_objects(self):
        """Test multiple objects."""
        obj = MyObject()
        path = self.container.to_object_path(obj)
        self.assertEqual(path, "/org/Project/Object/1")
        self.assertEqual(obj, self.container.from_object_path(path))
        self.message_bus.publish_object.assert_called_once()
        self.message_bus.reset_mock()

        obj = MyObject()
        path = self.container.to_object_path(obj)
        self.assertEqual(path, "/org/Project/Object/2")
        self.assertEqual(obj, self.container.from_object_path(path))
        self.message_bus.publish_object.assert_called_once()
        self.message_bus.reset_mock()

        obj = MyObject()
        path = self.container.to_object_path(obj)
        self.assertEqual(path, "/org/Project/Object/3")
        self.assertEqual(obj, self.container.from_object_path(path))
        self.message_bus.publish_object.assert_called_once()
        self.message_bus.reset_mock()
Esempio n. 3
0
 def setUp(self):
     self.message_bus = Mock()
     self.container = DBusContainer(namespace=("org", "Project"),
                                    basename="Object",
                                    message_bus=self.message_bus)
Esempio n. 4
0
#
# The common definitions
#
from dasbus.connection import SessionMessageBus
from dasbus.identifier import DBusServiceIdentifier, DBusInterfaceIdentifier
from dasbus.server.container import DBusContainer

# Define the message bus.
SESSION_BUS = SessionMessageBus()

# Define namespaces.
CHAT_NAMESPACE = ("org", "example", "Chat")
ROOMS_NAMESPACE = (*CHAT_NAMESPACE, "Rooms")

# Define services and objects.
CHAT = DBusServiceIdentifier(namespace=CHAT_NAMESPACE, message_bus=SESSION_BUS)

ROOM = DBusInterfaceIdentifier(namespace=CHAT_NAMESPACE, basename="Room")

# Define containers.
ROOM_CONTAINER = DBusContainer(namespace=ROOMS_NAMESPACE,
                               message_bus=SESSION_BUS)