def test_write_git_changelog(self): self.useFixture(fixtures.FakePopen(lambda _: { "stdout": BytesIO(self.changelog.encode('utf-8')) })) git.write_git_changelog(git_dir=self.git_dir, dest_dir=self.temp_path) with open(os.path.join(self.temp_path, "ChangeLog"), "r") as ch_fh: changelog_contents = ch_fh.read() self.assertIn("2013.2", changelog_contents) self.assertIn("0.5.17", changelog_contents) self.assertIn("------", changelog_contents) self.assertIn("Refactor hooks file", changelog_contents) self.assertIn( "Bug fix: create\_stack() fails when waiting", changelog_contents) self.assertNotIn("Refactor hooks file.", changelog_contents) self.assertNotIn("182feb3", changelog_contents) self.assertNotIn("review/monty_taylor/27519", changelog_contents) self.assertNotIn("0.5.13", changelog_contents) self.assertNotIn("0.6.7", changelog_contents) self.assertNotIn("12", changelog_contents) self.assertNotIn("(evil)", changelog_contents) self.assertNotIn("ev()il", changelog_contents) self.assertNotIn("ev(il", changelog_contents) self.assertNotIn("ev)il", changelog_contents) self.assertNotIn("e(vi)l", changelog_contents) self.assertNotIn('Merge "', changelog_contents) self.assertNotIn('1\_foo.1', changelog_contents)
def test_write_git_changelog(self): root_dir = self._root_dir() exist_files = [os.path.join(root_dir, f) for f in ".git", ".mailmap"] self.useFixture( fixtures.MonkeyPatch( "os.path.exists", lambda path: os.path.abspath(path) in exist_files)) self.useFixture( fixtures.FakePopen(lambda _: { "stdout": StringIO.StringIO("Author: Foo Bar <*****@*****.**>\n") })) builtin_open = open def _fake_open(name, mode): if name.endswith('.mailmap'): # StringIO.StringIO doesn't have __exit__ (at least python 2.6) return io.BytesIO("Foo Bar <*****@*****.**> <*****@*****.**>\n") return builtin_open(name, mode) self.useFixture(fixtures.MonkeyPatch("__builtin__.open", _fake_open)) setup.write_git_changelog() with open("ChangeLog", "r") as ch_fh: self.assertTrue("*****@*****.**" in ch_fh.read())
def test_main_command_failed_no_caching(self): cache_dir = self.useFixture(fixtures.TempDir()) backup_cache_dir = self.useFixture(fixtures.TempDir()) fake_metadata = _setup_heat_local_metadata(self) occ_args = [ 'os-collect-config', '--command', 'foo', '--cachedir', cache_dir.path, '--backup-cachedir', backup_cache_dir.path, '--config-file', '/dev/null', '--heat_local-path', fake_metadata, ] calls = [] def capture_popen(proc_args): calls.append(proc_args) return dict(returncode=1) self.useFixture(fixtures.FakePopen(capture_popen)) self.assertEqual(1, self._call_main(occ_args)) for test_dir in (cache_dir, backup_cache_dir): cache_contents = os.listdir(test_dir.path) last_files = [n for n in cache_contents if n.endswith('last')] self.assertEqual([], last_files)
def setUp(self): super(TestGithubWebhookHandler, self).setUp() self.handlers = [] self.useFixture(fixtures.MockPatch(handler_func, new=self.handler_func)) self.fake_popen = self.useFixture(fixtures.FakePopen())
def test_write_git_changelog(self): exist_files = [ os.path.join(self.root_dir, f) for f in (".git", ".mailmap") ] self.useFixture( fixtures.MonkeyPatch( "os.path.exists", lambda path: os.path.abspath(path) in exist_files)) self.useFixture( fixtures.FakePopen( lambda _: { "stdout": BytesIO("Author: Foo Bar " "<*****@*****.**>\n".encode('utf-8')) })) def _fake_read_git_mailmap(*args): return {"*****@*****.**": "*****@*****.**"} self.useFixture( fixtures.MonkeyPatch("pbr.packaging.read_git_mailmap", _fake_read_git_mailmap)) packaging.write_git_changelog(git_dir=self.git_dir, dest_dir=self.temp_path) with open(os.path.join(self.temp_path, "ChangeLog"), "r") as ch_fh: self.assertTrue("*****@*****.**" in ch_fh.read())
def _fake_popen_call_main(self, occ_args): calls = [] def capture_popen(proc_args): calls.append(proc_args) return dict(returncode=0) self.useFixture(fixtures.FakePopen(capture_popen)) self.assertEqual(0, self._call_main(occ_args)) return calls
def test_generate_authors(self): author_old = "Foo Foo <*****@*****.**>" author_new = "Bar Bar <*****@*****.**>" co_author = "Foo Bar <*****@*****.**>" co_author_by = "Co-authored-by: " + co_author root_dir = self._root_dir() git_log_cmd = ("git --git-dir=%s log --format" % os.path.join(root_dir, '.git')) git_co_log_cmd = ("git --git-dir=%s log" % os.path.join(root_dir, '.git')) cmd_map = { git_log_cmd: author_new, git_co_log_cmd: co_author_by, } exist_files = [ os.path.join(root_dir, ".git"), os.path.abspath("AUTHORS.in") ] self.useFixture( fixtures.MonkeyPatch( "os.path.exists", lambda path: os.path.abspath(path) in exist_files)) self.useFixture( fixtures.FakePopen( lambda proc_args: { "stdout": StringIO.StringIO( self._fake_log_output(proc_args["args"][2], cmd_map)) })) with open("AUTHORS.in", "w") as auth_fh: auth_fh.write(author_old) setup.generate_authors() with open("AUTHORS", "r") as auth_fh: authors = auth_fh.read() self.assertTrue(author_old in authors) self.assertTrue(author_new in authors) self.assertTrue(co_author in authors)
def test_write_git_changelog(self): self.useFixture(fixtures.FakePopen(lambda _: { "stdout": BytesIO(_changelog_content.encode('utf-8')) })) packaging.write_git_changelog(git_dir=self.git_dir, dest_dir=self.temp_path) with open(os.path.join(self.temp_path, "ChangeLog"), "r") as ch_fh: changelog_contents = ch_fh.read() self.assertIn("2013.2", changelog_contents) self.assertIn("0.5.17", changelog_contents) self.assertIn("------", changelog_contents) self.assertIn("Refactor hooks file", changelog_contents) self.assertNotIn("Refactor hooks file.", changelog_contents) self.assertNotIn("182feb3", changelog_contents) self.assertNotIn("review/monty_taylor/27519", changelog_contents) self.assertNotIn("0.5.13", changelog_contents) self.assertNotIn('Merge "', changelog_contents)
def test_generate_authors(self): author_old = "Foo Foo <*****@*****.**>" author_new = "Bar Bar <*****@*****.**>" co_author = "Foo Bar <*****@*****.**>" co_author_by = "Co-authored-by: " + co_author git_log_cmd = ("git --git-dir=%s log --format" % self.git_dir) git_co_log_cmd = ("git log --git-dir=%s" % self.git_dir) git_top_level = "git rev-parse --show-toplevel" cmd_map = { git_log_cmd: author_new, git_co_log_cmd: co_author_by, git_top_level: self.root_dir, } exist_files = [ self.git_dir, os.path.join(self.temp_path, "AUTHORS.in") ] self.useFixture( fixtures.MonkeyPatch( "os.path.exists", lambda path: os.path.abspath(path) in exist_files)) self.useFixture( fixtures.FakePopen( lambda proc_args: { "stdout": BytesIO( self._fake_log_output(proc_args["args"][2], cmd_map)) })) with open(os.path.join(self.temp_path, "AUTHORS.in"), "w") as auth_fh: auth_fh.write("%s\n" % author_old) packaging.generate_authors(git_dir=self.git_dir, dest_dir=self.temp_path) with open(os.path.join(self.temp_path, "AUTHORS"), "r") as auth_fh: authors = auth_fh.read() self.assertTrue(author_old in authors) self.assertTrue(author_new in authors) self.assertTrue(co_author in authors)
def test_main_print_only(self): cache_dir = self.useFixture(fixtures.TempDir()) backup_cache_dir = self.useFixture(fixtures.TempDir()) fake_metadata = _setup_heat_local_metadata(self) args = [ 'os-collect-config', '--command', 'bar', '--cachedir', cache_dir.path, '--backup-cachedir', backup_cache_dir.path, '--config-file', '/dev/null', '--print', '--cfn-metadata-url', 'http://192.0.2.1:8000/v1/', '--cfn-stack-name', 'foo', '--cfn-path', 'foo.Metadata', '--cfn-access-key-id', '0123456789ABCDEF', '--cfn-secret-access-key', 'FEDCBA9876543210', '--heat_local-path', fake_metadata, ] def fake_popen(args): self.fail('Called command instead of printing') self.useFixture(fixtures.FakePopen(fake_popen)) output = self.useFixture(fixtures.StringStream('stdout')) self.useFixture(fixtures.MonkeyPatch('sys.stdout', output.stream)) self._call_main(args) out_struct = json.loads(output.getDetails()['stdout'].as_text()) self.assertThat(out_struct, matchers.IsInstance(dict)) self.assertIn('cfn', out_struct) self.assertIn('heat_local', out_struct) self.assertIn('ec2', out_struct)