def test_geturl_posts_data(self): mock_urlopen = self.patch(maas_api_helper.urllib.request.urlopen) post_data = {factory.make_name("key"): factory.make_name("value")} maas_api_helper.geturl( "http://%s" % factory.make_hostname(), post_data=post_data ) self.assertThat( mock_urlopen, MockCalledOnceWith( ANY, data=urllib.parse.urlencode(post_data).encode("ascii") ), )
def test_geturl_sends_request(self): self.assertEquals( "mock response", maas_api_helper.geturl( "http://%s" % factory.make_hostname(), {} ).read(), )
def test_geturl_no_retry(self): mock_urlopen = self.patch(maas_api_helper.urllib.request.urlopen) maas_api_helper.geturl("http://example.com", retry=False) mock_urlopen.assert_called_once()