def test_it_retrieves_unstored_refs_via_urlopen(self): ref = "http://bar#baz" schema = {"baz": 12} with mock.patch("jsonschema.validators.requests", None): with mock.patch("jsonschema.validators.urlopen") as urlopen: urlopen.return_value.read.return_value = json.dumps(schema).encode("utf8") with self.resolver.resolving(ref) as resolved: self.assertEqual(resolved, 12) urlopen.assert_called_once_with("http://bar")
def test_it_retrieves_unstored_refs_via_urlopen(self): ref = "http://bar#baz" schema = {"baz": 12} with mock.patch("jsonschema.validators.requests", None): with mock.patch("jsonschema.validators.urlopen") as urlopen: urlopen.return_value.read.return_value = ( json.dumps(schema).encode("utf8")) with self.resolver.resolving(ref) as resolved: self.assertEqual(resolved, 12) urlopen.assert_called_once_with("http://bar")
def test_it_retrieves_unstored_refs_via_requests(self): ref = "http://bar#baz" schema = {"baz": 12} with mock.patch("jsonschema.validators.requests") as requests: requests.get.return_value.json.return_value = schema with self.resolver.resolving(ref) as resolved: self.assertEqual(resolved, 12) requests.get.assert_called_once_with("http://bar")
def test_it_retrieves_unstored_refs_via_requests(self): ref = "http://bar#baz" schema = {"baz" : 12} with mock.patch("jsonschema.validators.requests") as requests: requests.get.return_value.json.return_value = schema with self.resolver.resolving(ref) as resolved: self.assertEqual(resolved, 12) requests.get.assert_called_once_with("http://bar")
def test_if_a_version_is_provided_it_is_registered(self): with mock.patch("jsonschema.validators.validates") as validates: validates.side_effect = lambda version: lambda cls: cls Validator = validators.create( meta_schema={u"id": ""}, version="my version", ) validates.assert_called_once_with("my version") self.assertEqual(Validator.__name__, "MyVersionValidator")
def setUp(self): mock_open = mock.mock_open() patch_open = mock.patch.object(cli, "open", mock_open, create=True) patch_open.start() self.addCleanup(patch_open.stop) mock_json_load = mock.Mock() mock_json_load.return_value = {} patch_json_load = mock.patch("json.load") patch_json_load.start() self.addCleanup(patch_json_load.stop)
def test_it_retrieves_unstored_refs_via_urlopen(self): ref = "http://bar#baz" schema = {"baz": 12} @contextmanager def fake_urlopen(url): self.assertEqual(url, "http://bar") yield BytesIO(json.dumps(schema).encode("utf8")) with MockImport("requests", None): with mock.patch("jsonschema.validators.urlopen", fake_urlopen): with self.resolver.resolving(ref) as resolved: pass self.assertEqual(resolved, 12)
def setUp(self): patch = mock.patch("jsonschema.validators.requests") requests = patch.start() requests.get.side_effect = self.resolve self.addCleanup(patch.stop)
def test_if_a_version_is_not_provided_it_is_not_registered(self): with mock.patch("jsonschema.validators.validates") as validates: create(meta_schema={u"id": "id"}) self.assertFalse(validates.called)
def test_if_a_version_is_not_provided_it_is_not_registered(self): with mock.patch("jsonschema.validators.validates") as validates: create(meta_schema={"id" : "id"}) self.assertFalse(validates.called)
def test_uses_pprint(self): with mock.patch("pprint.pformat") as pformat: str(self.make_error()) self.assertEqual(pformat.call_count, 2) # schema + instance