本文整理汇总了Python中coupon.factories.slot_factory.SLOT_FACTORY.prepare_slot_coupons_for_flyer方法的典型用法代码示例。如果您正苦于以下问题:Python SLOT_FACTORY.prepare_slot_coupons_for_flyer方法的具体用法?Python SLOT_FACTORY.prepare_slot_coupons_for_flyer怎么用?Python SLOT_FACTORY.prepare_slot_coupons_for_flyer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coupon.factories.slot_factory.SLOT_FACTORY
的用法示例。
在下文中一共展示了SLOT_FACTORY.prepare_slot_coupons_for_flyer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_flyers_for_city
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_create_flyers_for_city(self):
""" Assert flyers are created for Poughkeepsie placement. """
slots = SLOT_FACTORY.create_slots(create_count=2)
SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots)
flyer_placement = FlyerPlacement.objects.create(site=self.site,
slot=slots[0], send_date=self.next_flyer_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement, geolocation_id=17009,
geolocation_type=self.city_type)
create_flyers_this_site_phase2(self.site, self.next_flyer_date,
Coupon.objects.none())
flyers = self.site.flyers.filter(
send_date=self.next_flyer_date).order_by('id')
self.assertEqual(flyers.count(), 2)
# This flyer has one subdivision, and it is Poughkeepsie.
self.assertEqual(flyers[0].flyer_subdivisions.count(), 1)
self.assertEqual(flyers[0].flyer_subdivisions.filter(
geolocation_type=self.city_type,
geolocation_id=17009).count(), 1)
self.assertTrue(flyers[1].flyer_subdivisions.count() > 6)
# This flyer has subdivisions for other counties except Dutchess, and
# for Red Hook, a city in Dutchess.
self.assertEqual(flyers[1].flyer_subdivisions.filter(
geolocation_type=self.county_type,
geolocation_id__in=[1866, 1890, 1886]).count(), 3)
self.assertEqual(flyers[1].flyer_subdivisions.filter(
geolocation_type=self.city_type,
geolocation_id=17043).count(), 1)
示例2: test_send_flyers_this_week
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_send_flyers_this_week(self):
""" Assert a flyer is sent. Assert the coupon links are correct. """
flyer = Flyer.objects.create(site_id=2, is_approved=2)
slots = SLOT_FACTORY.create_slots(create_count=2)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots)
for coupon in coupons:
append_coupon_to_flyer(flyer, coupon)
# It needs an eligible recipient.
consumer = CONSUMER_FACTORY.create_consumer()
CONSUMER_FACTORY.qualify_consumer(consumer)
send_flyers_this_week()
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[0].subject, 'Recent Hudson Valley coupons')
# Find the specific email to our test consumer.
x = 0
while x < len(mail.outbox):
if mail.outbox[x].to[0] == consumer.email:
break
x += 1
self.assertEqual(mail.outbox[0].extra_headers['From'],
'10HudsonValleyCoupons.com <[email protected]>')
target_path = '%s%s' % (settings.HTTP_PROTOCOL_HOST,
reverse('opt_out', kwargs={'payload':
PAYLOAD_SIGNING.create_payload(email=consumer.email)}))
# We cannot predict the signed email payload, so trim that piece of the
# url.
payload = target_path.split('/')[-2]
target_path = '/'.join(target_path.split('/')[:-2]) + '/'
self.assertTrue(target_path in
mail.outbox[x].extra_headers['List-Unsubscribe'])
LOG.debug(mail.outbox[0].body)
# Assert the opt out link is in the html version of the email.
self.assertTrue(target_path in mail.outbox[0].alternatives[0][0])
self.assertTrue('<mailto:list_unsubscribe-consumer_standard_flyer-' in
mail.outbox[0].extra_headers['List-Unsubscribe'])
self.assertTrue('@bounces.10coupons.com>' in
mail.outbox[0].extra_headers['List-Unsubscribe'])
for coupon in coupons:
# We cannot predict the random obfuscation of the email hash.
# So pass it as blank.
target_path = '%s%s' % (settings.HTTP_PROTOCOL_HOST,
reverse('flyer-click', args=[coupon.id, payload]))
target_path = '/'.join(target_path.split('/')[:-2]) + '/'
# Assert this url is in plain text version.
self.assertTrue(target_path in mail.outbox[0].body)
# Assert this url is in html version.
self.assertTrue(target_path in mail.outbox[0].alternatives[0][0])
# Assert a signed payload exists in each version.
# The payload for the opt-out link does not need to be the same string
# as the payload for the header, as long as they both load to the same.
payload = mail.outbox[x].body[
mail.outbox[x].body.index('opt-out-list/') + 13:].split('/')[0]
self.assertEqual(PAYLOAD_SIGNING.parse_payload(payload)['email'],
consumer.email)
self.assertTrue(payload in mail.outbox[x].alternatives[0][0])
flyer = Flyer.objects.get(id=flyer.id)
# Assert the flyer is now marked as sent.
self.assertTrue(flyer.send_status, '2')
self.assertTrue(FlyerConsumer.objects.filter(flyer=flyer,
consumer__id=consumer.id).count(), 1)
示例3: test_show_sample_flyer
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_show_sample_flyer(self):
""" Assert the sample flyer is displayed. """
flyer = Flyer.objects.get(id=401)
flyer.send_status = 2
flyer.save()
sent_date = '%s%s' % (flyer.send_date.strftime('%A, %B '),
flyer.send_date.strftime('%e').strip())
slots = SLOT_FACTORY.create_slots(create_count=2)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots)
for coupon in coupons:
FlyerCoupon.objects.create(flyer=flyer, coupon=coupon)
response = self.client.get(reverse('sample-flyer'))
self.assertTemplateUsed(response, 'display_sample_flyer.html')
self.assertTemplateUsed(response,
'include/dsp/dsp_coupons_for_flyer.html')
self.assertContains(response, sent_date)
self.assertContains(response, flyer.coupon.all()[0].offer.headline)
示例4: test_tweet_approved_coupon
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_tweet_approved_coupon(self):
""" Assert an approved coupon is tweeted.
To verify Tweet is unique, a random string is added.
Revised test to run no more than once every 5 minutes. """
slot = SLOT_FACTORY.create_slot()
coupon = SLOT_FACTORY.prepare_slot_coupons_for_flyer([slot])[0]
hours = 0.08
filename = settings.MEDIA_ROOT + 'feed/twittercom.htm'
if os.path.exists(filename) and is_file_recent(filename=filename,
hours=hours):
LOG.debug('skipping test_tweet_approved_coupon')
else:
get_web_page(web_url='http://twitter.com', hours=hours)
time.sleep(10)
# check latest twitter status
tweet = TWITTER_SERVICE.twitter_connect(coupon)
if tweet:
LOG.debug('tweet = %s' % tweet)
self.assertTrue(coupon.offer.headline in tweet)
self.assertTrue(coupon.offer.qualifier in tweet)
示例5: test_process_city
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_process_city(self):
""" Assert all the zips of Poughkeepsie are covered when a flyer exists
for the zip code 12601.
"""
slots = SLOT_FACTORY.create_slots(create_count=2)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots)
flyer_placement = FlyerPlacement.objects.create(site=self.site,
slot=slots[0], send_date=self.next_flyer_date)
catchall_flyer = Flyer.objects.create(site=self.site,
send_date=self.next_flyer_date)
flyer_12601 = Flyer.objects.create(site=self.site,
send_date=self.next_flyer_date)
FlyerSubdivision.objects.create(
flyer=flyer_12601, geolocation_type=self.zip_type,
geolocation_id=16045)
process_city(catchall_flyer, 17009, coupons[1], flyer_placement, [])
# Assert two other zip codes of Poughkeepsie were added to the catchall
# flyer.
self.assertEqual(catchall_flyer.flyer_subdivisions.filter(
geolocation_type=self.zip_type,
geolocation_id__in=[30218, 31367]).count(), 2)
示例6: test_process_county
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_process_county(self):
""" Assert Orange County is fully covered for flyers. """
slots = SLOT_FACTORY.create_slots(create_count=2)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots)
flyer_placement = FlyerPlacement.objects.create(site=self.site,
slot=slots[0], send_date=self.next_flyer_date)
flyer_12550 = Flyer.objects.create(site=self.site,
send_date=self.next_flyer_date)
FlyerSubdivision.objects.create(flyer=flyer_12550,
geolocation_type=self.zip_type, geolocation_id=23181)
flyer_new_windsor = Flyer.objects.create(site=self.site,
send_date=self.next_flyer_date)
FlyerSubdivision.objects.create(flyer=flyer_new_windsor,
geolocation_type=self.city_type, geolocation_id=17555)
catchall_flyer = Flyer.objects.create(site=self.site)
process_county(catchall_flyer, 1866, coupons[1], flyer_placement)
# Assert it got the subdivision for city Cornwall.
self.assertTrue(catchall_flyer.flyer_subdivisions.filter(
geolocation_type=self.city_type, geolocation_id=17536).count(), 1)
# Assert it got the subdivision for city Maybrook.
self.assertTrue(catchall_flyer.flyer_subdivisions.filter(
geolocation_type=self.city_type, geolocation_id=17549).count(), 1)
示例7: test_create_flyers_this_week
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_create_flyers_this_week(self):
""" Assert a site in Phase 2 falls back to Phase 1 logic when no flyer
placements are sold. Assert no flyer created for site 3 because no
consumers. """
# A slot on site 2 will be included in the flyer for free.
slot = SLOT_FACTORY.create_slot()
send_date = datetime.date(2011, 11, 17)
coupon = SLOT_FACTORY.prepare_slot_coupons_for_flyer(
[slot], send_date)[0]
site = Site.objects.get(id=3)
site.phase = 2
site.save()
create_flyers_this_week(send_date=send_date)
flyer = Flyer.objects.filter(send_date=send_date).latest('id')
self.assertEqual(flyer.site_id, 2) # Therefore no flyer site 3.
self.assertFalse(flyer.is_approved)
self.assertEqual(flyer.send_datetime, None)
self.assertEqual(flyer.send_status, '0')
self.assertEqual(flyer.flyer_coupons.count(), 1)
self.assertEqual(
flyer.flyer_coupons.filter(coupon__id=coupon.id).count(), 1)
self.assertEqual(flyer.flyer_subdivisions.count(), 0)
self.assertTrue('Hudson Valley, []' in mail.outbox[0].body)
示例8: test_create_update_flyer_subs
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_create_update_flyer_subs(self):
""" Assert minimal flyers created for placements in Dutchess county. """
slot = SLOT_FACTORY.create_slot()
coupon = SLOT_FACTORY.prepare_slot_coupons_for_flyer([slot])[0]
flyer_placement = FlyerPlacement.objects.create(site=self.site,
slot=slot, send_date=self.next_flyer_date)
# 12601.
flyer_placement_subdivision = FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement, geolocation_type=self.zip_type,
geolocation_id=16045)
flyer = Flyer.objects.create(site=self.site, is_approved=True,
send_date=self.next_flyer_date)
# Poughkeepsie
FlyerSubdivision.objects.create(flyer=flyer, geolocation_id=17009,
geolocation_type=self.city_type)
create_update_flyers_subs(FlyerPlacementSubdivision.objects.filter(
id=flyer_placement_subdivision.id), 'uszip', flyer_placement,
coupon, self.site)
# The city flyer subdivision has been split into at least 3 zip
# subdivisions.
self.assertTrue(FlyerSubdivision.objects.filter(
flyer__in=Flyer.objects.filter(
site=self.site, send_date=self.next_flyer_date),
geolocation_type=self.zip_type).count() > 2)
示例9: test_create_flyers_phase2
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import prepare_slot_coupons_for_flyer [as 别名]
def test_create_flyers_phase2(self):
""" Assert flyers are built for a site in phase 2. """
# Use a unique date to avoid collision with other tests.
send_date = datetime.date(2011, 11, 10)
slots = SLOT_FACTORY.create_slots(create_count=15)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots, send_date)
# 12550
flyer_placement = FlyerPlacement.objects.create(slot=slots[0],
site=self.site, send_date=send_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.zip_type,
geolocation_id=23181)
# Dutchess, Westchester
flyer_placement = FlyerPlacement.objects.create(slot=slots[1],
site=self.site, send_date=send_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.county_type,
geolocation_id=1844)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.county_type,
geolocation_id=1890)
# 12601, 10570
flyer_placement = FlyerPlacement.objects.create(slot=slots[2],
site=self.site, send_date=send_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.zip_type,
geolocation_id=16045)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.zip_type,
geolocation_id=16142)
# 12518
flyer_placement = FlyerPlacement.objects.create(slot=slots[3],
site=self.site, send_date=send_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.zip_type,
geolocation_id=15145)
# White Plains
flyer_placement = FlyerPlacement.objects.create(slot=slots[4],
site=self.site, send_date=send_date)
FlyerPlacementSubdivision.objects.create(
flyer_placement=flyer_placement,
geolocation_type=self.city_type,
geolocation_id=18258)
pre_count = Flyer.objects.filter(send_date=send_date).count()
admin_data = create_flyers_this_site_phase2(site=self.site,
send_date=send_date, national_coupons=Coupon.objects.none())
LOG.debug('admin_data: %s' % admin_data)
self.assertEqual(admin_data[0],
'Hudson Valley, [<FlyerSubdivision: 12550>]')
flyers = Flyer.objects.filter(send_date=send_date)
LOG.debug([(
flyer, flyer.flyer_coupons.all()) for flyer in flyers])
# All of these flyers need at least one FlyerSubdivision.
self.assertFalse(flyers.annotate(sub_count=Count(
'flyer_subdivisions')).filter(sub_count=0).count())
LOG.debug([(flyer, flyer.flyer_subdivisions.all()) for flyer in flyers])
self.assertEqual(flyers.count(), pre_count + 6)
# Assert this flyer has correct paid coupon, extra coupons, and goes to
# zip 12550.
flyer = flyers.get(flyer_subdivisions__geolocation_id=23181)
self.assertEqual(flyer.flyer_coupons.count(), 10)
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[0]).count())
self.assertEqual(flyer.flyer_subdivisions.count(), 1)
# Assert this flyer has another paid coupon too, and goes to zip 12601.
# (10570 is a subset of Westchester and 12601 is a subset of Dutchess.)
flyer = flyers.get(flyer_subdivisions__geolocation_id=16045)
self.assertEqual(flyer.flyer_coupons.count(), 10)
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[1]).count())
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[2]).count())
self.assertEqual(flyer.flyer_subdivisions.count(), 2)
# Assert this flyer has the paid coupon and goes to 12518.
flyer = flyers.get(flyer_subdivisions__geolocation_id=15145)
self.assertEqual(flyer.flyer_subdivisions.count(), 1)
self.assertEqual(flyer.flyer_coupons.count(), 10)
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[3]).count())
# Assert this flyer for remaining zips of Dutchess.
flyer = flyers.get(flyer_subdivisions__geolocation_id=30218)
self.assertTrue(flyer.flyer_subdivisions.filter(
geolocation_id=31367, geolocation_type__model='uszip').count())
# Assert Westchester gets two flyers: one for 10570 and one without.
# White Plains zip remains with the original Westchester flyer.
flyer = flyers.get(flyer_subdivisions__geolocation_id=18258)
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[4]).count())
# This Pleasantville zip, 10570, has a flyer with an extra coupon.
flyer = flyers.get(flyer_subdivisions__geolocation_id=16142)
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[2]).count())
self.assertTrue(flyer.flyer_coupons.filter(coupon=coupons[1]).count())