本文整理汇总了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)
示例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)
示例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 = []
示例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 = []
示例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)
示例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)