def test_update_annotations(self):

        HASH_0 = 'xxx'
        HASH_1 = 'yyy'

        RESULTS = deepcopy(amo.VALIDATOR_SKELETON_RESULTS)
        RESULTS['messages'] = [
            {'id': ['foo'],
             'context': ['foo'],
             'file': 'foo'},

            {'id': ['baz'],
             'context': ['baz'],
             'file': 'baz'},
        ]

        self.file.update(original_hash=HASH_0)
        self.file_1_1.update(original_hash=HASH_1)

        # Attach the validation results to our previous version's file,
        # and update the object's cached foreign key value.
        self.file.validation = FileValidation.objects.create(
            file=self.file_1_1, validation=json.dumps(RESULTS))

        def annotation(hash_, key, **kw):
            return ValidationAnnotation(file_hash=hash_, message_key=key, **kw)

        def key(metasyntatic_variable):
            """Return an arbitrary, but valid, message key for the given
            arbitrary string."""
            return '[["{0}"], ["{0}"], "{0}", null, false]'.format(
                metasyntatic_variable)

        # Create two annotations which match the above messages, and
        # one which does not.
        ValidationAnnotation.objects.bulk_create((
            annotation(HASH_0, key('foo'), ignore_duplicates=True),
            annotation(HASH_0, key('bar'), ignore_duplicates=True),
            annotation(HASH_0, key('baz'), ignore_duplicates=False),
        ))

        # Create the annotator and make sure it links our target
        # file to the previous version.
        annotator = utils.ValidationAnnotator(self.file_1_1)
        assert annotator.prev_file == self.file

        annotator.update_annotations()

        # The two annotations which match messages in the above
        # validation results should be duplicated for this version.
        # The third annotation should not.
        assert (set(ValidationAnnotation.objects.filter(file_hash=HASH_1)
                    .values_list('message_key', 'ignore_duplicates')) ==
                set(((key('foo'), True), (key('baz'), False))))
Test that annotations are correctly copied from an old file to a new
dataset/ETHPy150Open mozilla/addons-server/src/olympia/devhub/tests/test_utils.py/TestValidationAnnotatorUnlisted.test_update_annotations