コード例 #1
0
ファイル: test_forms.py プロジェクト: st333v/addons-server
    def test_v2_blocks_cant_be_edited(self):
        data = {
            'guids': 'any@thing\nsecond@thing',
        }
        anyblock = Block.objects.create(guid='any@thing',
                                        updated_by=user_factory())
        Block.objects.create(guid='second@thing', updated_by=user_factory())

        form = MultiDeleteForm(data=data)
        form.is_valid()
        form.clean()  # would raise

        # Give any@thing a .legacy_id so its sync'd with legacy blocklist
        anyblock.update(legacy_id='123456')
        form.is_valid()
        with self.assertRaises(ValidationError):
            form.clean()

        # except if the legacy submit waffle is enabled
        with override_switch('blocklist_legacy_submit', active=True):
            form.clean  # would raise
コード例 #2
0
    def test_guids_must_exist_for_block_deletion(self):
        data = {
            'guids': 'any@thing\nsecond@thing',
        }
        Block.objects.create(guid='any@thing', updated_by=user_factory())

        form = MultiDeleteForm(data=data)
        form.is_valid()
        with self.assertRaises(ValidationError):
            # second@thing doesn't exist as a block
            form.clean()

        Block.objects.create(guid='second@thing', updated_by=user_factory())
        form.is_valid()
        form.clean()  # would raise

        # except if one of the Blocks is already being changed/deleted
        bls = BlocklistSubmission.objects.create(
            input_guids=data['guids'],
            action=BlocklistSubmission.ACTION_DELETE)
        bls.save()
        form.is_valid()
        with self.assertRaises(ValidationError):
            form.clean()