当前位置: 首页>>代码示例>>Python>>正文


Python testutils.override_switch函数代码示例

本文整理汇总了Python中waffle.testutils.override_switch函数的典型用法代码示例。如果您正苦于以下问题:Python override_switch函数的具体用法?Python override_switch怎么用?Python override_switch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了override_switch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_is_feature_enabled

    def test_is_feature_enabled(self):
        request = RequestFactory().get('/')
        request.user = AnonymousUser()

        # Return True if no switch or flag are provided
        self.assertTrue(utils.is_feature_enabled({'switch': None, 'flag': None}, request))

        name = 'test-waffle'
        item = {'switch': 'test-waffle'}
        # Return False if switch inactive
        with override_switch(name, active=False):
            self.assertFalse(utils.is_feature_enabled(item, request))

        # Return True if switch active
        with override_switch(name, active=True):
            self.assertTrue(utils.is_feature_enabled(item, request))

        item = {'flag': 'test-waffle'}
        # Return False if flag inactive
        with override_flag(name, active=False):
            self.assertFalse(utils.is_feature_enabled(item, request))

        # Return True if flag active
        with override_flag(name, active=True):
            self.assertTrue(utils.is_feature_enabled(item, request))
开发者ID:edx,项目名称:edx-analytics-dashboard,代码行数:25,代码来源:test_utils.py

示例2: test_description_optional

    def test_description_optional(self):
        delicious = Addon.objects.get()
        assert delicious.type == amo.ADDON_EXTENSION

        with override_switch('content-optimization', active=False):
            form = forms.DescribeForm(
                {'name': u'Delicious for everyone', 'summary': u'foo',
                 'slug': u'bar'},
                request=self.request, instance=delicious)
            assert form.is_valid(), form.errors

        with override_switch('content-optimization', active=True):
            form = forms.DescribeForm(
                {'name': u'Delicious for everyone', 'summary': u'foo',
                 'slug': u'bar'},
                request=self.request, instance=delicious)
            assert not form.is_valid()

            # But only extensions are required to have a description
            delicious.update(type=amo.ADDON_STATICTHEME)
            form = forms.DescribeForm(
                {'name': u'Delicious for everyone', 'summary': u'foo',
                 'slug': u'bar'},
                request=self.request, instance=delicious)
            assert form.is_valid(), form.errors

            #  Do it again, but this time with a description
            delicious.update(type=amo.ADDON_EXTENSION)
            form = forms.DescribeForm(
                {'name': u'Delicious for everyone', 'summary': u'foo',
                 'slug': u'bar', 'description': u'its a description'},
                request=self.request,
                instance=delicious)
            assert form.is_valid(), form.errors
开发者ID:iamVP7,项目名称:addons-server,代码行数:34,代码来源:test_forms.py

示例3: test_summary_min_length

    def test_summary_min_length(self):
        delicious = Addon.objects.get()
        assert delicious.type == amo.ADDON_EXTENSION

        with override_switch('content-optimization', active=False):
            form = forms.DescribeForm(
                {'name': 'Delicious for everyone', 'summary': 'foo',
                 'slug': 'bar', 'description': '123456789'},
                request=self.request, instance=delicious)
            assert form.is_valid(), form.errors

        with override_switch('content-optimization', active=True):
            form = forms.DescribeForm(
                {'name': 'Delicious for everyone', 'summary': 'foo',
                 'slug': 'bar', 'description': '123456789'},
                request=self.request, instance=delicious)
            assert not form.is_valid()

            # But only extensions have a minimum length
            delicious.update(type=amo.ADDON_STATICTHEME)
            form = forms.DescribeForm(
                {'name': 'Delicious for everyone', 'summary': 'foo',
                 'slug': 'bar', 'description': '123456789'},
                request=self.request, instance=delicious)
            assert form.is_valid()

            #  Do it again, but this time with a description
            delicious.update(type=amo.ADDON_EXTENSION)
            form = forms.DescribeForm(
                {'name': 'Delicious for everyone', 'summary': 'foo',
                 'slug': 'bar', 'description': '1234567890'},
                request=self.request,
                instance=delicious)
            assert form.is_valid(), form.errors
