當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.TESTING屬性代碼示例

本文整理匯總了Python中django.conf.settings.TESTING屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.TESTING屬性的具體用法?Python settings.TESTING怎麽用?Python settings.TESTING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.TESTING屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ready

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def ready(self):
        super().ready()
        """
        This magic executes modules named search_indexes in every installed app. Search indexes
        is registered this way.
        """
        if not settings.TESTING:
            # Simple way to initialize the search backend. We may change this in the future.
            if settings.SEARCH_BACKEND == "elasticsearch":
                search_backed = ElasticsearchBackend()
            elif settings.SEARCH_BACKEND == "postgres":
                search_backed = PostgresBackend()
            else:
                raise ValueError("Invalid search backend")

            search_backed.set_up()
            backend.current_backend = search_backed

            autodiscover_modules("search_indexes")
            from .signals import post_save_callback, post_delete_callback  # noqa 
開發者ID:webkom,項目名稱:lego,代碼行數:22,代碼來源:apps.py

示例2: save_kobocat_user

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def save_kobocat_user(sender, instance, created, raw, **kwargs):
    """
    Sync auth_user table between KPI and KC, and, if the user is newly created,
    grant all KoBoCAT model-level permissions for the content types listed in
    `settings.KOBOCAT_DEFAULT_PERMISSION_CONTENT_TYPES`
    """
    if not settings.TESTING:
        KobocatUser.sync(instance)

        if created:
            # FIXME: If this fails, the next attempt results in
            #   IntegrityError: duplicate key value violates unique constraint
            #   "auth_user_username_key"
            # and decorating this function with `transaction.atomic` doesn't
            # seem to help. We should roll back the KC user creation if
            # assigning model-level permissions fails
            grant_kc_model_level_perms(instance) 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:19,代碼來源:signals.py

示例3: clean_description

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def clean_description(self):
        desc = self.cleaned_data['description']
        if settings.TESTING:
            check_spam = False
        else:
            akismet = Akismet(settings.AKISMET_KEY, blog="CC Search")
            check_spam = akismet.check(self.request.get_host(),
                                  user_agent=self.request.META.get('user-agent'),
                                  comment_author=self.request.user.username,
                                  comment_content=desc)
        wordfilter = Wordfilter()
        check_words = wordfilter.blacklisted(desc)
        if check_spam or check_words:
            raise forms.ValidationError("This description failed our spam or profanity check; the description has not been updated.")

        return desc 
開發者ID:cc-archive,項目名稱:open-ledger,代碼行數:18,代碼來源:forms.py

示例4: member_post_save_webhook_cb

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def member_post_save_webhook_cb(
    sender, instance, created, raw, update_fields, **kwargs
):
    """
    Send a webhook alert when a user signs up.
    """
    if raw or not created or settings.TESTING or settings.ENV != "production":
        return

    try:
        requests.post(
            settings.ZAPIER_WEBHOOK_URL,
            json={
                "type": "member-created",
                "name": instance.name,
                "username": instance.user.username,
                "email": instance.primary_email.email,
            },
        )
    except:  # pylint: disable=bare-except
        # monitoring should never interfere with the operation of the site
        pass 
開發者ID:OpenHumans,項目名稱:open-humans,代碼行數:24,代碼來源:signals.py

示例5: ready

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def ready(self):
        if not settings.TESTING:
            from lego.apps.events.models import Event
            from lego.apps.events.signals import event_save_callback

            post_save.connect(event_save_callback, sender=Event) 
開發者ID:webkom,項目名稱:lego,代碼行數:8,代碼來源:apps.py

示例6: disable_on_test

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def disable_on_test(signal_handler):
    """
    Decorator that turns off signal handlers when loading fixture data and running tests.
    """

    @wraps(signal_handler)
    def wrapper(*args, **kwargs):
        if kwargs.get("raw") or settings.TESTING:
            return
        return signal_handler(*args, **kwargs)

    return wrapper 
開發者ID:webkom,項目名稱:lego,代碼行數:14,代碼來源:events.py

示例7: save_kobocat_token

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def save_kobocat_token(sender, instance, **kwargs):
    """
    Sync AuthToken table between KPI and KC
    """
    if not settings.TESTING:
        KobocatToken.sync(instance) 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:8,代碼來源:signals.py

示例8: delete_kobocat_token

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def delete_kobocat_token(sender, instance, **kwargs):
    """
    Delete corresponding record from KC AuthToken table
    """
    if not settings.TESTING:
        try:
            KobocatToken.objects.get(pk=instance.pk).delete()
        except KobocatToken.DoesNotExist:
            pass 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:11,代碼來源:signals.py

示例9: update_search_index

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def update_search_index(sender, instance, **kwargs):
    """When an Image instance is saved, tell the search engine about it."""
    if not settings.TESTING:
        _update_search_index(instance) 
