Exemple #1
0
    def test_annotate_results(self):
        """Test that results are annotated as expected."""

        RESULTS = deepcopy(amo.VALIDATOR_SKELETON_RESULTS)
        RESULTS['messages'] = [
            {
                'id': ['foo', 'bar'],
                'context': ['foo', 'bar', 'baz'],
                'file': 'foo',
                'signing_severity': 'low'
            },
            {
                'id': ['a', 'b'],
                'context': ['c', 'd', 'e'],
                'file': 'f',
                'ignore_duplicates': False,
                'signing_severity': 'high'
            },
            {
                'id': ['z', 'y'],
                'context': ['x', 'w', 'v'],
                'file': 'u',
                'signing_severity': 'high'
            },
        ]

        HASH = 'xxx'

        def annotation(hash_, message, **kw):
            """Create a ValidationAnnotation object for the given file hash,
            and the key of the given message, with the given keywords."""

            key = utils.ValidationComparator.message_key(message)
            return ValidationAnnotation(file_hash=hash_,
                                        message_key=json.dumps(key),
                                        **kw)

        # Create two annotations for this file, and one for a message in this
        # file, but with the wrong hash.
        ValidationAnnotation.objects.bulk_create((
            annotation(HASH, RESULTS['messages'][0], ignore_duplicates=False),
            annotation(HASH, RESULTS['messages'][1], ignore_duplicates=True),
            annotation('zzz', RESULTS['messages'][2], ignore_duplicates=True),
        ))

        # Annote a copy of the results.
        annotated = deepcopy(RESULTS)
        utils.ValidationComparator(annotated).annotate_results(HASH)

        # The two annotations for this file should be applied.
        assert annotated['messages'][0]['ignore_duplicates'] is False
        assert annotated['messages'][1]['ignore_duplicates'] is True
        # The annotation for the wrong file should not be applied, and
        # `ignore_duplicates` should be set to the default for the messge
        # severity (false).
        assert annotated['messages'][2]['ignore_duplicates'] is False
 def run_comparator(self, old, new):
     return (utils.ValidationComparator({'messages': [old]})
             .compare_results({'messages': [new]}))