开发者ID:bqbn,项目名称:addons-server,代码行数:34,代码来源:test_forms.py

示例4: test_new_switch

    def test_new_switch(self):
        assert not Switch.objects.filter(name='foo').exists()

        with override_switch('foo', active=True):
            assert waffle.switch_is_active('foo')

        with override_switch('foo', active=False):
            assert not waffle.switch_is_active('foo')

        assert not Switch.objects.filter(name='foo').exists()
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py

示例5: test_new_switch

    def test_new_switch(self):
        assert not Switch.objects.filter(name="foo").exists()

        with override_switch("foo", active=True):
            assert waffle.switch_is_active(req(), "foo")

        with override_switch("foo", active=False):
            assert not waffle.switch_is_active(req(), "foo")

        assert not Switch.objects.filter(name="foo").exists()
开发者ID:webus,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py

示例6: test_switch_existed_and_was_NOT_active

    def test_switch_existed_and_was_NOT_active(self):
        Switch.objects.create(name='foo', active=False)

        with override_switch('foo', active=True):
            assert waffle.switch_is_active('foo')

        with override_switch('foo', active=False):
            assert not waffle.switch_is_active('foo')

        # make sure it didn't change 'active' value
        assert not Switch.objects.get(name='foo').active
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py

示例7: test_cache_is_flushed_by_testutils_even_in_transaction

    def test_cache_is_flushed_by_testutils_even_in_transaction(self):
        Switch.objects.create(name='foo', active=True)

        with transaction.atomic():
            with override_switch('foo', active=True):
                assert waffle.switch_is_active('foo')

            with override_switch('foo', active=False):
                assert not waffle.switch_is_active('foo')

        assert waffle.switch_is_active('foo')
开发者ID:jsocol,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py

示例8: test_switch_existed_and_was_active

    def test_switch_existed_and_was_active(self):
        Switch.objects.create(name="foo", active=True)

        with override_switch("foo", active=True):
            assert waffle.switch_is_active(req(), "foo")

        with override_switch("foo", active=False):
            assert not waffle.switch_is_active(req(), "foo")

        # make sure it didn't change 'active' value
        assert Switch.objects.get(name="foo").active
开发者ID:webus,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py

示例9: test_maybe_check_with_akismet

def test_maybe_check_with_akismet(body, pre_save_body, user_id,
                                  user_id_resp, waffle_enabled, is_checked):
    user = user_factory(
        id=user_id, username='u%s' % user_id, email='%[email protected]' % user_id)
    rating_kw = {
        'addon': addon_factory(),
        'user': user,
        'rating': 4,
        'body': body,
        'ip_address': '1.2.3.4'}

    if user_id_resp:
        rating_kw['user_responsible'] = (
            user if user_id_resp == user_id
            else user_factory(
                id=user_id_resp, username='u%s' % user_id_resp,
                email='%[email protected]' % user_id_resp))

    rating = Rating.objects.create(**rating_kw)
    request = RequestFactory().get('/')

    to_patch = 'olympia.ratings.utils.check_akismet_reports.delay'
    with mock.patch(to_patch) as check_akismet_reports_mock:
        with override_switch('akismet-spam-check', active=waffle_enabled):
            result = maybe_check_with_akismet(request, rating, pre_save_body)
            assert result == is_checked
            if is_checked:
                assert AkismetReport.objects.count() == 1
                check_akismet_reports_mock.assert_called()
            else:
                assert AkismetReport.objects.count() == 0
                check_akismet_reports_mock.assert_not_called()
开发者ID:diox,项目名称:olympia,代码行数:32,代码来源:test_utils_.py

示例10: test_translate_template

def test_translate_template(client):
    url = reverse('pontoon.translate.next')

    with override_switch('translate_next', active=True):
        response = client.get(url)
        assert response.status_code == 200
        assert 'Translate.Next' in response.content