開發者ID:cc-archive,項目名稱:open-ledger,代碼行數:6,代碼來源:signals.py

示例10: toggle_data

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def toggle_data(self, user, source, public):
        if source not in get_source_labels() and not source.startswith(
            "direct-sharing-"
        ):
            error_msg = (
                "Public sharing toggle attempted for "
                'unexpected source "{}"'.format(source)
            )
            django_messages.error(self.request, error_msg)

            if not settings.TESTING:
                raven_client.captureMessage(error_msg)
            return
        project = id_label_to_project(source)
        project_membership = DataRequestProjectMember.objects.get(
            member=user.member, project=project
        )

        participant = user.member.public_data_participant
        access, _ = PublicDataAccess.objects.get_or_create(
            participant=participant, project_membership=project_membership
        )
        access.is_public = False
        if public == "True":
            if not project.no_public_data:
                access.is_public = True
        access.save()

        if (
            project.approved
            and not ActivityFeed.objects.filter(
                member=user.member, project=project, action="publicly-shared"
            ).exists()
        ):
            event = ActivityFeed(
                member=user.member, project=project, action="publicly-shared"
            )
            event.save() 
開發者ID:OpenHumans,項目名稱:open-humans,代碼行數:40,代碼來源:views.py

示例11: test_settings

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def test_settings(self):
        """
        Ensure the test settings module works as expected
        """
        from django.conf import settings
        self.assertTrue(settings.TESTING)
        self.assertEqual(settings.LOGIN_URL, "/simple/login/")
        with self.settings(UNIAUTH_LOGIN_DISPLAY_STANDARD=False):
            self.assertFalse(settings.UNIAUTH_LOGIN_DISPLAY_STANDARD) 
開發者ID:lgoodridge,項目名稱:django-uniauth,代碼行數:11,代碼來源:test_simple.py

示例12: get

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def get(self, request, *args, **kwargs):
        image = self.get_object()
        alias = kwargs.pop('alias')
        r = kwargs.pop('r')
        opts = {
            'revision_label': r,
            'animated': 'animated' in self.request.GET,
            'insecure': 'insecure' in self.request.GET,
        }

        force = request.GET.get('force')
        if force is not None:
            image.thumbnail_invalidate()

        sync = request.GET.get('sync')
        if sync is not None:
            opts['sync'] = True

        if settings.TESTING:
            thumb = image.thumbnail_raw(alias, opts)
            if thumb:
                return redirect(thumb.url)
            return None

        url = image.thumbnail(alias, opts)
        return redirect(smart_unicode(url)) 
開發者ID:astrobin,項目名稱:astrobin,代碼行數:28,代碼來源:image.py

示例13: call_update_in_new_process

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def call_update_in_new_process(self, enabled=not settings.TESTING):
        if enabled and self.comment.reply_content:
            for _ in xrange(knobs.FOOTER_UPDATE_ATTEMPTS):
                try:
                    subprocess.check_call(
                        ["env", "python", "/var/canvas/website/manage.py", "generate_footer", str(self.comment.id)],
                        env={'DISPLAY': ':0'}
                    )
                except subprocess.CalledProcessError:
                    continue
                break 
開發者ID:canvasnetworks,項目名稱:canvas,代碼行數:13,代碼來源:footer.py

示例14: member_pre_save_cb

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import TESTING [as 別名]
def member_pre_save_cb(sender, instance, raw, **kwargs):
    """
    Subscribe or unsubscribe a user from Mailchimp.
    """
    if raw or settings.TESTING:
        return

    try:
        member = sender.objects.get(pk=instance.pk)
    except sender.DoesNotExist:
        pass
    else:
        if member.newsletter == instance.newsletter:
            return

    if not settings.MAILCHIMP_API_KEY:
        logger.warn(
            "User changed email preference but no Mailchimp API key "
            "has been specified, set MAILCHIMP_API_KEY."
        )

        return

    mc = mailchimp.Mailchimp(settings.MAILCHIMP_API_KEY)

    try:
        address = instance.primary_email.email
    except AttributeError:
        # We're not sure why the callback is firing an extra time, before
        # SignupView.create_account runs (when email not yet saved).
        return

    if instance.newsletter:
        try:
            mc.lists.subscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                double_optin=False,
                update_existing=True,
            )
        except mailchimp.ListAlreadySubscribedError:
            logger.info('"%s" was already subscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e)
    else:
        try:
            mc.lists.unsubscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                send_goodbye=False,
                send_notify=False,
            )
        except (mailchimp.ListNotSubscribedError, mailchimp.EmailNotExistsError):
            logger.info('"%s" was already unsubscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e) 
開發者ID:OpenHumans,項目名稱:open-humans,代碼行數:58,代碼來源:signals.py


注:本文中的django.conf.settings.TESTING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。