def enable_disable_remotes_test(self): f = os.path.join(temp_folder(), "aux_file") Remotes().save(f) cache = ClientCache(os.path.dirname(f), TestBufferConanOutput()) registry = cache.registry registry.add("local", "http://localhost:9300") registry.set_disabled_state("local", True) self.assertEqual( list(registry.load_remotes().all_values()), [("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, True)]) self.assertEqual( list(registry.load_remotes().values()), [("conan-center", "https://conan.bintray.com", True, False)]) registry.set_disabled_state("conan-center", True) self.assertEqual( list(registry.load_remotes().all_values()), [("conan-center", "https://conan.bintray.com", True, True), ("local", "http://localhost:9300", True, True)]) self.assertEqual(list(registry.load_remotes().values()), []) registry.set_disabled_state("*", False) self.assertEqual( list(registry.load_remotes().values()), [("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, False)]) registry.set_disabled_state("*", True) self.assertEqual(list(registry.load_remotes().values()), [])
def build_consumer(self, path, profile_build_requires=None, ref=None, create_ref=None, install=True): profile = Profile() if profile_build_requires: profile.build_requires = profile_build_requires profile.process_settings(self.cache) update = check_updates = False recorder = ActionRecorder() remotes = Remotes() build_mode = [] # Means build all ref = ref or ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile, options, root_ref=ref) app = self._get_app() deps_graph = app.graph_manager.load_graph(path, create_ref, graph_info, build_mode, check_updates, update, remotes, recorder) if install: binary_installer = BinaryInstaller(app, recorder) build_mode = BuildMode(build_mode, app.out) binary_installer.install(deps_graph, None, build_mode, update, False, graph_info) return deps_graph
def _build_graph(self, profile_host, profile_build, install=False): path = temp_folder() path = os.path.join(path, "conanfile.txt") save(path, textwrap.dedent(""" [requires] app/testing@user/channel """)) ref = ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile_host=profile_host, profile_build=profile_build, options=options, root_ref=ref) recorder = ActionRecorder() app = self._get_app() deps_graph = app.graph_manager.load_graph(path, create_reference=None, graph_info=graph_info, build_mode=[], check_updates=False, update=False, remotes=Remotes(), recorder=recorder) if install: build_mode = [] # Means build all binary_installer = BinaryInstaller(app, recorder) build_mode = BuildMode(build_mode, app.out) binary_installer.install(deps_graph, None, build_mode, update=False, profile_host=profile_host, profile_build=profile_build, graph_lock=None, keep_build=False) return deps_graph
def test_remote_none(self): """ RemoteRegistry should be able to deal when the URL is None """ f = os.path.join(temp_folder(), "add_none_test") Remotes().save(f) cache = ClientCache(os.path.dirname(f), TestBufferConanOutput()) registry = cache.registry registry.add("foobar", None) self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("foobar", None, True, False)]) self.assertIn( "WARN: The URL is empty. It must contain scheme and hostname.", cache._output) registry.remove("foobar") registry.update("conan-center", None) self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", None, True, False)]) self.assertIn( "WARN: The URL is empty. It must contain scheme and hostname.", cache._output)
def build_graph(self, content, profile_build_requires=None, ref=None, create_ref=None, install=True): path = temp_folder() path = os.path.join(path, "conanfile.py") save(path, str(content)) self.loader.cached_conanfiles = {} profile = Profile() if profile_build_requires: profile.build_requires = profile_build_requires profile.process_settings(self.cache) update = check_updates = False recorder = ActionRecorder() remotes = Remotes() build_mode = [] # Means build all ref = ref or ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile, options, root_ref=ref) deps_graph, _ = self.manager.load_graph(path, create_ref, graph_info, build_mode, check_updates, update, remotes, recorder) if install: self.binary_installer.install(deps_graph, None, False, graph_info) return deps_graph
def test_returns_on_failures(self): test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")]) servers = {"default": test_server} class Response(object): ok = None status_code = None charset = None text = "" headers = {} def __init__(self, ok, status_code): self.ok = ok self.status_code = status_code class BuggyRequester(object): def __init__(self, *args, **kwargs): pass def get(self, *args, **kwargs): return Response(False, 404) client2 = TestClient(servers=servers, requester_class=BuggyRequester) ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable") installer = ConanProxy(client2.cache, client2.user_io.out, client2.remote_manager) remotes = Remotes() remotes.add("remotename", "url") with self.assertRaises(NotFoundException): installer.get_recipe(ref, False, False, remotes, ActionRecorder()) class BuggyRequester2(BuggyRequester): def get(self, *args, **kwargs): return Response(False, 500) client2 = TestClient(servers=servers, requester_class=BuggyRequester2) installer = ConanProxy(client2.cache, client2.user_io.out, client2.remote_manager) try: installer.get_recipe(ref, False, False, remotes, ActionRecorder()) except NotFoundException: self.assertFalse(True) # Shouldn't capture here except ConanException: pass
def registry(self): if not self._registry: remotes_path = self.registry_path if not os.path.exists(remotes_path): self._output.warn("Remotes registry file missing, " "creating default one in %s" % remotes_path) remotes = Remotes.defaults() remotes.save(remotes_path) self._registry = RemoteRegistry(self) return self._registry
def test_add_remove_update(self): f = os.path.join(temp_folder(), "aux_file") Remotes().save(f) cache = ClientCache(os.path.dirname(f), TestBufferConanOutput()) registry = cache.registry # Add registry.add("local", "http://localhost:9300") self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, False)]) # Add registry.add("new", "new_url", False) self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, False), ("new", "new_url", False, False)]) with self.assertRaises(ConanException): registry.add("new", "new_url") # Update registry.update("new", "other_url") self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, False), ("new", "other_url", True, False)]) with self.assertRaises(ConanException): registry.update("new2", "new_url") registry.update("new", "other_url", False) self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("local", "http://localhost:9300", True, False), ("new", "other_url", False, False)]) # Remove registry.remove("local") self.assertEqual( list(registry.load_remotes().values()), [("conancenter", "https://center.conan.io", True, False), ("conan-center", "https://conan.bintray.com", True, False), ("new", "other_url", False, False)]) with self.assertRaises(ConanException): registry.remove("new2")
def update_servers(self): cache = self.cache Remotes().save(cache.remotes_path) registry = cache.registry for name, server in self.servers.items(): if isinstance(server, ArtifactoryServer): registry.add(name, server.repo_api_url) self.users.update({name: [(ARTIFACTORY_DEFAULT_USER, ARTIFACTORY_DEFAULT_PASSWORD)]}) elif isinstance(server, TestServer): registry.add(name, server.fake_url) else: registry.add(name, server)
def _get_app(self): self.remote_manager = MockRemoteManager() cache = self.cache self.resolver = RangeResolver(self.cache, self.remote_manager) proxy = ConanProxy(cache, self.output, self.remote_manager) pyreq_loader = PyRequireLoader(proxy, self.resolver) pyreq_loader.enable_remotes(remotes=Remotes()) self.loader = ConanFileLoader(None, self.output, ConanPythonRequire(None, None), pyreq_loader=pyreq_loader) binaries = GraphBinariesAnalyzer(cache, self.output, self.remote_manager) self.manager = GraphManager(self.output, cache, self.remote_manager, self.loader, proxy, self.resolver, binaries) generator_manager = GeneratorManager() hook_manager = Mock() app_type = namedtuple("ConanApp", "cache out remote_manager hook_manager graph_manager" " binaries_analyzer generator_manager") app = app_type(self.cache, self.output, self.remote_manager, hook_manager, self.manager, binaries, generator_manager) return app
def update_servers(self): Remotes().save(self.cache.registry_path) registry = self.cache.registry def add_server_to_registry(name, server): if isinstance(server, ArtifactoryServer): registry.add(name, server.repo_api_url) self.users.update({name: [(ARTIFACTORY_DEFAULT_USER, ARTIFACTORY_DEFAULT_PASSWORD)]}) elif isinstance(server, TestServer): registry.add(name, server.fake_url) else: registry.add(name, server) for name, server in self.servers.items(): if name == "default": add_server_to_registry(name, server) for name, server in self.servers.items(): if name != "default": add_server_to_registry(name, server)