本文整理汇总了Python中coupon.factories.slot_factory.SLOT_FACTORY类的典型用法代码示例。如果您正苦于以下问题:Python SLOT_FACTORY类的具体用法?Python SLOT_FACTORY怎么用?Python SLOT_FACTORY使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SLOT_FACTORY类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_business_preference
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)
示例2: test_create_flyers_for_city
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)
示例3: test_send_flyers_this_week
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)
示例4: test_get_current_coupons
def test_get_current_coupons(self):
""" Assert coupon in slot is selected. """
SLOT_FACTORY.create_slot()
# If *any* tests have loaded fixtures with current coupons, this count
# will be higher than 1.
initial_count = Coupon.current_coupons.count()
self.assertTrue(initial_count > 0)
SLOT_FACTORY.create_slot()
self.assertEqual(Coupon.current_coupons.count(), initial_count + 1)
示例5: setUp
def setUp(self):
super(TestShowAllCouponsThisBiz, self).setUp()
self.slot_list = SLOT_FACTORY.create_slot_family(create_count=3)[1]
self.coupon_list = SLOT_FACTORY.get_active_coupons(
slot_list=self.slot_list)
self.coupon0 = self.coupon_list[0]
self.business = self.coupon0.offer.business
self.consumer = self.business.advertiser.consumer
self.request_data = None
self.response = None
示例6: setUp
def setUp(self):
""" Set a coupon in a slot. """
super(TestBusinessService, self).setUp()
self.coupon = COUPON_FACTORY.create_coupon(create_location=False)
SLOT_FACTORY.create_slot(coupon=self.coupon,
create_slot_time_frame=True)
self.business = self.coupon.offer.business
BusinessProfileDescription.objects.create(business=self.business,
business_description='The best profile description evah.')
self.advertiser = self.business.advertiser
示例7: setUp
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
示例8: setUpClass
def setUpClass(cls):
""" Set up coupons to be retrieved for the following tests. """
super(TestCouponPerformance, cls).setUpClass()
coupon = COUPON_FACTORY.create_coupon()
expiring_coupon = COUPON_FACTORY.create_coupon()
expiring_coupon.expiration_date = (
datetime.date.today() + datetime.timedelta(1))
expiring_coupon.save()
coupon_w_locations = COUPON_FACTORY.create_coupons_many_locations()[0]
second_coupon_this_biz = COUPON_FACTORY.create_coupon()
offer = second_coupon_this_biz.offer
offer.business = expiring_coupon.offer.business
offer.save()
SLOT_FACTORY.create_slot(coupon=coupon)
SLOT_FACTORY.create_slot(coupon=expiring_coupon)
SLOT_FACTORY.create_slot(coupon=coupon_w_locations)
SLOT_FACTORY.create_slot(coupon=second_coupon_this_biz)
# Move coupon to share advertiser with second_coupon_this_biz.
business = coupon.offer.business
business.advertiser = second_coupon_this_biz.offer.business.advertiser
business.save()
# Relate all of these businesses except one to these coupons advertisers.
cls.ad_rep = AD_REP_FACTORY.create_ad_rep()
AdRepAdvertiser.objects.create(ad_rep=cls.ad_rep,
advertiser=expiring_coupon.offer.business.advertiser)
AdRepAdvertiser.objects.create(ad_rep=cls.ad_rep,
advertiser=coupon_w_locations.offer.business.advertiser)
# Set vars for testing:
cls.advertiser_not_related = coupon.offer.business.advertiser
cls.expiring_coupon = expiring_coupon
cls.coupon_w_locations = coupon_w_locations
cls.business_w_2_coupons = second_coupon_this_biz
示例9: test_view_single_coupon
def test_view_single_coupon(self):
""" Assert a valid coupon displays correctly with a consumer in session.
"""
slot = SLOT_FACTORY.create_slot()
coupon = slot.slot_time_frames.latest('id').coupon
coupon.is_valid_thursday = False
coupon.save()
coupon.default_restrictions.add(3)
business = coupon.offer.business
consumer = CONSUMER_FACTORY.create_consumer(subscription_list=False)
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
self.assertEqual(coupon.consumer_actions.filter(action=2).count(), 0)
response = self.client.get(reverse('view-single-coupon',
kwargs={'slug': coupon.slug(), 'coupon_id': coupon.id}))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'coupon/display_single_coupon.html')
self.assertTemplateUsed(response, 'include/dsp/dsp_single_coupon.html')
self.assertContains(response, '<meta name="robots" content="noydir">')
self.assertContains(response, '<meta name="robots" content="noodp">')
self.assertContains(response, '<a class="button largeBtn" ' +
'href="/hudson-valley/coupon/%s/" rel="nofollow">' % coupon.id)
self.assertContains(response,
'href="/hudson-valley/"><div >HudsonValley</div>')
self.assertContains(response,
'href="/hudson-valley/coupons/%s/%s/">%s' % (
business.slug(), business.id, business.business_name))
self.assertContains(response, 'class="business_name">%s' %
business.business_name)
self.assertContains(response, 'class="headline">%s' %
coupon.offer.headline)
self.assertContains(response,
'<h4 class="qualifier">\n %s\n' %
coupon.offer.qualifier)
self.assertContains(response, 'Tax and Gratuity Not Included.')
self.assertContains(response,
'No cash value. Not valid in combination with other offers.')
self.assertContains(response, 'Coupon void if altered.')
self.assertContains(response,
'class="valid_days">Offer not valid Thursdays.')
self.assertContains(response,
'class="redemption_window">Valid through %s' %
frmt_expiration_date_for_dsp(coupon.expiration_date))
self.assertNotContains(response, 'Send this coupon to your inbox.')
self.assertNotContains(response, 'Send My Coupon')
# Assumes contest is running:
self.assertContains(response, '%s%s' % ('Create a coupon like',
' this for YOUR business'))
# Check for consumer action recorded for this coupon
self.assertEqual(coupon.consumer_actions.filter(action=2).count(), 1)
# Check for facebook meta for like button.
self.assertTemplateUsed(response, 'include/dsp/dsp_facebook_meta.html')
self.assertContains(response,
'meta property="og:url" content="%s/hudson-valley/coupon-%s/%s/"' %
(settings.HTTP_PROTOCOL_HOST, coupon.slug(), coupon.id))
self.assertTemplateUsed(response,
'include/dsp/dsp_facebook_like_small.html')
self.assertContains(response,
'fb:like href="%s/hudson-valley/coupon-%s/%s/"' %
(settings.HTTP_PROTOCOL_HOST, coupon.slug(), coupon.id))
示例10: test_no_auto_renew
def test_no_auto_renew(self):
""" Asserts a slot with auto-renew False does not renew. """
slot = SLOT_FACTORY.create_slot()
task = AutoRenewSlotsTask()
task.test_mode = True
with self.assertRaises(ValidationError):
task.process_slot_payment(slot)
示例11: setUp
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)
示例12: test_external_click_coupon
def test_external_click_coupon(self):
""" Assert external click action gets incremented. """
slot = SLOT_FACTORY.create_slot()
coupon = slot.slot_time_frames.latest('id').coupon
coupon.precise_url = 'http://cnn.com'
coupon.save()
consumer = CONSUMER_FACTORY.create_consumer()
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
try:
before_clicks = CouponAction.objects.get(
action__id=8, coupon=coupon).count
except CouponAction.DoesNotExist:
before_clicks = 0
response = self.client.get(reverse('external-click-coupon',
kwargs={'coupon_id': coupon.id}))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['location'], coupon.precise_url)
self.assertEqual(CouponAction.objects.get(
action__id=8, coupon=coupon).count, before_clicks + 1)
try:
ConsumerAction.objects.get(
action__id=8, coupon=coupon, consumer=consumer)
except ConsumerAction.DoesNotExist:
self.fail('ConsumerAction not recorded.')
示例13: test_family_first
def test_family_first(self):
""" Assert a business related to two slot families, the first having an
available child and the second having an available parent slot,
the first family is filled first.
"""
slot_family_1 = SLOT_FACTORY.create_slot_family(create_count=2)
LOG.debug('slot_family_1: %s' % str(slot_family_1))
# New slot for that same business:
slot = SLOT_FACTORY.create_slot(create_slot_time_frame=False)
slot.business = slot_family_1[0]['parent'].business
slot.save()
family_availability_dict = check_available_family_slot(slot.business.id)
coupon = COUPON_FACTORY.create_coupon()
new_slot = publish_business_coupon(family_availability_dict, coupon)
LOG.debug('family_availability_dict: %s' % family_availability_dict)
self.assertEqual(new_slot.parent_slot, slot_family_1[0]['parent'])
示例14: test_get_active_coupon_bad
def test_get_active_coupon_bad(self):
""" Assert a slot with an expired coupon returns None. """
coupon = COUPON_FACTORY.create_coupon()
slot = SLOT_FACTORY.create_slot(coupon=coupon)
coupon.expiration_date = (datetime.date.today() -
datetime.timedelta(weeks=1))
coupon.save()
self.assertEqual(slot.get_active_coupon(), None)
示例15: test_show_sample_flyer
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)