def test_call_without_any_cache(self, get_credentials, get): """Calling the function without disk or in-memory cache.""" self.assertEquals( buildapi.query_repositories(), json.loads(REPOSITORIES)) self.assertEquals( buildapi.REPOSITORIES, json.loads(REPOSITORIES))
def test_with_clobber(self, get_credentials, get): """When clobber is True query_repositories should ignore both caches.""" # Using a different 'repositories' mock to make sure # query_repositories is using the right one. different_repositories = {"real-repo": "repo"} buildapi.REPOSITORIES = different_repositories with open('tmp_repositories.txt', 'w') as f: json.dump(different_repositories, f) self.assertEquals(buildapi.query_repositories(clobber=True), json.loads(REPOSITORIES))
def test_with_clobber(self, get_credentials, get): """When clobber is True query_repositories should ignore both caches.""" # Using a different 'repositories' mock to make sure # query_repositories is using the right one. different_repositories = {"real-repo": "repo"} buildapi.REPOSITORIES = different_repositories with open('tmp_repositories.txt', 'w') as f: json.dump(different_repositories, f) self.assertEquals( buildapi.query_repositories(clobber=True), json.loads(REPOSITORIES))
def test_file_cache(self): """Calling the function without in-memory caching but with file cache.""" buildapi.REPOSITORIES = {} # Using a different 'repositories' mock to make sure # query_repositories is using the right one. different_repositories = {"real-repo": "repo"} with open('tmp_repositories.txt', 'w') as f: json.dump(different_repositories, f) self.assertEquals(buildapi.query_repositories(), different_repositories)
def test_file_cache(self): """Calling the function without in-memory caching but with file cache.""" buildapi.REPOSITORIES = {} # Using a different 'repositories' mock to make sure # query_repositories is using the right one. different_repositories = {"real-repo": "repo"} with open('tmp_repositories.txt', 'w') as f: json.dump(different_repositories, f) self.assertEquals( buildapi.query_repositories(), different_repositories)
def query_repo_name_from_buildername(buildername, clobber=False): """Return the repository name from a given buildername.""" repositories = buildapi.query_repositories(clobber) ret_val = None for repo_name in repositories: if repo_name in buildername: ret_val = repo_name break if ret_val is None and not clobber: # Since repositories file is cached, it can be that something has changed. # Adding clobber=True will make it overwrite the cached version with latest one. query_repo_name_from_buildername(buildername, clobber=True) if ret_val is None: raise Exception("Repository name not found in buildername. " "Please provide a correct buildername.") return ret_val
def query_repo_name_from_buildername(buildername, clobber=False): """ Return the repository name from a given buildername. Raises MozciError if there is no repository name in buildername. """ repositories = buildapi.query_repositories(clobber) ret_val = None for repo_name in repositories: if any(True for iterable in [' %s ', '_%s_', '-%s-'] if iterable % repo_name in buildername): ret_val = repo_name break if ret_val is None and not clobber: # Since repositories file is cached, it can be that something has changed. # Adding clobber=True will make it overwrite the cached version with latest one. query_repo_name_from_buildername(buildername, clobber=True) if ret_val is None: raise MozciError("Repository name not found in buildername. " "Please provide a correct buildername.") return ret_val
def query_repositories(): """Return all information about the repositories we have.""" return buildapi.query_repositories()
def test_in_memory_cache(self): """Calling the function without disk cache but with in-memory cache.""" buildapi.REPOSITORIES = json.loads(REPOSITORIES) self.assertEquals(buildapi.query_repositories(), json.loads(REPOSITORIES))
def test_call_without_any_cache(self, get_credentials, get): """Calling the function without disk or in-memory cache.""" self.assertEquals(buildapi.query_repositories(), json.loads(REPOSITORIES)) self.assertEquals(buildapi.REPOSITORIES, json.loads(REPOSITORIES))
def test_in_memory_cache(self): """Calling the function without disk cache but with in-memory cache.""" buildapi.REPOSITORIES = json.loads(REPOSITORIES) self.assertEquals( buildapi.query_repositories(), json.loads(REPOSITORIES))