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


Python ResponseFactory.build方法代碼示例

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


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

示例1: test_happy_to_rating

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
    def test_happy_to_rating(self):
        """Test we don't populate rating from happy"""
        resp = ResponseFactory.build(happy=True, rating=None)
        resp.save()
        eq_(resp.rating, None)

        resp = ResponseFactory.build(happy=False, rating=None)
        resp.save()
        eq_(resp.rating, None)
開發者ID:rlr,項目名稱:fjord,代碼行數:11,代碼來源:test_models.py

示例2: create_basic_sampledata

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
def create_basic_sampledata():
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    products = sentence_generator(PRODUCTS)
    platforms = sentence_generator(PLATFORMS)
    locales = sentence_generator(settings.DEV_LANGUAGES)
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    Response.objects.bulk_create(objs)
開發者ID:ANKIT-KS,項目名稱:fjord,代碼行數:48,代碼來源:sampledata.py

示例3: create_additional_sampledata

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
def create_additional_sampledata(samplesize="1000"):
    samplesize = int(samplesize)

    print "Generating {0} feedback responses...".format(samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCT_TUPLES)
    urls = sentence_generator(URLS)
    locales = locale_generator()

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u""
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                platform=product[2],
                url=url,
                user_agent=product[3],
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print "  {0}...".format(i)

    if objs:
        print "  {0}...".format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
開發者ID:Givemore,項目名稱:fjord,代碼行數:60,代碼來源:sampledata.py

示例4: create_additional_sampledata

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
def create_additional_sampledata(samplesize):
    samplesize = int(samplesize)

    print 'Working on generating {0} feedback responses....'.format(
        samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCTS)
    urls = sentence_generator(URLS)
    user_agents = sentence_generator(USER_AGENTS)
    locales = sentence_generator(settings.DEV_LANGUAGES)

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u''
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                url=url,
                user_agent=user_agents.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print '  {0}...'.format(i)

    if objs:
        print '  {0}...'.format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
開發者ID:ANKIT-KS,項目名稱:fjord,代碼行數:54,代碼來源:sampledata.py

示例5: test_rating_to_happy

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
 def test_rating_to_happy(self):
     """Test that we do populate happy from rating"""
     data = {
         1: False,
         2: False,
         3: False,
         4: True,
         5: True
     }
     for rat, expected in data.items():
         # Create the response, but DON'T save it to the db.
         resp = ResponseFactory.build(happy=None, rating=rat)
         resp.save()
         eq_(resp.happy, expected)
開發者ID:rlr,項目名稱:fjord,代碼行數:16,代碼來源:test_models.py

示例6: create_basic_sampledata

# 需要導入模塊: from fjord.feedback.tests import ResponseFactory [as 別名]
# 或者: from fjord.feedback.tests.ResponseFactory import build [as 別名]
def create_basic_sampledata():
    print "Generating 100 happy and 100 sad responses..."
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    # Note: We're abusing sentence_generator to just return random
    # choice from a tuple of things.
    products = sentence_generator(PRODUCT_TUPLES)
    locales = locale_generator()
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))

        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=product[2],
                user_agent=product[3],
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=product[2],
                locale=locales.next(),
                user_agent=product[3],
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

    Response.objects.bulk_create(objs)
開發者ID:Givemore,項目名稱:fjord,代碼行數:67,代碼來源:sampledata.py


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