def test_disambiguate_with_abbreviated_site(self): with self.config: self.config.get_workspaces('bitbucket').returns(['ripio-test']) self.config.get_workspaces('github').returns(['ripio-test']) sut = ripio.Completion('gh:ripio', self.config) self.assertEquals(sut.found, ['github:ripio-test/ripio'])
def test_public_repo_and_default_bitbucket_workspace(self): with self.config: self.config.get_credentials('bitbucket').returns( ripio.Credentials(BITBUCKET_CREDENTIALS)) sut = ripio.Completion('ripio', self.config) self.assertEquals(sut.found, ['bitbucket:DavidVilla/ripio'])
def test_bitbucket_private_repo_without_credentials(self): with self.config: self.config.get_workspaces('bitbucket').returns(['ripio-test']) sut = ripio.Completion('private', self.config) self.assertEquals(sut.found, []) self.assertEquals(sut.denied, ['bitbucket:ripio-test/private'])
def test_one_match(self): with self.config: self.config.get_workspaces('bitbucket').returns( ['DavidVilla', 'ripio-test']) sut = ripio.Completion('repo0', self.config) self.assertEquals(sut.found, ['bitbucket:ripio-test/repo0'])
def get_repo(config, name=None, guess=True): name = name or config.repo try: repo_ref = ripio.RepoRef(name) print(f"- repository identity is '{repo_ref}'") except ripio.BadRepositoryName: if not guess: raise # FIXME: refactor this handler print(f"- trying to complete '{name}' at known workspaces...") completion = ripio.Completion(name, config.config_file) if len(completion.found) == 1: repo_ref = ripio.RepoRef(completion.found[0]) print("- guessing '{}'".format(repo_ref)) elif len(completion.found) > 1: print("- serveral completions found:") for r in completion.found: print(f" - {r}") sys.exit(1) return ripio.Repo.make(repo_ref, config.credentials)
def test_github_private_repo_without_credentials(self): with self.config as c: c.get_workspaces('github').returns(['ripio-test']) with self.assertRaises(ripio.WrongCompletion): sut = ripio.Completion('private', self.config) self.assertEquals(sut.found, []) self.assertEquals(sut.denied, ['github:ripio-test/private'])
def test_match_in_two_sites(self): with self.config: self.config.get_workspaces('bitbucket').returns(['ripio-test']) self.config.get_workspaces('github').returns(['ripio-test']) sut = ripio.Completion('ripio', self.config) self.assertEquals( sut.found, ['bitbucket:ripio-test/ripio', 'github:ripio-test/ripio'])
def test_no_matches(self): with self.config: self.config.get_workspaces('bitbucket').returns(['ripio-test']) with self.assertRaises(ripio.WrongCompletion): ripio.Completion('missing', self.config)
def test_no_workspaces_in_config(self): with self.assertRaises(ripio.ConfigError): ripio.Completion('repo0', self.config)