コード例 #1
0
ファイル: test_forms.py プロジェクト: st333v/addons-server
    def test_existing_blocks_some_existing(self):
        data = {
            'input_guids': 'full@existing',
            'min_version': '0',
            'max_version': '*',
            'existing_min_version': '1',
            'existing_max_version': '10',
        }
        block_admin = BlocklistSubmissionAdmin(model=BlocklistSubmission,
                                               admin_site=admin_site)
        request = RequestFactory().get('/')

        # A single guid is always updated so checks are bypassed
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise

        # Two or more guids trigger the checks
        data.update(input_guids='partial@existing\nfull@existing')
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        with self.assertRaises(ValidationError):
            form.clean()

        # Not if the existing min/max versions match, i.e. they've not been
        # changed
        data.update(
            existing_min_version=data['min_version'],
            existing_max_version=data['max_version'],
        )
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise

        # It should also be okay if the min/max *have* changed but the blocks
        # affected are the same
        data = {
            'input_guids': 'partial@existing\nfull@existing',
            'min_version': '56',
            'max_version': '156',
            'existing_min_version': '23',
            'existing_max_version': '123',
        }
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise
コード例 #2
0
    def test_all_existing_blocks_but_delete_action(self):
        data = {
            'input_guids': 'any@thing\nsecond@thing',
            'action': BlocklistSubmission.ACTION_DELETE
        }
        block_admin = BlocklistSubmissionAdmin(model=BlocklistSubmission,
                                               admin_site=admin_site)
        request = RequestFactory().get('/')

        # checks are bypassed if action != BlocklistSubmission.ACTION_ADDCHANGE
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise

        # Even if min_version or max_version are provided
        data.update(min_version='0',
                    max_version='*',
                    existing_min_version='1234',
                    existing_max_version='4567')
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise
コード例 #3
0
    def test_existing_blocks_no_existing(self):
        data = {
            'input_guids': 'any@new\nanother@new',
            'min_version': '0',
            'max_version': '*',
            'existing_min_version': '1',
            'existing_max_version': '10'}
        block_admin = BlocklistSubmissionAdmin(
            model=BlocklistSubmission, admin_site=admin_site)
        request = RequestFactory().get('/')

        # All new guids should always be fine
        form = block_admin.get_form(request=request)(data=data)
        form.is_valid()
        form.clean()  # would raise if there needed to be a recalculation