开发者ID:Pike,项目名称:pontoon,代码行数:7,代码来源:test_views.py

示例11: test_has_project_and_draft_registration

    def test_has_project_and_draft_registration(self):
        prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge')
        factories.DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema
        )

        assert_equal(
            landing_page(user=self.user),
            {
                'has_projects': True,
                'has_draft_registrations': True,
                'campaign_long': 'Prereg Challenge',
                'campaign_short': 'prereg_challenge',
                'is_logged_in': True,
            }
        )

        with override_switch(name=OSF_PREREGISTRATION, active=True):
            prereg_schema = RegistrationSchema.objects.get(name='OSF Preregistration')
            factories.DraftRegistrationFactory(
                initiator=self.user,
                registration_schema=prereg_schema
            )
            assert_equal(
                landing_page(user=self.user),
                {
                    'has_projects': True,
                    'has_draft_registrations': True,
                    'campaign_long': 'OSF Preregistration',
                    'campaign_short': 'prereg',
                    'is_logged_in': True,
                }
            )
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:34,代码来源:test_prereg.py

示例12: test_check_akismet_reports

def test_check_akismet_reports(return_value, headers, waffle_on, flag_count):
    task_user = user_factory(id=settings.TASK_USER_ID)
    assert RatingFlag.objects.count() == 0
    rating = Rating.objects.create(
        addon=addon_factory(), user=user_factory(), rating=4, body=u'spám?',
        ip_address='1.2.3.4')
    akismet_report = AkismetReport.create_for_rating(rating, 'foo/baa', '')

    with mock.patch('olympia.lib.akismet.models.requests.post') as post_mock:
        # Mock a definitely spam response - same outcome
        post_mock.return_value.json.return_value = return_value
        post_mock.return_value.headers = headers
        with override_switch('akismet-rating-action', active=waffle_on):
            check_akismet_reports([akismet_report.id])

    RatingFlag.objects.count() == flag_count
    rating = rating.reload()
    if flag_count > 0:
        flag = RatingFlag.objects.get()
        assert flag.rating == rating
        assert flag.user == task_user
        assert flag.flag == RatingFlag.SPAM
        assert rating.editorreview
    else:
        assert not rating.editorreview
开发者ID:mozilla,项目名称:addons-server,代码行数:25,代码来源:test_tasks.py

示例13: test_has_project

    def test_has_project(self):
        factories.ProjectFactory(creator=self.user)

        assert_equal(
            landing_page(user=self.user),
            {
                'has_projects': True,
                'has_draft_registrations': False,
                'campaign_long': 'Prereg Challenge',
                'campaign_short': 'prereg_challenge',
                'is_logged_in': True,
            }
        )

        with override_switch(name=OSF_PREREGISTRATION, active=True):
            assert_equal(
                landing_page(user=self.user),
                {
                    'has_projects': True,
                    'has_draft_registrations': False,
                    'campaign_long': 'OSF Preregistration',
                    'campaign_short': 'prereg',
                    'is_logged_in': True,
                }
            )
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:25,代码来源:test_prereg.py

示例14: test_try_new_frontend_banner_presence

    def test_try_new_frontend_banner_presence(self):
        response = self.client.get(self.url)
        assert b'AMO is getting a new look.' not in response.content

        with override_switch('try-new-frontend', active=True):
            response = self.client.get(self.url)
            assert b'AMO is getting a new look.' in response.content
开发者ID:iamVP7,项目名称:addons-server,代码行数:7,代码来源:tests.py

示例15: test_waffle_switch_inactive_does_not_enforce_csrf

 def test_waffle_switch_inactive_does_not_enforce_csrf(self, app, url, payload):
     with override_switch('enforce_csrf', active=False):
         res = app.post_json_api(
             url,
             payload,
             expect_errors=True
         )
     assert res.status_code == 201
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:8,代码来源:test_auth.py


注:本文中的waffle.testutils.override_switch函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。