def add_remove_update_test(self): f = os.path.join(temp_folder(), "aux_file") save(f, dump_registry(default_remotes, {}, {})) registry = RemoteRegistry(f, TestBufferConanOutput()) # Add registry.remotes.add("local", "http://localhost:9300") self.assertEqual(registry.remotes.list, [("conan-center", "https://conan.bintray.com", True), ("local", "http://localhost:9300", True)]) # Add registry.remotes.add("new", "new_url", False) self.assertEqual(registry.remotes.list, [("conan-center", "https://conan.bintray.com", True), ("local", "http://localhost:9300", True), ("new", "new_url", False)]) with self.assertRaises(ConanException): registry.remotes.add("new", "new_url") # Update registry.remotes.update("new", "other_url") self.assertEqual(registry.remotes.list, [("conan-center", "https://conan.bintray.com", True), ("local", "http://localhost:9300", True), ("new", "other_url", True)]) with self.assertRaises(ConanException): registry.remotes.update("new2", "new_url") registry.remotes.update("new", "other_url", False) self.assertEqual(registry.remotes.list, [("conan-center", "https://conan.bintray.com", True), ("local", "http://localhost:9300", True), ("new", "other_url", False)]) # Remove registry.remotes.remove("local") self.assertEqual(registry.remotes.list, [("conan-center", "https://conan.bintray.com", True), ("new", "other_url", False)]) with self.assertRaises(ConanException): registry.remotes.remove("new2")
def _get_registry(): f = os.path.join(temp_folder(), "aux_file") remotes, refs = load_registry_txt( "conan.io https://server.conan.io True\n" "conan.io2 https://server2.conan.io True\n") reg = dump_registry(remotes, refs, {}) save(f, reg) return RemoteRegistry(f, TestBufferConanOutput())
def registry(self): reg_json_path = join(self.conan_folder, REGISTRY_JSON) if not os.path.exists(reg_json_path): # Load the txt if exists and convert to json reg_txt = join(self.conan_folder, REGISTRY) if os.path.exists(reg_txt): migrate_registry_file(reg_txt, reg_json_path) else: self._output.warn("Remotes registry file missing, " "creating default one in %s" % reg_json_path) save(reg_json_path, dump_registry(default_remotes, {}, {})) return reg_json_path
def refs_test(self): f = os.path.join(temp_folder(), "aux_file") save(f, dump_registry(default_remotes, {}, {})) registry = RemoteRegistry(f, TestBufferConanOutput()) ref = ConanFileReference.loads("MyLib/0.1@lasote/stable") remotes = registry.remotes.list registry.refs.set(ref, remotes[0].name) remote = registry.refs.get(ref) self.assertEqual(remote, remotes[0]) registry.refs.set(ref, remotes[0].name) remote = registry.refs.get(ref) self.assertEqual(remote, remotes[0])
def update_servers(self): save(self.client_cache.registry_path, dump_registry({}, {}, {})) registry = self.client_cache.registry def add_server_to_registry(name, server): if isinstance(server, TestServer): registry.remotes.add(name, server.fake_url) else: registry.remotes.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)
def remove_all_package_test(self): f = os.path.join(temp_folder(), "aux_file") save(f, dump_registry(default_remotes, {}, {})) registry = RemoteRegistry(f, TestBufferConanOutput()) registry.remotes.add("r1", "url1", True, insert=0) registry.remotes.add("r2", "url2", True, insert=0) ref = ConanFileReference.loads("MyLib/0.1@lasote/stable") ref2 = ConanFileReference.loads("MyLib2/0.1@lasote/stable") registry.prefs.set(PackageReference(ref, "1"), "r1") registry.prefs.set(PackageReference(ref, "2"), "r1") registry.prefs.set(PackageReference(ref, "3"), "r1") registry.prefs.set(PackageReference(ref, "4"), "r2") registry.prefs.set(PackageReference(ref2, "1"), "r1") registry.prefs.remove_all(ref) self.assertIsNone(registry.prefs.get(PackageReference(ref, "1"))) self.assertIsNone(registry.prefs.get(PackageReference(ref, "2"))) self.assertIsNone(registry.prefs.get(PackageReference(ref, "3"))) self.assertIsNone(registry.prefs.get(PackageReference(ref, "4"))) self.assertEquals(registry.prefs.get(PackageReference(ref2, "1")).name, "r1") registry.prefs.set(PackageReference(ref, "1"), "r1") registry.prefs.set(PackageReference(ref, "2"), "r1") registry.prefs.set(PackageReference(ref, "3"), "r1") registry.prefs.set(PackageReference(ref, "4"), "r2") registry.prefs.set(PackageReference(ref2, "1"), "r1") registry.prefs.remove_all(ref, "r1") self.assertIsNone(registry.prefs.get(PackageReference(ref, "1"))) self.assertIsNone(registry.prefs.get(PackageReference(ref, "2"))) self.assertIsNone(registry.prefs.get(PackageReference(ref, "3"))) self.assertEquals(registry.prefs.get(PackageReference(ref, "4")).name, "r2") self.assertEquals(registry.prefs.get(PackageReference(ref2, "1")).name, "r1")