本文整理匯總了Python中consumer.factories.consumer_factory.CONSUMER_FACTORY類的典型用法代碼示例。如果您正苦於以下問題:Python CONSUMER_FACTORY類的具體用法?Python CONSUMER_FACTORY怎麽用?Python CONSUMER_FACTORY使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CONSUMER_FACTORY類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_valid_ad_rep
def test_valid_ad_rep(self):
""" Assert view displays downline consumer and qualified consumer counts
for each.
"""
child_ad_rep1, parent_ad_rep = AD_REP_FACTORY.create_generations(
create_count=2)
child_ad_rep2 = AD_REP_FACTORY.create_ad_rep()
child_ad_rep2.parent_ad_rep = parent_ad_rep
child_ad_rep2.save()
consumers = CONSUMER_FACTORY.create_consumers(create_count=3)
for consumer in consumers:
CONSUMER_FACTORY.qualify_consumer(consumer)
AdRepConsumer.objects.create(consumer=consumers[0],
ad_rep=child_ad_rep1)
AdRepConsumer.objects.create(consumer=consumers[1],
ad_rep=child_ad_rep2)
AdRepConsumer.objects.create(consumer=consumers[2],
ad_rep=child_ad_rep2)
self.client.login(username='super', password='secret')
response = self.client.get(reverse('admin-downline-consumers',
kwargs={'ad_rep_id': parent_ad_rep.id}))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Recruitment Activity for %s %s' %
(parent_ad_rep.first_name, parent_ad_rep.last_name))
self.assertContains(response, 'Customers')
self.assertContains(response, '%s %s' %
(child_ad_rep1.first_name, child_ad_rep1.last_name))
self.assertContains(response,
"Click a name to view that Advertising Representative's")
self.assertTrue(response.content.count('>1</strong>'), 2)
# Output is sorted by consumer count;, child_ad_rep2 comes first.
self.assertTrue(response.content.index(child_ad_rep2.first_name) <
response.content.index(child_ad_rep1.first_name))
# Only market managers (rank) get this text:
self.assertNotContains(response, 'commission is paid to you')
示例2: 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)
示例3: test_delete_subscriber
def test_delete_subscriber(self):
""" Delete a subscriber that has a consumer and assert the consumer is
not dropped.
"""
consumer = CONSUMER_FACTORY.create_consumer()
CONSUMER_FACTORY.qualify_consumer(consumer)
mobile_phone = consumer.subscriber.mobile_phones.all()[0]
consumer.subscriber.delete()
with self.assertRaises(MobilePhone.DoesNotExist):
MobilePhone.objects.get(id=mobile_phone.id)
try:
consumer = Consumer.objects.get(id=consumer.id)
except Consumer.DoesNotExist:
self.fail('Retain Consumer when subscriber is deleted!')
self.assertEqual(consumer.subscriber, None)
示例4: test_downline_recruits
def test_downline_recruits(self):
""" Assert recruits and their referred customer counts display. """
ad_rep_list = AD_REP_FACTORY.create_ad_reps(create_count=3)
parent_ad_rep = ad_rep_list[0]
child_ad_rep_1 = ad_rep_list[1]
child_ad_rep_2 = ad_rep_list[2]
child_ad_rep_1.parent_ad_rep = parent_ad_rep
child_ad_rep_1.save()
child_ad_rep_2.parent_ad_rep = parent_ad_rep
child_ad_rep_2.save()
consumer = CONSUMER_FACTORY.create_consumer()
AdRepConsumer.objects.create(ad_rep=child_ad_rep_1, consumer=consumer)
self.session['ad_rep_id'] = parent_ad_rep.id
self.login(email=parent_ad_rep.email)
self.assemble_session(self.session)
response = self.client.get(reverse('ad-rep-downline-recruits'))
self.assertEqual(response.request['PATH_INFO'],
'/hudson-valley/ad-rep/downline-recruits/')
self.assertContains(response,
'Click a name to display contact information')
self.assertContains(response, '%s %s' % (child_ad_rep_1.first_name,
child_ad_rep_1.last_name))
self.assertContains(response, '%s %s' % (child_ad_rep_2.first_name,
child_ad_rep_2.last_name))
self.assertContains(response, '<strong>1</strong>')
示例5: test_get_subscriber_in_session
def test_get_subscriber_in_session(self):
""" Assert GET with subscriber in session pre-fills the form. """
consumer = CONSUMER_FACTORY.create_consumer()
CONSUMER_FACTORY.qualify_consumer(consumer)
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
LOG.debug("session = %s" % self.session)
slot = SLOT_FACTORY.create_slot()
coupon = slot.slot_time_frames.latest('id').coupon
response = self.client.get(reverse('show-send-sms-single-coupon',
kwargs = {'coupon_id':coupon.id}))
LOG.debug("response: %s" % response.content)
self.assertContains(response, 'value="%s"' %
consumer.subscriber.mobile_phones.latest('id').mobile_phone_number)
self.assertContains(response,
'<option value="2" selected="selected">AT&T</option>')
示例6: 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))
示例7: 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.')
示例8: test_subscriber_reg_with_con
def test_subscriber_reg_with_con(self):
""" Post to registration form with valid data, with a consumer already
in session.
"""
consumer = CONSUMER_FACTORY.create_consumer()
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
post_data = {'mobile_phone_number': '9145550001',
'subscriber_zip_postal': '12550', 'carrier': '2'}
response = self.client.post(reverse('subscriber-registration'),
post_data, follow=True)
# Redirects to local site.
self.assertEqual(response.redirect_chain[0][0], '%s%s' % (
settings.HTTP_PROTOCOL_HOST,
reverse('subscriber-registration-confirmation',
urlconf='urls_local.urls_2')
))
self.assertEqual(response.redirect_chain[0][1], 302)
self.assertContains(response,
'A text message was sent to <strong>(914) 555-0001</strong>')
consumer = Consumer.objects.get(id=consumer.id)
try:
subscriber = Subscriber.objects.get(
mobile_phones__mobile_phone_number='9145550001')
except Subscriber.MultipleObjectsReturned:
self.fail("We created more than one subscriber.")
except Subscriber.DoesNotExist:
self.fail("We did create not a subscriber.")
self.assertEqual(subscriber.site_id, 2)
self.assertEqual(consumer.subscriber, subscriber)
sms_message_sent = SMSMessageSent.objects.latest('id')
self.assertEqual(sms_message_sent.smsto, '9145550001')
self.assertEqual(sms_message_sent.smsmsg[:50],
"10Coupons Alrts: Reply YES to get text coupons (4m")
示例9: test_create_relate_ad_rep
def test_create_relate_ad_rep(self):
""" Assert an ad_rep is created and related to an advertiser, an order,
and a consumer.
"""
email = '[email protected]'
ad_rep = AdRep.objects.create(username=email, email=email,
firestorm_id=100)
self.assertFalse(ad_rep.advertisers().count())
self.assertFalse(ad_rep.orders().count())
self.assertFalse(ad_rep.consumers().count())
# Select an advertiser who may or may not have an ad_rep:
advertiser = ADVERTISER_FACTORY.create_advertiser()
try:
AdRepAdvertiser.objects.create(ad_rep=ad_rep, advertiser=advertiser)
except IntegrityError: # This advertiser already has a rep; change reps.
advertiser.ad_rep_advertiser.ad_rep = ad_rep
advertiser.ad_rep_advertiser.save()
self.assertTrue(ad_rep.advertisers().count())
# Advertisers are a subclassed from Consumer, but relating an advertiser
# to this ad_rep does *not* add the base consumer, too.
self.assertFalse(ad_rep.consumers().count())
order = ORDER_FACTORY.create_order()
AdRepOrder.objects.create(ad_rep=ad_rep, order=order)
self.assertTrue(ad_rep.orders().count())
# Select a consumer who does not have an ad_rep:
consumer = CONSUMER_FACTORY.create_consumer()
AdRepConsumer.objects.create(ad_rep=ad_rep, consumer=consumer)
self.assertTrue(ad_rep.consumers().count())
示例10: test_con_sub_reg_confirmation
def test_con_sub_reg_confirmation(self):
""" Assert consumer + subscriber registration success confirmation page
displays correctly if is_email_verified is not set in session.
"""
consumer = CONSUMER_FACTORY.create_consumer()
CONSUMER_FACTORY.qualify_consumer(consumer)
create_consumer_in_session(self, consumer)
# Remove is_email_verified from session.
del self.session['consumer']['is_email_verified']
self.assemble_session(self.session)
response = self.client.post(reverse('con-sub-reg-confirmation'))
self.assertTemplateUsed(response,
'registration/display_con_sub_reg_confirmation.html')
self.assertTemplateUsed(response,
'include/dsp/dsp_subscriber_registration_confirmation.html')
self.assertTemplateUsed(response,
'include/dsp/dsp_con_sub_reg_confirmation.html')
示例11: test_home_with_subscriber
def test_home_with_subscriber(self):
""" Assert xfbml for facebook like appears for subscriber on home page.
"""
consumer = CONSUMER_FACTORY.create_consumer()
CONSUMER_FACTORY.qualify_consumer(consumer)
mobile_phone = consumer.subscriber.mobile_phones.all()[0]
mobile_phone.is_verified = False
mobile_phone.save()
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
response = self.client.get(reverse('all-coupons'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request['PATH_INFO'],
'/hudson-valley/coupons/')
self.assertTemplateUsed(response, 'coupon/display_all_coupons.html')
self.assertTemplateUsed(response, 'include/dsp/dsp_share_site.html')
# Assumes contest is running:
self.assertContains(response, 'load_like_contest_not_qualified')
示例12: test_show_on_site_1_w_session
def test_show_on_site_1_w_session(self):
""" Assert view when hit /coupons/ on site 1 with session. """
consumer = CONSUMER_FACTORY.create_consumer()
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
response = self.client.get('/coupons/')
self.assertEqual(response.status_code, 302)
self.assertEqual(urlparse.urlparse(response['location']).path,
'/hudson-valley/coupons/')
示例13: test_consumer_case_mismatch
def test_consumer_case_mismatch(self):
""" Assert case is ignored when checking for preexisting consumer. """
consumer = CONSUMER_FACTORY.create_consumer()
ad_rep_dict = {'email': consumer.email.upper(), 'firestorm_id': 13,
'url': 'upper-cased'}
for field in self.ad_rep_repl_website_fields:
ad_rep_dict[field] = ''
CREATE_OR_UPDATE_AD_REP.run(ad_rep_dict)
self.assertTrue(AdRep.objects.filter(email=consumer.email).count())
示例14: test_reenter_off_site_zip
def test_reenter_off_site_zip(self):
""" Assert a consumer in session posts a phone number registered to
another consumer on the all coupons page.
"""
consumer = CONSUMER_FACTORY.create_consumer()
create_consumer_in_session(self, consumer)
subscriber = SUBSCRIBER_FACTORY.create_subscriber()
consumer_2 = CONSUMER_FACTORY.create_consumer()
consumer_2.subscriber = subscriber
consumer_2.save()
mobile_phone_number = subscriber.mobile_phones.all(
)[0].mobile_phone_number
self.assemble_session(self.session)
post_data = {'mobile_phone_number': mobile_phone_number,
'subscriber_zip_postal': '12550', 'carrier': '5'}
response = self.client.post(reverse('all-coupons'), post_data)
self.assertTemplateUsed(response, 'coupon/display_all_coupons.html')
self.assertTemplateUsed(response,
'include/dsp/dsp_pricing_unlocked.html')
示例15: test_get_coupons_sub_form
def test_get_coupons_sub_form(self):
""" Assert all coupons with consumer in session loads subscriber form
and contest text is not suppressed.
"""
consumer = CONSUMER_FACTORY.create_consumer()
create_consumer_in_session(self, consumer)
self.assemble_session(self.session)
response = self.client.get(reverse('all-coupons'))
self.assertTemplateUsed(response, 'coupon/display_all_coupons.html')
self.assertContains(response, 'Win $10,000!*')