You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Martin! Long time no write, hope you are fine :-)
I'm testing a service that calls a method on an application (via D-Bus) as soon as the application's name is registered on the D-Bus session. I'm mocking the application using python-dbusmock, but it's not trivial because, for the way that mock objects are build, python-dbusmock first registers the service name (and it couldn't be otherwise, since we control the mock object over D-Bus), and only then we can add the objects/methods over D-Bus. This indeed causes a problem in my tests, because the service under tests will invoke the method on the application before the AddMethod() call has been done.
I thought of using a template, but since the object path, interface name and method name of the applications are not known in advance (they are read from the application's .desktop file), we would have to generate the template dynamically, and it makes the tests more complex then what they ought to be.
So I went for another solution, where I start the mock object under a different bus name (the original name with a "XXX" appended to it), add the application's method, and then register the real name. I do this last bit in this way:
This works fine, but I don't like that it uses internal variables of the mock object (that self.bus_name.get_bus() part in the RegisterName method's implementation). And it seems to me that this functionality might be useful to other people as well.
What do you think about adding a RegisterBusName method to the mock object? If you agree, I could create a PR, it doesn't sound too hard.
The text was updated successfully, but these errors were encountered:
Hello @mardy! I'm good, thanks! I hope you as well 😁
Adding a RegisterBusName() helper to the mock object seems fine to me. That would indeed be cleaner than poking in the mock's innards. Thanks in advance!
Hi Martin! Long time no write, hope you are fine :-)
I'm testing a service that calls a method on an application (via D-Bus) as soon as the application's name is registered on the D-Bus session. I'm mocking the application using python-dbusmock, but it's not trivial because, for the way that mock objects are build, python-dbusmock first registers the service name (and it couldn't be otherwise, since we control the mock object over D-Bus), and only then we can add the objects/methods over D-Bus. This indeed causes a problem in my tests, because the service under tests will invoke the method on the application before the AddMethod() call has been done.
I thought of using a template, but since the object path, interface name and method name of the applications are not known in advance (they are read from the application's .desktop file), we would have to generate the template dynamically, and it makes the tests more complex then what they ought to be.
So I went for another solution, where I start the mock object under a different bus name (the original name with a "XXX" appended to it), add the application's method, and then register the real name. I do this last bit in this way:
This works fine, but I don't like that it uses internal variables of the mock object (that
self.bus_name.get_bus()
part in the RegisterName method's implementation). And it seems to me that this functionality might be useful to other people as well.What do you think about adding a
RegisterBusName
method to the mock object? If you agree, I could create a PR, it doesn't sound too hard.The text was updated successfully, but these errors were encountered: