本文整理汇总了Python中coupon.factories.slot_factory.SLOT_FACTORY.create_slots方法的典型用法代码示例。如果您正苦于以下问题:Python SLOT_FACTORY.create_slots方法的具体用法?Python SLOT_FACTORY.create_slots怎么用?Python SLOT_FACTORY.create_slots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coupon.factories.slot_factory.SLOT_FACTORY
的用法示例。
在下文中一共展示了SLOT_FACTORY.create_slots方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_flyers_this_week
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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)
示例2: test_business_preference
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def test_business_preference(self):
""" Assert distinct businesses are preferred. """
slot_family = SLOT_FACTORY.create_slot_family()
slots = SLOT_FACTORY.create_slots(create_count=3)
site = Site.objects.get(id=2)
content = CreateWidget().run(site, template='10CouponsWidget160x600.js')
LOG.debug(content)
LOG.debug('slot_family: %s' % str(slot_family))
LOG.debug('slots: %s' % slots)
# Parent slot, created first, in in content first.
self.assertTrue(content.find(
slot_family[0]['parent'].slot_time_frames.all(
)[0].coupon.offer.headline) < content.find(
slots[0].slot_time_frames.all()[0].coupon.offer.headline))
# These unrelated slots are next.
self.assertTrue(content.find(
slots[0].slot_time_frames.all()[0].coupon.offer.headline) <
content.find(
slots[1].slot_time_frames.all()[0].coupon.offer.headline))
self.assertTrue(content.find(
slots[1].slot_time_frames.all()[0].coupon.offer.headline) <
content.find(
slots[2].slot_time_frames.all()[0].coupon.offer.headline))
# The unrelated slots were preferred over the child slots
self.assertTrue(content.find(
slots[2].slot_time_frames.all()[0].coupon.offer.headline) <
slot_family[0]['children'][0].slot_time_frames.all(
)[0].coupon.offer.headline)
示例3: test_create_flyers_for_city
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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)
示例4: setUp
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def setUp(self):
super(TestGetSlotCoupons, self).setUp()
self.site = Site.objects.get(id=2)
self.initial_coupon_count = \
Coupon.current_coupons.get_current_coupons_by_site(
self.site).count()
self.slot_list = SLOT_FACTORY.create_slots(5)
示例5: create_two_flyer_placements
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def create_two_flyer_placements(self):
""" Create two flyer placements. """
slots = SLOT_FACTORY.create_slots(create_count=2)
flyer_placements = []
for slot in slots:
flyer_placements.append(
FlyerPlacement.objects.create(slot=slot, site=self.site,
send_date=self.send_date))
return flyer_placements
示例6: setUp
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def setUp(self):
super(SearchCouponsTestCase, self).setUp()
self.slot_list = SLOT_FACTORY.create_slots(create_count=5)
haystack_site.get_index(Coupon).reindex()
self.coupon_list = SLOT_FACTORY.get_active_coupons(
slot_list=self.slot_list)
self.coupon0 = self.coupon_list[0]
self.all_coupons = ALL_COUPONS.get_all_coupons(
Site.objects.get(id=2))[0]
self.request_data = None
self.response = None
示例7: setUp
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def setUp(self):
""" Prep data for each test. """
super(TestGenericFeedView, self).setUp()
self.slots = SLOT_FACTORY.create_slots(2)
self.coupon_1 = self.slots[0].slot_time_frames.all()[0].coupon
self.coupon_1.is_redeemed_by_sms = True
self.coupon_1.save()
COUPON_LOCATION_FACTORY.create_coupon_location(coupon=self.coupon_1)
self.coupon_2 = self.slots[1].slot_time_frames.all()[0].coupon
self.coupon_2.is_redeemed_by_sms = True
self.coupon_2.save()
COUPON_LOCATION_FACTORY.create_coupon_locations(coupon=self.coupon_2,
create_all=True, coupon_location_count=2)
self.generic_coupon_feed = GenericCouponFeed()
示例8: test_no_current_coupon
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def test_no_current_coupon(self):
""" Assert a flyer placement is skipped when no current coupon. """
slots = SLOT_FACTORY.create_slots(create_count=2)
slots[0].slot_time_frames.all().delete()
FlyerPlacement.objects.create(site=self.site,
slot=slots[0], send_date=self.next_flyer_date)
national_coupons = Coupon.objects.filter(
id=slots[1].slot_time_frames.all()[0].coupon.id)
create_flyers_this_site_phase2(self.site, self.next_flyer_date,
national_coupons)
try:
flyer = self.site.flyers.get(send_date=self.next_flyer_date)
except Flyer.DoesNotExist:
self.fail('Flyer was not created.')
self.assertEqual(flyer.flyer_subdivisions.count(), 0)
示例9: test_show_sample_flyer
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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)
示例10: setUp
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def setUp(self):
super(TestSortCoupons, self).setUp()
slots = SLOT_FACTORY.create_slots(create_count=3)
coupons = []
create_datetime = datetime.datetime(2011, 1, 1)
for slot in slots:
coupon = slot.slot_time_frames.all()[0].coupon
coupon.coupon_create_datetime = create_datetime
coupon.save()
coupons.append(coupon)
create_datetime += datetime.timedelta(days=30)
self.coupon_1, self.coupon_2, self.coupon_3 = coupons
self.coupon_ids = [coupon.id for coupon in coupons]
self.coupons = Coupon.objects.filter(id__in=self.coupon_ids)
for coupon in self.coupons:
rank_date_time, created = RankDateTime.objects.get_or_create(
coupon=coupon)
if not created:
rank_date_time.save()
示例11: test_process_city
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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)
示例12: test_process_county
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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)
示例13: test_create_flyers_phase2
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [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())
示例14: test_create_flyers_this_week
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def test_create_flyers_this_week(self):
""" Test the flyer creation process.
This test sets up case where we have a new ordered coupon this week for
site 2. Test is time sensitive, so we fix times during the test.
Assert a new flyer is created, with a paid coupon.
Assert that, when it is sent, its order_item is updated.
"""
try:
content_type = ContentType.objects.get(
app_label='coupon', model='slot')
except CouponType.DoesNotExist:
content_type = ContentType.objects.create(
app_label='coupon', model='slot')
send_date = datetime.date(2011, 11, 3)
slots = SLOT_FACTORY.create_slots(create_count=5)
coupons = SLOT_FACTORY.prepare_slot_coupons_for_flyer(slots, send_date)
# A slot ending this week:
slots[0].end_date = datetime.date.today() + datetime.timedelta(days=1)
slots[0].save()
# A paid flyer placement.
billing_record = BillingRecord.objects.create(
business=slots[1].business)
order = Order.objects.create(billing_record=billing_record)
order_item = OrderItem.objects.create(
site_id=2,
business=slots[1].business,
order=order,
product_id=1,
start_datetime=datetime.datetime.now() - datetime.timedelta(days=1),
end_datetime=datetime.datetime.now() + datetime.timedelta(weeks=1),
item_id=slots[1].id,
content_type=content_type)
# Media Partner
# Media partner coupon will only be included if it was created after the
# most current flyer for this site.
coupons[2].coupon_type_id = 5
coupons[2].save()
# A Media partner coupon must have a zip in this market.
location = BUSINESS_LOCATION_FACTORY.create_business_location(
coupons[2].offer.business)
location.location_zip_postal = '12550'
location.save()
coupons[2].location.add(location)
# National
coupons[3].coupon_type_id = 6
coupons[3].save()
flyers_count = Flyer.objects.count()
LOG.debug('flyer count before: %s' % flyers_count)
# Site needs consumers or no flyers are created.
CONSUMER_FACTORY.create_consumer()
create_flyers_this_week(send_date=send_date, test_mode=True)
# The actual number here will depend on how many sites in initial_data:
LOG.debug('flyer count after: %s' % Flyer.objects.count())
self.assertTrue(Flyer.objects.count() > flyers_count)
for coupon_id, flavor in (
(coupons[0].id, 'slot ending'),
(coupons[1].id, 'paid'),
(coupons[2].id, 'media partner'),
(coupons[3].id, 'national'),
(coupons[4].id, 'never in a flyer before')):
try:
flyer = Flyer.objects.filter(site=2,
flyer_coupons__coupon__id=coupon_id).latest('id')
except Flyer.DoesNotExist:
self.fail('Failed to include this %s coupon.' % flavor)
flyer.is_approved = True
flyer.save()
# Flyer needs eligible recipient.
consumer = Consumer(email='[email protected]',
site_id=2, is_emailable=True)
consumer.save()
consumer.email_subscription.add(1)
send_flyer(flyer)
order_item = OrderItem.objects.get(id=order_item.id)
self.assertEqual(order_item.content_type,
ContentType.objects.get(app_label='coupon', model='flyercoupon'))
self.assertEqual(order_item.item_id,
FlyerCoupon.objects.get(flyer=flyer, coupon=coupons[1]).id)
示例15: test_process_auto_renew_slots
# 需要导入模块: from coupon.factories.slot_factory import SLOT_FACTORY [as 别名]
# 或者: from coupon.factories.slot_factory.SLOT_FACTORY import create_slots [as 别名]
def test_process_auto_renew_slots(self):
""" Assert slots are auto-renewed creating payments and extending end
date.
"""
today = datetime.date.today()
slots = SLOT_FACTORY.create_slots(create_count=5)
for index, slot in enumerate(slots):
slot.start_date = datetime.date(2011, 1, 1)
slot.end_date = today
slot.save()
credit_card = self.create_credit_card(slot)
if index == 1:
ad_rep = AD_REP_FACTORY.create_ad_rep()
AdRepAdvertiser.objects.create(ad_rep=ad_rep,
advertiser=slot.business.advertiser)
if index != 3:
billing_record = BillingRecord.objects.create(
business=slot.business)
if index == 0:
credit_card_0 = credit_card
billing_record_0 = billing_record
if index != 4:
slot.is_autorenew = True
slot.save()
old_payment_count = Payment.objects.count()
task = AutoRenewSlotsTask()
task.test_mode = True
task.run(test_recipients=['[email protected]'])
new_payment_count = Payment.objects.count()
self.assertTrue(new_payment_count > old_payment_count)
# A good renewal; get updated slot end_date:
slot = Slot.objects.get(id=slots[0].id)
try:
order = Order.objects.get(billing_record=billing_record_0)
except Order.DoesNotExist:
self.fail('No payment for a valid auto-renewal')
self.assertEqual(order.total, slot.renewal_rate)
try:
payment = Payment.objects.get(order__id=order.id)
except Payment.DoesNotExist:
self.fail('No payment for a valid auto-renewal')
self.assertEqual(payment.amount, slot.renewal_rate)
self.assertEqual(payment.status, 'A')
self.assertEqual(payment.credit_card, credit_card_0)
try:
order_item = order.order_items.all()[0]
except IndexError:
self.fail('Order has no order items.')
self.assertEqual(order_item.product.id, 2)
self.assertEqual(order_item.ordered_object, slot)
self.assertEqual(order_item.amount, slot.renewal_rate)
self.assertEqual(order_item.end_datetime, datetime.datetime.combine(
slot.end_date, datetime.time()))
self.assertTrue(slot.end_date > today)
self.assertTrue(Slot.objects.get(id=slots[1].id).end_date > today)
self.assertTrue(Slot.objects.get(id=slots[2].id).end_date > today)
# No renewal because business has no billing record:
self.assertEqual(Slot.objects.get(id=slots[3].id).end_date, today)
# No renewal because is_autorenew is False:
self.assertEqual(Slot.objects.get(id=slots[4].id).end_date, today)
for email in mail.outbox:
self.assertNotEqual(email.subject, 'Auto-renew not approved')
self.assertTrue(ad_rep.first_name in mail.outbox[0].alternatives[0][0])