[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Pulp-list] Agent decoupling



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Followup:

I had to take it a step further. The usage of gofer is to call
Agent().Repo().method. So using the approach I suggested still doesn't
work, since you can never get a reference to the actual object created
by your mock agent since it's a new object only used in a single
invocation of the API call and then thrown away.

I'm changing the abstraction to have factory methods for the consumer
proxies themselves:


def retrieve_repo_proxy(uuid, **options):
    '''
    Utility factory method for retrieving the repo proxy to a consumer.

    @param uuid: uuid of the consumer
    @type  uuid: string

    @param options: options to the underlying message bus
    @type  options: dict
    '''
    agent = retrieve_agent(uuid, **options)
    return agent.Repo()



That way, in your unit test you make an instance of a mock with whatever
testing needs you have and monkey patch the individual factory method to
return that mock:



class MockRepoProxy(object):

    def bind(self):
        print('Calling bind')

MOCK_REPO_PROXY = MockRepoProxy()

def retrieve_mock_repo_proxy(uuid, **options):
    return MOCK_REPO_PROXY

pulp.server.agent.retrieve_repo_proxy = retrieve_mock_repo_proxy




Then in the API, when bind retrieves the repo proxy it'll get my mock
and I can control it's behavior to simulate error conditions and log
invocations in the test.



On 02/24/2011 02:37 PM, Jay Dobies wrote:
> As part of the bind refactor, I'm adding test cases for the bind API
> call. Currently, the agent call is tightly coupled into the API call:
> 
> def bind(self, id, repoid):
> [snip]
>         agent = Agent(id, async=True)
>         repolib = agent.Repo()
>         repolib.update()
> 
> That doesn't let us mock out the qpidd call, so if we had unit tests for
> any non-async agent calls they would fail because the receiver wasn't
> present.
> 
> It's best to just mock out something like a message bus connection in a
> unit test (the tests for the Agent itself can be handled separately), so
> I added a factory method to agent.py.
> 
> Going forward, instead of instantiating an Agent object directly in the
> API, use the factory method (agent.retrieve_agent()). That way we can
> monkey patch that method in the API unit test to return a mock so we can
> track that the API methods are invoking the correct methods on an agent,
> just not doing them over a live bus.
> 
> That factory method currently exists in the bind-refactor branch and
> should be in master in the next few days.
> 

_______________________________________________
Pulp-list mailing list
Pulp-list redhat com
https://www.redhat.com/mailman/listinfo/pulp-list


- -- 
Jay Dobies
RHCE# 805008743336126
Freenode: jdob
http://pulpproject.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNZr5cAAoJEOMmcTqOSQHC2/oH/jwiUYINUgJ5JVOdzjDudfsh
hkVGW9zaRsx0LThjpSiOvc0YqqkEqoHHCxUJ1nvVXZqOg01Yd4aviQzGG/Cqht99
fjP5sXoCKI0QuGTKs86k5kvTYg2UuwhXIBri+xnYWDPsaUsuv5nacC33Y3A0UqLx
exxeFiH+5pZsJPQ6Hje60JV+DWYwsyx9Y7XQc6ZIhMkXv3zW3CMu7Emr8Xnq29AB
oBcynyYZkEELz4mwjrPdAvGvDr7axFmXb8Xo29sUMCJa6gFY6I8vtBxl43i7O4GL
SgclcjGUGYvAELr3oANSTW0p3j4oVhKk+5ZgcsXbzhTtyGxBl8PcGG0cmgEv3QI=
=KT/q
-----END PGP SIGNATURE-----


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]