Example #1
0
    def test_should_load_the_value_based_on_the_order_user_defined(self):
        file = TestUtils().write_to_temp('log20090909090.xml', PluginsTests.FAILED_LOG_AT_OCT_11)
        plugins = Plugins.INSTANCE(TestUtils().plugins())
        plugins.load_plugins()

        config = TestUtils().connectfour_config()
        config.plugins = self._file_is_missing
        result = plugins.handle(file, config)

        self.assertEquals(2, len(result))
        self.assertEquals('build.1', result[0])
        self.assertEquals('1 minute(s) 0 second(s)', result[1])
Example #2
0
 def setUp(self):
     self.testutils                = TestUtils()
     self.root                     = settings.PROJECT_DIR
     self.failed                   = Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', BuildsTest.FAILED_LOG))
     self.passed_at_oct_11         = Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', BuildsTest.PASSED_LOG_AT_OCT_11))
     self.another_passed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', BuildsTest.ANOTHER_PASSED_LOG_AT_OCT_11))
     self.failed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', BuildsTest.FAILED_LOG_AT_OCT_11))        
Example #3
0
 def setUp(self):
     self.testutils                = TestUtils()
     self.root                     = settings.PROJECT_DIR
     self.failed                   = Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', BuildBreakerTests.FAILED_LOG_AT_OCT_11))
     self.did_not_fix         = Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', BuildBreakerTests.DID_NOT_FIX_IT_LOG))
     self.fixed_it = Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', BuildBreakerTests.FIXED_IT_LOG))
     self.another_pass = Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', BuildBreakerTests.ANOTHER_PASS))        
Example #4
0
 def setUp(self):
     self.utils = TestUtils()
     self.configs = Groups().default()
     self.tar_file = os.path.join(self.configs.results_dir(), 'all.tar')
     if os.path.exists(self.tar_file):
         os.remove(self.tar_file)
     os.rmdir_p(self.configs.results_dir())
     os.rmdir_p(self.utils.temp_dir())
Example #5
0
class TarTests(TestCase):   
    def setUp(self):
        self.utils = TestUtils()
        self.configs = Groups().default()
        self.tar_file = os.path.join(self.configs.results_dir(), 'all.tar')
        if os.path.exists(self.tar_file):
            os.remove(self.tar_file)
        os.rmdir_p(self.configs.results_dir())
        os.rmdir_p(self.utils.temp_dir())

    def tearDown(self):
        if os.path.exists(self.tar_file):
            os.remove(self.tar_file)
        os.rmdir_p(self.configs.results_dir())
        os.rmdir_p(self.utils.temp_dir())
         
    def test_should_generate_tar_file_with_all_csvs(self):
        self.assertEquals(False, os.path.exists(self.tar_file))
        group = Groups().default()
        group.id = 'default'
        group.configs = self.configs
        pg = ProjectGroup.create(group)

        tar = Tar(self.configs)

        tar.create()
        self.assertEquals(True, os.path.exists(os.path.join(self.configs.results_dir(), 'all.tar')))
        self.utils.extract_tar(os.path.join(self.configs.results_dir(), 'all.tar'), self.utils.temp_dir())
        files = os.list_matched_files(self.utils.temp_dir(), ".*")
        self.assertEquals(4, len(files))
        
Example #6
0
class BuildsTest(TestCase):
    FAILED_LOG_AT_OCT_11 = '''<cruisecontrol>
      <modifications />
      <info>
        <property name="projectname" value="connectfour4" />
        <property name="lastbuild" value="20091011000000" />
        <property name="lastsuccessfulbuild" value="20091011000000" />
        <property name="builddate" value="2009-10-11T09:39:22" />
        <property name="cctimestamp" value="20091011173922" />
        <property name="label" value="build.1" />
        <property name="interval" value="300" />
        <property name="lastbuildsuccessful" value="true" />
        <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
        <property name="logfile" value="log20091011173922.xml" />
      </info>
      <build time="1 minute(s) 0 second(s)">
        <target name="exec">
          <task name="echo">
            <message priority="info"><![CDATA[haha]]></message>
          </task>
        </target>
      </build>
    </cruisecontrol>'''
    
    PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T09:39:22" />
    <property name="cctimestamp" value="20091011173922" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="1 minute(s) 0 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''
    ANOTHER_PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T10:39:22" />
    <property name="cctimestamp" value="20091011173900" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="0 minute(s) 2 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    FAILED_LOG = '''<?xml version="1.0" encoding="UTF-8"?>
