Exemple #1
0
    def test_init_raise(self):
        '''Test instance creation that raises an error - invalid parameters'''
        with pytest.raises(exc.CheckbValueError):
            check.CheckDetail(None, outcome='INVALID TYPE')

        with pytest.raises(exc.CheckbValueError):
            check.CheckDetail(None, output='foobar')

        with pytest.raises(exc.CheckbValueError):
            check.CheckDetail(None, keyvals='foobar')
    def setup(self, tmpdir):
        self.artifactsdir = tmpdir.mkdir('artifacts')
        self.report_filename = 'report.html'

        self.cd = check.CheckDetail(
            item='foo_bar',
            report_type=check.ReportType.KOJI_BUILD,
            outcome='NEEDS_INSPECTION',
            note='foo_bar note',
            output=["foo\nbar"],
            keyvals={
                "foo": "moo1",
                "bar": "moo2"
            },
            artifact='artifact.log',
        )

        self.yaml = check.export_YAML(self.cd)

        self.ref_params = {
            'results': self.yaml,
            'artifactsdir': self.artifactsdir.strpath,
        }
        self.ref_arg_data = {
            'resultsdb_job_id': 1,
            'checkname': 'test_resultsdb_report',
            'jobid': 'all/123',
            'uuid': 'c25237a4-b6b3-11e4-b98a-3c970e018701',
        }

        self.rd = create_report_directive.CreateReportDirective()
Exemple #3
0
    def test_multi(self):
        '''Test export with multiple item sections'''
        cd2 = check.CheckDetail(item='foobar-1.2-3.fc20',
                                outcome='FAILED',
                                note='dependency error',
                                report_type=check.ReportType.BODHI_UPDATE)
        cd3 = check.CheckDetail(item='f20-updates',
                                outcome='INFO',
                                note='2 stale updates',
                                report_type=check.ReportType.KOJI_TAG)
        yaml_output = check.export_YAML([self.cd, cd2, cd3])
        yaml_obj = yaml.safe_load(yaml_output)

        assert len(yaml_obj['results']) == 3
        assert yaml_obj['results'][0]['item'] == self.cd.item
        assert yaml_obj['results'][1]['item'] == cd2.item
        assert yaml_obj['results'][2]['item'] == cd3.item
Exemple #4
0
 def setup_method(self, method):
     self.cd = check.CheckDetail(item=self.item,
                                 outcome=self.outcome,
                                 note=self.note,
                                 report_type=self.report_type,
                                 keyvals=self.keyvals,
                                 checkname=self.checkname,
                                 artifact=self.artifact)
     self.cd._internal = self._internal
Exemple #5
0
    def setup(self, monkeypatch):
        '''Run this before every test invocation'''

        self.cd = check.CheckDetail(
            item='foo_bar',
            report_type=check.ReportType.KOJI_BUILD,
            outcome='NEEDS_INSPECTION',
            note='foo_bar note',
            output=["foo\nbar"],
            keyvals={"foo": "moo1", "bar": "moo2"},
            checkname='qa.test_resultsdb_report',
            )

        self.yaml = check.export_YAML(self.cd)

        self.ref_input = {'results': self.yaml}
        self.ref_arg_data = {
            'resultsdb_job_id': 1,
            'jobid': 'all/123',
            'uuid': 'c25237a4-b6b3-11e4-b98a-3c970e018701',
            'artifactsdir': '/some/directory/',
            'task': '/taskdir',
            'item': 'firefox-45.0.2-1.fc23'
            }

        self.ref_resultdata = {u'id': 1234}

        self.ref_jobid = 1234
        self.ref_uuid = 'c25237a4-b6b3-11e4-b98a-3c970e018701'
        self.ref_refurl = u'http://example.com/%s' % self.cd.checkname
        self.ref_jobdata = {u'end_time': None,
                            u'href': u'http://127.0.0.1/api/v2.0/jobs/%d' % self.ref_jobid,
                            u'id': self.ref_jobid,
                            u'name': self.cd.checkname,
                            u'ref_url': self.ref_refurl,
                            u'results': [],
                            u'results_count': 0,
                            u'start_time': None,
                            u'status': u'SCHEDULED'}

        self.stub_rdb = mock.Mock(**{
            'get_testcase.return_value': {},
            'create_job.return_value': self.ref_jobdata,
            'create_result.return_value': self.ref_resultdata,
            })
        self.test_rdb = resultsdb_directive.ResultsdbDirective(self.stub_rdb)

        # while it appears useless, this actually sets config in several tests
        monkeypatch.setattr(config, '_config', None)
        self.conf = config.get_config()
        self.conf.report_to_resultsdb = True

        monkeypatch.setattr(configparser, 'ConfigParser', StubConfigParser)
