def test_script(self):
        product = self.factory.makeProduct()
        self.factory.makeBug(target=product)
        self.assertEqual(0, get_bugsummary_rows(product).count())
        self.assertEqual(1, get_bugsummaryjournal_rows(product).count())
        transaction.commit()

        exit_code, out, err = run_script('scripts/bugsummary-rebuild.py')
        self.addDetail("stdout", text_content(out))
        self.addDetail("stderr", text_content(err))
        self.assertEqual(0, exit_code)

        transaction.commit()
        self.assertEqual(1, get_bugsummary_rows(product).count())
        self.assertEqual(0, get_bugsummaryjournal_rows(product).count())
 def test_rebuild_bugsummary_for_target(self):
     # rebuild_bugsummary_for_target rebuilds BugSummary for a
     # specific target from BugTaskFlat. Since it ignores the
     # journal, it also removes any relevant journal entries.
     product = self.factory.makeProduct()
     self.factory.makeBug(target=product)
     self.assertEqual(0, get_bugsummary_rows(product).count())
     self.assertEqual(1, get_bugsummaryjournal_rows(product).count())
     log = BufferLogger()
     with dbuser('bugsummaryrebuild'):
         rebuild_bugsummary_for_target(product, log)
     self.assertEqual(1, get_bugsummary_rows(product).count())
     self.assertEqual(0, get_bugsummaryjournal_rows(product).count())
     self.assertThat(
         log.getLogBufferAndClear(),
         MatchesRegex(
             'DEBUG Rebuilding %s\nDEBUG Added {.*: 1L}' % product.name))