def test_as_str_in_neuro_registry_tag_yes(self) -> None: image = RemoteImage(name="ubuntu", tag="v10.04", owner="me", registry="registry.io") assert str(image) == "image://me/ubuntu:v10.04" assert _as_repo_str(image) == "registry.io/me/ubuntu:v10.04"
def test_as_str_not_in_neuro_registry_tag_yes(self) -> None: image = RemoteImage(name="ubuntu", tag="v10.04", owner=None, registry=None) assert str(image) == "ubuntu:v10.04" assert _as_repo_str(image) == "ubuntu:v10.04"
def test_convert_to_local_image(self) -> None: neuro_image = RemoteImage(name="ubuntu", tag="latest", owner="artem", registry="reg.com") local_image = self.parser.convert_to_local_image(neuro_image) assert local_image == LocalImage(name="ubuntu", tag="latest")
def test_convert_to_neuro_image(self) -> None: local_image = LocalImage(name="ubuntu", tag="latest") neuro_image = self.parser.convert_to_neuro_image(local_image) assert neuro_image == RemoteImage(name="ubuntu", tag="latest", owner="alice", registry="reg.neu.ro")
def test_parse_as_neuro_image_with_scheme_tilde_user_no_tag(self) -> None: image = "image://~/ubuntu" parsed = self.parser.parse_as_neuro_image(image) assert parsed == RemoteImage(name="ubuntu", tag="latest", owner="alice", registry="reg.neu.ro")
def test_parse_as_neuro_image_with_scheme_with_user_no_tag_2(self) -> None: image = "image://bob/library/ubuntu" parsed = self.parser.parse_as_neuro_image(image) assert parsed == RemoteImage(name="library/ubuntu", tag="latest", owner="bob", registry="reg.neu.ro")
def test_parse_as_neuro_image_with_scheme_with_user_with_tag(self) -> None: image = "image://bob/ubuntu:v10.04" parsed = self.parser.parse_as_neuro_image(image) assert parsed == RemoteImage(name="ubuntu", tag="v10.04", owner="bob", registry="reg.neu.ro")
async def test_tags_bad_image_without_name( self, make_client: _MakeClient) -> None: url = URL("http://whatever") registry_url = URL("http://whatever-registry") async with make_client(url, registry_url=registry_url) as client: image = RemoteImage(name="", tag=None, owner="me", registry="reg") with pytest.raises(ValueError, match="missing image name"): await client.images.tags(image)
def test_parse_as_neuro_image_allow_tag_false_with_scheme_no_tag( self) -> None: image = "image:ubuntu" parsed = self.parser.parse_as_neuro_image(image, allow_tag=False) assert parsed == RemoteImage(name="ubuntu", tag=None, owner="alice", registry="reg.neu.ro")
def test_parse_as_neuro_image_with_scheme_tilde_user_with_tag_2( self) -> None: image = "image://~/library/ubuntu:v10.04" parsed = self.parser.parse_as_neuro_image(image) assert parsed == RemoteImage(name="library/ubuntu", tag="v10.04", owner="alice", registry="reg.neu.ro")
def test_parse_remote__registry_has_port__image_in_good_repo(self) -> None: my_parser = _ImageNameParser(default_user="******", registry_url=URL("http://localhost:5000")) image = "localhost:5000/bob/library/ubuntu:v10.04" parsed = my_parser.parse_remote(image) assert parsed == RemoteImage(name="library/ubuntu", tag="v10.04", owner="bob", registry="localhost:5000")
async def test_tags_bad_image_with_tag(self, make_client: _MakeClient) -> None: url = URL("http://whatever") registry_url = URL("http://whatever-registry") async with make_client(url, registry_url=registry_url) as client: image = RemoteImage(name="ubuntu", tag="latest", owner="me", registry="reg") with pytest.raises(ValueError, match="tag is not allowed"): await client.images.tags(image)
async def test_ls_images(self, aiohttp_server: _TestServerFactory, make_client: _MakeClient) -> None: JSON = {"repositories": ["image://bob/alpine", "image://jill/bananas"]} async def handler(request: web.Request) -> web.Response: return web.json_response(JSON) app = web.Application() app.router.add_get("/v2/_catalog", handler) srv = await aiohttp_server(app) url = "http://platform" registry_url = srv.make_url("/v2/") async with make_client(url, registry_url=registry_url) as client: ret = await client.images.ls() registry = _get_url_authority(registry_url) assert set(ret) == { RemoteImage("alpine", tag=None, owner="bob", registry=registry), RemoteImage("bananas", tag=None, owner="jill", registry=registry), }
def test_parse_remote__registry_has_port__image_in_other_repo( self) -> None: my_parser = _ImageNameParser(default_user="******", registry_url=URL("http://localhost:5000")) image = "example.com:9999/bob/library/ubuntu:v10.04" parsed = my_parser.parse_remote(image) # NOTE: "owner" is parsed only for images in neuromation registry assert parsed == RemoteImage( name="bob/library/ubuntu", tag="v10.04", owner=None, registry="example.com:9999", )