Exemple #6
0
 def test_init_params(self):
     '''Test instance creation with non-empty parameters'''
     cd = check.CheckDetail(item='foo-1.2-3.fc20',
                            outcome='FAILED',
                            note='untested',
                            output=['line1', 'line2'],
                            checkname='testcheck',
                            artifact='logfile.log')
     assert cd.item == 'foo-1.2-3.fc20'
     assert cd.outcome == 'FAILED'
     assert cd.note == 'untested'
     assert cd.checkname == 'testcheck'
     assert cd.artifact == 'logfile.log'
Exemple #7
0
    def test_create_multi_item_summary(self):
        '''Test create_multi_item_summary method'''
        # a basic use case with a list of strings
        summary = check.CheckDetail.create_multi_item_summary(
            ['PASSED', 'PASSED', 'FAILED', 'ABORTED', 'INFO', 'INFO'])
        assert summary == '2 PASSED, 2 INFO, 1 FAILED, 1 ABORTED'

        # an empty list should return an empty string
        summary = check.CheckDetail.create_multi_item_summary([])
        assert summary == ''

        # a use case with one CheckDetail instance input
        summary = check.CheckDetail.create_multi_item_summary(self.cd)
        assert summary == '1 NEEDS_INSPECTION'

        # a use case with multiple CheckDetail instances input
        cd1 = check.CheckDetail(None, outcome='PASSED')
        cd2 = check.CheckDetail(None, outcome='PASSED')
        cd3 = check.CheckDetail(None, outcome='INFO')
        summary = check.CheckDetail.create_multi_item_summary(
            [self.cd, cd1, cd2, cd3])
        assert summary == '2 PASSED, 1 INFO, 1 NEEDS_INSPECTION'
    def test_report_artifact_in_log_url(self, monkeypatch):
        """Checks whether artifact is correctly mapped to log_url"""
        cd = check.CheckDetail(item='foo_bar',
                               report_type=check.ReportType.KOJI_BUILD,
                               outcome='NEEDS_INSPECTION',
                               note='foo_bar note',
                               output=["foo\nbar"],
                               keyvals={
                                   "foo": "moo1",
                                   "bar": "moo2"
                               },
                               checkname='qa.test_resultsdb_report',
                               artifact='digest/logs/logfile.log')
        monkeypatch.setattr(self.test_rdb, 'get_artifact_path',
                            lambda *x: 'digest/logs/logfile.log')

        yaml = check.export_YAML(cd)
        ref_input = {'results': yaml}

        self.test_rdb.process(ref_input, self.ref_arg_data)

        # Given the input data, the resultsdb should be called once, and only
        #   once, calling "create_result".
        # This assert failing either means that more calls were added in the
        #   source code, or that a bug is present, and "create_result" is
        #   called multiple times.
        # we expect rdb to be called 4 times: create job, update to RUNNING,
        # check for testcase, report result and complete job

        assert len(self.stub_rdb.mock_calls) == 2

        # Select the first call of "create_result" method.
        # This could be written as self.stub_rdb.calls()[0] at the moment, but
        #   this is more future-proof, and accidental addition of resultsdb
        #   calls is handled by the previous assert.
        call = [
            call for call in self.stub_rdb.mock_calls
            if call[0] == 'create_result'
        ][0]
        # Select the keyword arguments of that call
        call_data = call[2]

        # the log url depends on the arg_data, so construct it here
        ref_log_url = '%s/%s/%s' %\
                      (self.conf.artifacts_baseurl, self.ref_arg_data['uuid'], cd.artifact)

        assert call_data['ref_url'] == ref_log_url
Exemple #9
0
    def test_minimal(self):
        '''Test that empty CheckDetail values don't produce empty YAML lines,
        for example 'note:' should not be present if there's no
        CheckDetail.note'''
        cd = check.CheckDetail('foo')
        yaml_output = check.export_YAML(cd)
        yaml_obj = yaml.safe_load(yaml_output)['results'][0]

        # the output should look like this:
        #
        # results:
        #   - item: XXX
        #     outcome: XXX
        #
        # ('outcome:' is technically not a mandatory line, but with CheckDetail
        # export we produce it every time)
        assert len(yaml_obj) == 2
Exemple #10
0
 def setup_method(self, method):
     '''Run this before every test invocation'''
     # for most methods, we want a default empty CheckDetail instance
     self.cd = check.CheckDetail(None)