| 
18 | 18 | # However, if you have executed another commercial license agreement  | 
19 | 19 | # with Crate these terms will supersede the license and you may use the  | 
20 | 20 | # software solely pursuant to the terms of the relevant commercial agreement.  | 
21 |  | - | 
 | 21 | +import json  | 
22 | 22 | import os  | 
23 | 23 | import tempfile  | 
 | 24 | +import urllib  | 
 | 25 | +from distutils.version import LooseVersion  | 
24 | 26 | from unittest import TestCase, mock  | 
25 | 27 | from io import BytesIO  | 
 | 28 | + | 
 | 29 | +import crate  | 
26 | 30 | from .layer import CrateLayer, prepend_http, http_url_from_host_port, wait_for_http_url  | 
27 | 31 | 
 
  | 
28 | 32 | 
 
  | 
@@ -58,6 +62,22 @@ def test_wait_for_http(self):  | 
58 | 62 |         addr = wait_for_http_url(log=log, timeout=1)  | 
59 | 63 |         self.assertEqual(None, addr)  | 
60 | 64 | 
 
  | 
 | 65 | +    @mock.patch.object(crate.testing.layer, "_download_and_extract", lambda uri, directory: None)  | 
 | 66 | +    def test_layer_from_uri(self):  | 
 | 67 | +        """  | 
 | 68 | +        The CrateLayer can also be created by providing an URI that points to  | 
 | 69 | +        a CrateDB tarball.  | 
 | 70 | +        """  | 
 | 71 | +        with urllib.request.urlopen("https://crate.io/versions.json") as response:  | 
 | 72 | +            versions = json.loads(response.read().decode())  | 
 | 73 | +            version = versions["crate_testing"]  | 
 | 74 | + | 
 | 75 | +        self.assertGreaterEqual(LooseVersion(version), LooseVersion("4.5.0"))  | 
 | 76 | + | 
 | 77 | +        uri = "https://cdn.crate.io/downloads/releases/crate-{}.tar.gz".format(version)  | 
 | 78 | +        layer = CrateLayer.from_uri(uri, name="crate-by-uri", http_port=42203)  | 
 | 79 | +        self.assertIsInstance(layer, CrateLayer)  | 
 | 80 | + | 
61 | 81 |     @mock.patch.dict('os.environ', {}, clear=True)  | 
62 | 82 |     def test_java_home_env_not_set(self):  | 
63 | 83 |         with tempfile.TemporaryDirectory() as tmpdir:  | 
 | 
0 commit comments