[ovirt-devel] Mocks for oVirt Python SDK code
Piotr Kliczewski
piotr.kliczewski at gmail.com
Wed Aug 16 09:22:16 UTC 2017
On Mon, Aug 14, 2017 at 1:39 PM, Barak Korren <bkorren at redhat.com> wrote:
> On 14 August 2017 at 14:21, Yaniv Kaul <ykaul at redhat.com> wrote:
>> I was wondering if there are any examples of mocks written for code written
>> on top of the oVirt Python SDK.
>> I would assume there will be a different a call mocking sdk.Connection()
>> that would return a mock'ed object and from there continue?
>>
>> Context: I'm looking into writing an oVirt driver for some project. They
>> (rightfully so) ask for unit tests, using mocks, fixtures, etc. I'm unsure
>> this is really going to be easy or meaningful, but I thought I'd look into
>> it...
We used [1] in ovirt provider to record http interactions and replay them during
specific unit tests. For python there is [2] and it could be used in the same
way. Sadly sdk uses native client so it is not that easy to record interactions.
As workaround we started to dump objects to yaml [3] during recording run
and later load them during the tests.
[1] https://rubygems.org/gems/vcr/versions/3.0.3
[2] https://github.com/kevin1024/vcrpy
[3] https://github.com/ManageIQ/manageiq-providers-ovirt/tree/master/spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher/response_yamls
>
> A little aside, but I typically find that if you have to write any
> mocks of your own rather then using the python-mock package
> (unitest.mock in Python3), it means you're probably doing systems
> tests instead of unit tests, or your code design is not very testable.
>
> --
> Barak Korren
> RHV DevOps team , RHCE, RHCi
> Red Hat EMEA
> redhat.com | TRIED. TESTED. TRUSTED. | redhat.com/trusted
> _______________________________________________
> Devel mailing list
> Devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/devel
More information about the Devel
mailing list