def test_client_call(self, mocked): c = delicious.DeliciousClient('username', 'password') res = c.foo.bar(a=1, b=2) mocked.assert_called_with( 'https://api.del.icio.us/v1/foo/bar?a=1&b=2', username = '******', password = '******' ) # # Fake delicious client that mocks all the calls update() makes. # # Quick 'n' dirty XML etree maker xml = lambda s: etree.fromstring(s.strip()) FakeClient = mock.Mock() # This makes FakeClient.__init__ do the right thing w/r/t mocking FakeClient.return_value = FakeClient FakeClient.posts.update.return_value = xml( '<update time="2009-08-18T15:30:16Z" inboxnew="0"/>' ) FakeClient.posts.dates.return_value = xml(''' <dates tag="" user="******"> <date count="1" date="2009-08-18"/> </dates> ''')
def getxml(url, **kwargs): """Fetch and parse some XML. Returns an ElementTree""" xml = fetch_resource(url, **kwargs) return etree.fromstring(xml)
@mock.patch('jellyroll.providers.utils.getxml') def test_client_call(self, mocked): c = delicious.DeliciousClient('username', 'password') res = c.foo.bar(a=1, b=2) mocked.assert_called_with('https://api.del.icio.us/v1/foo/bar?a=1&b=2', username='******', password='******') # # Fake delicious client that mocks all the calls update() makes. # # Quick 'n' dirty XML etree maker xml = lambda s: etree.fromstring(s.strip()) FakeClient = mock.Mock() # This makes FakeClient.__init__ do the right thing w/r/t mocking FakeClient.return_value = FakeClient FakeClient.posts.update.return_value = xml( '<update time="2009-08-18T15:30:16Z" inboxnew="0"/>') FakeClient.posts.dates.return_value = xml(''' <dates tag="" user="******"> <date count="1" date="2009-08-18"/> </dates> ''')