<cruisecontrol>
  <modifications>
    <modification type="mercurial">
      <file action="added">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-13T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
    <modification type="mercurial">
      <file action="modified">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-17T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
  </modifications>
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011201149" />
    <property name="lastsuccessfulbuild" value="20091011201149" />
    <property name="builddate" value="2009-10-17T14:03:24" />
    <property name="cctimestamp" value="20091017220324" />
    <property name="label" value="build.18" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091017220324.xml" />
  </info>
  <build time="0 minute(s) 4 second(s)" error="exec error">
    <target name="exec">
      <task name="echa">
        <message priority="error"><![CDATA[Could not execute command: echa with arguments: haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    def setUp(self):
        self.testutils                = TestUtils()
        self.root                     = settings.PROJECT_DIR
        self.failed                   = Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', BuildsTest.FAILED_LOG))
        self.passed_at_oct_11         = Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', BuildsTest.PASSED_LOG_AT_OCT_11))
        self.another_passed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', BuildsTest.ANOTHER_PASSED_LOG_AT_OCT_11))
        self.failed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', BuildsTest.FAILED_LOG_AT_OCT_11))        
        

    def tearDown(self):
        self.testutils.cleantemp()
        
    def testShouldGroupTheBuilds(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]
        grouped_builds = builds.group_by_each_day()
        self.assertEquals(2, len(grouped_builds))

        atime = datetime.strptime("20091011000000", "%Y%m%d%H%M%S")
        btime = datetime.strptime("20091017000000", "%Y%m%d%H%M%S")

        self.assertEquals(2, len(grouped_builds[atime].builds))
        btime = datetime.strptime("20091017000000", "%Y%m%d%H%M%S")
        self.assertEquals(1, len(grouped_builds[btime].builds))

    def testShouldCalculateThePassCount(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]

        atime = datetime.strptime("20091011000000", "%Y%m%d%H%M%S")
        self.assertEquals(2, builds.group_by_each_day()[atime].pass_count())

    def testShouldCalculateTheFailCount(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]

        atime = datetime.strptime("20091017000000", "%Y%m%d%H%M%S")
        self.assertEquals(0, builds.group_by_each_day()[atime].pass_count())

    def testShouldCalculateThePassRate(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]

        atime = datetime.strptime("20091011000000", "%Y%m%d%H%M%S")
        self.assertEquals(1, builds.group_by_each_day()[atime].pass_rate())

    def testShouldTheBuildsTimes(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]

        atime = datetime.strptime("20091011000000", "%Y%m%d%H%M%S")
        values, min, max, max_time = builds.build_times()
        self.assertEquals(3, len(values))

        self.assertEquals (util.datetimeutils.cctimestamp_to_unix_timestamp("20091011173900"), min)
        self.assertEquals (util.datetimeutils.cctimestamp_to_unix_timestamp("20091017220324"), max)
        self.assertEquals (60, max_time)

    def testShouldCalculateTheBuildPerDay(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]

        values, labels, max_time = builds.per_build_time()
        
        self.assertEquals('#1C9E05', values[0]['colour']);
        self.assertEquals('#1C9E05', values[1]['colour']);
        self.assertEquals('#FF368D', values[2]['colour']);
        self.assertEquals(60, values[0]['top']);
        self.assertEquals(2,  values[1]['top']);
        self.assertEquals(4,  values[2]['top']);
        self.assertEquals('2009-10-11 17:39:22', labels[0])
        self.assertEquals('2009-10-11 17:39:00', labels[1])
        self.assertEquals('2009-10-17 22:03:24', labels[2])
        self.assertEquals(60, max_time);


    def test_should_calculate_pass_rate_by_day(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]

        n_days_summary = builds.get_n_days_summary()
        self.assertEquals('67.0', str(n_days_summary.pass_rate_values()[0]['y']))

    def test_should_calculate_total_count(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]

        self.assertEquals(3, builds.total_count())

    def test_should_calculate_pass_count(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]

        self.assertEquals(2, builds.pass_count())

    def test_should_calculate_avg_build_time(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]

        self.assertEquals('40.67', builds.avg_build_time())


    def test_should_return_zero_as_avg_build_time_if_no_builds(self):
        builds = Builds()

        self.assertEquals('0', builds.avg_build_time())

    def testShouldCalcateAvgRunsPerDay(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed]
        self.assertEquals('1.5', builds.avg_runs());

    def testShouldCalcateAvgRunsPerDay(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.passed_at_oct_11, self.passed_at_oct_11]
        self.assertEquals('3.00', builds.avg_runs());
        
    def testShouldOnlyKeep2digitAfterPoint(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.failed]
        self.assertEquals('0.33', str(builds.avg_runs()));
Example #7
0
 def setUp(self):
     self.test_utils = TestUtils()
     self.test_utils.cleanup_results()
Example #8
0
class FunctionalTests(TestCase):

    def setUp(self):
        self.test_utils = TestUtils()
        self.test_utils.cleanup_results()

    def tearDown(self):
        self.test_utils.cleanup_results()
        self.test_utils.rename_bak_to_conf()

    def test_user_should_be_able_to_setup_the_application(self):
        user = User()
        user.open_home_page()
        self.assertContains(user.response, 'Missing Data')
        user.open_show_page('connectfour4')
        self.assertContains(user.response, 'MISSING REPORT')
        self.assertContains(user.response, user.found_config_file_location())
        user.generates_reports_for('connectfour4')

        user.open_setup_page('connectfour4')
        self.assertContains(user.response, 'OK')

        user.downloads_build_times_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_csv()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_pass_rate_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_per_build_time_data()
        self.assertEquals(True, user.can_visit_resource())
    
    def test_user_should_be_able_to_request_with_project_id(self):
        user = User()
        user.open_home_page()
        self.assertContains(user.response, 'Missing Data')
        user.open_show_page('cclive')       
        self.assertContains(user.response, 'MISSING REPORT')
        self.assertContains(user.response, user.found_config_file_location())
        user.generates_reports_for('cclive')

        user.open_setup_page('cclive')
        self.assertContains(user.response, 'OK')
        
        user.open_show_page('cclive')

        self.assertContains(user.response, '4 runs')
        user.downloads_build_times_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_csv()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_pass_rate_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_per_build_time_data()
        self.assertEquals(True, user.can_visit_resource())
        

    
    def test_user_should_not_wait_for_re_generating_the_data_when_referesh_the_page(self):
       user = User()
       self.test_utils.rename_conf_to_bak()
       user.open_home_page()
       self.assertContains(user.response, 'Opps! seems you did not create any config file')

       self.test_utils.rename_bak_to_conf()
       user.open_home_page()
       self.assertContains(user.response, 'cclive')
       self.assertContains(user.response, 'connectfour4')
       
    def test_should_print_hint_on_the_screen_when_user_first_time_uses_software(self):
       user = User()
       user.open_home_page()
       self.assertContains(user.response, 'Missing Data')
Example #9
0
class BuildsByDayTests(TestCase):
    FAILED_LOG_AT_OCT_11 = '''<cruisecontrol>
      <modifications />
      <info>
        <property name="projectname" value="connectfour4" />
        <property name="lastbuild" value="20091011000000" />
        <property name="lastsuccessfulbuild" value="20091011000000" />
        <property name="builddate" value="2009-10-11T09:39:22" />
        <property name="cctimestamp" value="20091011173922" />
        <property name="label" value="build.1" />
        <property name="interval" value="300" />
        <property name="lastbuildsuccessful" value="true" />
        <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
        <property name="logfile" value="log20091011173922.xml" />
      </info>
      <build time="1 minute(s) 0 second(s)">
        <target name="exec">
          <task name="echo">
            <message priority="info"><![CDATA[haha]]></message>
          </task>
        </target>
      </build>
    </cruisecontrol>'''
    
    PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T09:39:22" />
    <property name="cctimestamp" value="20091011173922" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="1 minute(s) 0 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''
    ANOTHER_PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T10:39:22" />
    <property name="cctimestamp" value="20091011173900" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="0 minute(s) 2 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    FAILED_LOG = '''<?xml version="1.0" encoding="UTF-8"?>
<cruisecontrol>
  <modifications>
    <modification type="mercurial">
      <file action="added">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-13T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
    <modification type="mercurial">
      <file action="modified">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-17T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
  </modifications>
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011201149" />
    <property name="lastsuccessfulbuild" value="20091011201149" />
    <property name="builddate" value="2009-10-17T14:03:24" />
    <property name="cctimestamp" value="20091017220324" />
    <property name="label" value="build.18" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091017220324.xml" />
  </info>
  <build time="0 minute(s) 4 second(s)" error="exec error">
    <target name="exec">
      <task name="echa">
        <message priority="error"><![CDATA[Could not execute command: echa with arguments: haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    def setUp(self):
        self.testutils                = TestUtils()
        self.root                     = settings.PROJECT_DIR
        self.failed                   = Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', BuildsByDayTests.FAILED_LOG))
        self.passed_at_oct_11         = Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', BuildsByDayTests.PASSED_LOG_AT_OCT_11))
        self.another_passed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', BuildsByDayTests.ANOTHER_PASSED_LOG_AT_OCT_11))
        self.failed_at_oct_11 = Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', BuildsByDayTests.FAILED_LOG_AT_OCT_11))        
        

    def tearDown(self):
        self.testutils.cleantemp()

    def test_should_total_runs_by_day(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]
        n_days_summary = builds.get_n_days_summary();
        
        self.assertEquals(3, n_days_summary.total_runs_values()[0].get('y'))
    
    def test_should_return_zero_total_runs_if_no_builds(self):
        builds = Builds()
        n_days_summary = builds.get_n_days_summary();
        
        self.assertEquals(0, len(n_days_summary.total_runs_values()))

    
    def test_should_passed_runs_by_day(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]
        n_days_summary = builds.get_n_days_summary();

        self.assertEquals(2, n_days_summary.passed_runs_values()[0].get('y'))
    
    def test_should_return_zero_if_no_passed_build(self):
        builds = Builds()
        builds.builds = [self.failed_at_oct_11]

        n_days_summary = builds.get_n_days_summary();
        self.assertEquals(0, n_days_summary.passed_runs_values()[0].get('y'))

    def test_should_return_zero_passed_build_if_no_builds(self):
        builds = Builds()
        n_days_summary = builds.get_n_days_summary();
        self.assertEquals(0, len(n_days_summary.passed_runs_values()))

    
    def test_should_passed_runs_by_day(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11, self.failed_at_oct_11]
        n_days_summary = builds.get_n_days_summary();

        self.assertEquals(1, n_days_summary.failed_runs_values()[0].get('y'))

    def test_should_return_zero_if_no_passed_build(self):
        builds = Builds()
        builds.builds = [self.passed_at_oct_11,  self.another_passed_at_oct_11]

        n_days_summary = builds.get_n_days_summary();
        self.assertEquals(0, n_days_summary.failed_runs_values()[0].get('y'))

    def test_should_return_zero_passed_build_if_no_builds(self):
        builds = Builds()
        n_days_summary = builds.get_n_days_summary();
        self.assertEquals(0, len(n_days_summary.failed_runs_values()))
Example #10
0
class BuildBreakerTests(TestCase):
    FAILED_LOG_AT_OCT_11 = '''<cruisecontrol>
    <modifications>
      <modification type="mercurial">
        <file action="added">
          <revision>12</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-13T09:48:27</date>
        <user>khu</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>12</revision>
      </modification>
      <modification type="mercurial">
        <file action="modified">
          <revision>12</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-17T09:48:27</date>
        <user>khu</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>12</revision>
      </modification>
    </modifications>
      <info>
        <property name="projectname" value="connectfour4" />
        <property name="lastbuild" value="20091011000000" />
        <property name="lastsuccessfulbuild" value="20091011000000" />
        <property name="builddate" value="2009-10-11T09:39:22" />
        <property name="cctimestamp" value="20091011173922" />
        <property name="label" value="build.1" />
        <property name="interval" value="300" />
        <property name="lastbuildsuccessful" value="true" />
        <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
        <property name="logfile" value="log20091011173922.xml" />
      </info>
      <build time="1 minute(s) 0 second(s)">
        <target name="exec">
          <task name="echo">
            <message priority="info"><![CDATA[haha]]></message>
          </task>
        </target>
      </build>
    </cruisecontrol>'''
        
    DID_NOT_FIX_IT_LOG = '''<?xml version="1.0" encoding="UTF-8"?>
    <cruisecontrol>
      <modifications>
        <modification type="mercurial">
          <file action="added">
            <revision>12</revision>
            <filename>b</filename>
          </file>
          <date>2009-10-13T09:48:27</date>
          <user>khu</user>
          <comment><![CDATA[f****d]]></comment>
          <revision>12</revision>
        </modification>
        <modification type="mercurial">
          <file action="modified">
            <revision>12</revision>
            <filename>b</filename>
          </file>
          <date>2009-10-17T09:48:27</date>
          <user>khu</user>
          <comment><![CDATA[f****d]]></comment>
          <revision>12</revision>
        </modification>
        <modification type="mercurial">
          <file action="modified">
            <revision>13</revision>
            <filename>b</filename>
          </file>
          <date>2009-10-17T09:48:27</date>
          <user>xkf</user>
          <comment><![CDATA[f****d]]></comment>
          <revision>13</revision>
        </modification>
      </modifications>
      <info>
        <property name="projectname" value="connectfour4" />
        <property name="lastbuild" value="20091011201149" />
        <property name="lastsuccessfulbuild" value="20091011201149" />
        <property name="builddate" value="2009-10-17T14:03:24" />
        <property name="cctimestamp" value="20091017220324" />
        <property name="label" value="build.18" />
        <property name="interval" value="300" />
        <property name="lastbuildsuccessful" value="true" />
        <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
        <property name="logfile" value="log20091017220324.xml" />
      </info>
      <build time="0 minute(s) 4 second(s)" error="exec error">
        <target name="exec">
          <task name="echa">
            <message priority="error"><![CDATA[Could not execute command: echa with arguments: haha]]></message>
          </task>
        </target>
      </build>
    </cruisecontrol>'''
        
    FIXED_IT_LOG = '''<cruisecontrol>
    <modifications>
      <modification type="mercurial">
        <file action="added">
          <revision>12</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-13T09:48:27</date>
        <user>khu</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>12</revision>
      </modification>
      <modification type="mercurial">
        <file action="modified">
          <revision>12</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-17T09:48:27</date>
        <user>khu</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>12</revision>
      </modification>
      <modification type="mercurial">
        <file action="modified">
          <revision>13</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-17T09:48:27</date>
        <user>xkf</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>13</revision>
      </modification>
      <modification type="mercurial">
        <file action="modified">
          <revision>14</revision>
          <filename>b</filename>
        </file>
        <date>2009-10-17T09:48:27</date>
        <user>xkf</user>
        <comment><![CDATA[f****d]]></comment>
        <revision>14</revision>
      </modification>
    </modifications>
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T09:39:22" />
    <property name="cctimestamp" value="20091011173922" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="1 minute(s) 0 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    ANOTHER_PASS = '''<cruisecontrol>
    <modifications>
        <modification type="mercurial">
          <file action="added">
            <revision>15</revision>
            <filename>b</filename>
          </file>
          <date>2009-10-13T09:48:27</date>
          <user>xkf</user>
          <comment><![CDATA[f****d]]></comment>
          <revision>15</revision>
        </modification>
      </modifications>
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T10:39:22" />
    <property name="cctimestamp" value="20091011173900" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="0 minute(s) 2 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''



    def setUp(self):
        self.testutils                = TestUtils()
        self.root                     = settings.PROJECT_DIR
        self.failed                   = Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', BuildBreakerTests.FAILED_LOG_AT_OCT_11))
        self.did_not_fix         = Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', BuildBreakerTests.DID_NOT_FIX_IT_LOG))
        self.fixed_it = Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', BuildBreakerTests.FIXED_IT_LOG))
        self.another_pass = Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', BuildBreakerTests.ANOTHER_PASS))        
        

    def tearDown(self):
        self.testutils.cleantemp()
        
    def test_should_group_the_commitors_based_on_(self):
        builds = Builds()
        builds.builds = [self.failed,  self.did_not_fix, self.fixed_it, self.another_pass]
        grouped_commitors = builds.build_breakers()
        commitor = grouped_commitors.find('xkf')
        self.assertEquals(2, commitor.passed_count())
        self.assertEquals(1, commitor.failed_count())

        commitor = grouped_commitors.find('khu')
        self.assertEquals(0, commitor.passed_count())
        self.assertEquals(1, commitor.failed_count())
Example #11
0
 def setUp(self):
     self.testutils                = TestUtils()
     self.root                     = settings.PROJECT_DIR
Example #12
0
class ProjectGroupTests(TestCase):
    FAILED_LOG_AT_OCT_11 = '''<cruisecontrol>
      <modifications />
      <info>
        <property name="projectname" value="connectfour4" />
        <property name="lastbuild" value="20091011000000" />
        <property name="lastsuccessfulbuild" value="20091011000000" />
        <property name="builddate" value="2009-10-11T09:39:22" />
        <property name="cctimestamp" value="20091011173922" />
        <property name="label" value="build.1" />
        <property name="interval" value="300" />
        <property name="lastbuildsuccessful" value="true" />
        <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
        <property name="logfile" value="log20091011173922.xml" />
      </info>
      <build time="1 minute(s) 0 second(s)">
        <target name="exec">
          <task name="echo">
            <message priority="info"><![CDATA[haha]]></message>
          </task>
        </target>
      </build>
    </cruisecontrol>'''
    
    PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T09:39:22" />
    <property name="cctimestamp" value="20091011173922" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="1 minute(s) 0 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''
    ANOTHER_PASSED_LOG_AT_OCT_11 = '''<cruisecontrol>
  <modifications />
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011000000" />
    <property name="lastsuccessfulbuild" value="20091011000000" />
    <property name="builddate" value="2009-10-11T10:39:22" />
    <property name="cctimestamp" value="20091011173900" />
    <property name="label" value="build.1" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091011173922Lbuild.1.xml" />
  </info>
  <build time="0 minute(s) 2 second(s)">
    <target name="exec">
      <task name="echo">
        <message priority="info"><![CDATA[haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    FAILED_LOG = '''<?xml version="1.0" encoding="UTF-8"?>
<cruisecontrol>
  <modifications>
    <modification type="mercurial">
      <file action="added">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-13T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
    <modification type="mercurial">
      <file action="modified">
        <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
        <filename>b</filename>
      </file>
      <date>2009-10-17T09:48:27</date>
      <user>twer@localhost</user>
      <comment><![CDATA[f****d]]></comment>
      <revision>1:96ad1ef37c2ae7828a66e16d8eb508b7b69465a4</revision>
    </modification>
  </modifications>
  <info>
    <property name="projectname" value="connectfour4" />
    <property name="lastbuild" value="20091011201149" />
    <property name="lastsuccessfulbuild" value="20091011201149" />
    <property name="builddate" value="2009-10-17T14:03:24" />
    <property name="cctimestamp" value="20091017220324" />
    <property name="label" value="build.18" />
    <property name="interval" value="300" />
    <property name="lastbuildsuccessful" value="true" />
    <property name="logdir" value="/Users/twer/Desktop/cruisecontrol-bin-2.8.2/logs/connectfour4" />
    <property name="logfile" value="log20091017220324.xml" />
  </info>
  <build time="0 minute(s) 4 second(s)" error="exec error">
    <target name="exec">
      <task name="echa">
        <message priority="error"><![CDATA[Could not execute command: echa with arguments: haha]]></message>
      </task>
    </target>
  </build>
</cruisecontrol>'''

    def setUp(self):
        self.testutils                = TestUtils()
        self.root                     = settings.PROJECT_DIR
        

    def tearDown(self):
        self.testutils.cleantemp()
        
    def testShouldGroupTheBuilds(self):
        acc_builds = self._builds_obj('acc', [self.failed(),  self.another_passed_at_oct_11(), self.passed_at_oct_11()])
        safe_builds = self._builds_obj('safe', [self.failed(),  self.another_passed_at_oct_11()])
        pg = ProjectGroup()
        pg.append('acc', acc_builds)
        pg.append('safe', safe_builds)
        
        values, names, max = pg.projects_comparation()
        self.assertEquals(2, values[0][0])
        self.assertEquals(1, values[0][1])
        self.assertEquals(1, values[1][0])
        self.assertEquals(1, values[1][1])
        self.assertEquals('acc', names[0])
        self.assertEquals('safe', names[1])
        self.assertEquals(3, max)
        

    def _builds_obj(self, project_id, builds):
        all_builds = []
        builds_obj = Builds()
        for build in builds:
            build.project_id = project_id
        
        builds_obj.builds = builds
        return builds_obj
 
    def failed(self):
        return Build.from_file(self.testutils.write_to_temp('FAILED_LOG.xml', ProjectGroupTests.FAILED_LOG))

    def passed_at_oct_11(self):
        return Build.from_file(self.testutils.write_to_temp('PASSED_LOG_AT_OCT_11.xml', ProjectGroupTests.PASSED_LOG_AT_OCT_11))

    def another_passed_at_oct_11(self):
        return Build.from_file(self.testutils.write_to_temp('ANOTHER_PASSED_LOG_AT_OCT_11.xml', ProjectGroupTests.ANOTHER_PASSED_LOG_AT_OCT_11))

    def failed_at_oct_11(self):
        return Build.from_file(self.testutils.write_to_temp('FAILED_LOG_AT_OCT_11.xml', ProjectGroupTests.FAILED_LOG_AT_OCT_11))
        
        
# def test_should_not_remove_records_of_other_project(self):
#     self.assertEqual(0, len(Build.objects.all()))
#     builds = Builds.create_builds(TestUtils().connectfour_config(), BuildFactoryTest.PATTERN);
#     self.assertEqual(2, len(Build.objects.all()))
#     builds = Builds.create_builds(TestUtils().cclive_config(), None);        
#     self.assertEqual(7, len(Build.objects.all()))
#
Example #13
0
 def setUp(self):
     self.l3_support = None
     self.test_utils = TestUtils()
     self.test_utils.cleanup_results()
Example #14
0
class FunctionalTests(TestCase):

    def setUp(self):
        self.l3_support = None
        self.test_utils = TestUtils()
        self.test_utils.cleanup_results()

    def tearDown(self):
       self.test_utils.cleanup_results()
       self.test_utils.rename_bak_to_conf()
       if self.l3_support != None:
           os.remove(self.l3_support)
            
            
    def test_user_should_be_able_to_setup_the_application(self):
        user = User()
        user.open_home_page()
        self.assertContains(user.response, 'Missing Data')
        user.open_show_page('connectfour4')
        self.assertContains(user.response, 'MISSING REPORT')
        self.assertContains(user.response, user.found_config_file_location())
        user.generates_reports_for('connectfour4')

        user.open_setup_page('connectfour4')
        self.assertContains(user.response, 'OK')

        user.downloads_build_times_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_csv()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_pass_rate_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_per_build_time_data()
        self.assertEquals(True, user.can_visit_resource())
      
    def test_user_should_be_able_to_request_with_project_id(self):
        user = User()
        user.open_home_page()
        self.assertContains(user.response, 'Missing Data')
        user.open_show_page('cclive')       
        self.assertContains(user.response, 'MISSING REPORT')
        self.assertContains(user.response, user.found_config_file_location())
        user.generates_reports_for('cclive')

        user.open_setup_page('cclive')
        self.assertContains(user.response, 'OK')

        user.open_show_page('cclive')

        self.assertContains(user.response, '6 runs')
        self.assertContains(user.response, '0.00%')
        self.assertContains(user.response, '251.33(s)')
        user.downloads_build_times_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_csv()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_pass_rate_data()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_per_build_time_data()
        self.assertEquals(True, user.can_visit_resource())

    def test_user_should_not_wait_for_re_generating_the_data_when_referesh_the_page(self):
         user = User()
         self.test_utils.rename_conf_to_bak()
         user.open_home_page()
         self.assertContains(user.response, 'Opps! seems you did not create any config file')

         self.test_utils.rename_bak_to_conf()
         user.open_home_page()
         self.assertContains(user.response, 'cclive')
         self.assertContains(user.response, 'connectfour4')
 
    def test_user_can_find_which_project_might_go_wrong(self):
        user = User()
        user.generates_reports_for('connectfour4')
        user.open_home_page()
        self.assertEquals(True, user.noticed_warning_icon('connectfour4'))

        user.open_show_page('connectfour4')
        self.assertEquals('More than 1 month', user.found_last_build_happened_at())
        self.assertEquals('More than 1 month', user.found_last_pass_happened_at())

    def test_user_can_find_latest_status_for_each_project(self):
        user = User()
        user.generates_reports_for('connectfour4')
        user.open_home_page()
        self.assertEquals('failed', user.found_status_for('connectfour4'))
        self.assertEquals('failed', user.found_status_for('cclive'))
        self.assertEquals('passed', user.found_status_for('acc-srv'))
      
    def test_user_can_generate_all_logs(self):
        user = User()
        self.l3_support = self.test_utils.create_l3_support_config()
        user.open_home_page()
        self.assertContains(user.response, 'l3_support')

        user.open_show_page('l3_support')       
        self.assertContains(user.response, 'MISSING REPORT')

        user.generates_all_reports()
        
        user.downloads_groups_acc_projects_comparation()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_groups_others_projects_comparation()
        self.assertEquals(True, user.can_visit_resource())
        user.downloads_groups_defaults_projects_comparation()
        self.assertEquals(True, user.can_visit_resource())
        
        user.open_show_page('l3_support')

        self.assertContains(user.response, '2 runs')
        self.assertContains(user.response, '100.00%')
        self.assertContains(user.response, '1200.00(s)')

    def test_user_can_visit_different_group_using_unique_url(self):
        user = User()
        user.open_home_page('others')
        self.assertContains(user.response, 'safe')
        self.assertNotContains(user.response, 'cclive')
        self.assertNotContains(user.response, 'connectfour4')
        self.assertNotContains(user.response, 'missing-logs')
        self.assertNotContains(user.response, 'acc-srv')
        user.open_home_page('acc')        
        self.assertNotContains(user.response, 'safe')
        self.assertContains(user.response, 'cclive')
        self.assertContains(user.response, 'connectfour4')
        self.assertContains(user.response, 'acc-srv')
        user.open_home_page()        
        self.assertContains(user.response, 'safe')
        self.assertContains(user.response, 'cclive')
        self.assertContains(user.response, 'connectfour4')
        self.assertContains(user.response, 'missing-logs')
        self.assertContains(user.response, 'acc-srv')  

    def test_user_should_be_redirected_to_default_group_when_group_does_not_exists(self):
        user = User()
        user.open_home_page('some-thing-missing')
        self.assertContains(user.response, 'safe')
        self.assertContains(user.response, 'cclive')
        self.assertContains(user.response, 'connectfour4')
        self.assertContains(user.response, 'missing-logs')
        self.assertContains(user.response, 'acc-srv')  
        

    def test_user_should_be_redirected_to_default_group_when_no_group_was_provided(self):
        user = User()
        user.open_home_page(None)
        self.assertContains(user.response, 'safe')
        self.assertContains(user.response, 'cclive')
        self.assertContains(user.response, 'connectfour4')
        self.assertContains(user.response, 'missing-logs')
        self.assertContains(user.response, 'acc-srv')  

    def test_user_can_download_all_the_csv_files_as_a_single_tar(self):
        user = User()
        user.open_home_page()
        user.generates_all_reports()
        user.downloads_all_csv_as_single_tar()
        self.assertEquals(True, user.can_visit_resource())
        
    def test_user_can_be_noticed_if_the_logs_dir_is_incorrectly_defined(self):
        user = User()
        user.open_home_page()
        self.assertEquals('unknown', user.found_status_for('missing-logs'))