Skip to content

Commit

Permalink
fix tests: override STRETCH_CACHE_MISS_TOTAL
Browse files Browse the repository at this point in the history
  • Loading branch information
brad committed Jul 6, 2014
1 parent e57c47d commit 0206bfc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
49 changes: 25 additions & 24 deletions backend/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get():
paypal_password = s.paypal_password
paypal_signature = s.paypal_signature
bitpay_api_key = s.bitpay_api_key

if 'productionPaypal' in j and j['productionPaypal']:
paypal_api_url = "https://api-3t.paypal.com/nvp"
paypal_url = "https://www.paypal.com/webscr"
Expand All @@ -100,7 +100,7 @@ def get():
paypal_signature = paypal_signature,
paypal_api_url = paypal_api_url,
paypal_url = paypal_url,
bitpay_api_key = bitpay_api_key
bitpay_api_key = bitpay_api_key
)
return Config._instance

Expand All @@ -127,9 +127,9 @@ class Secrets(db.Model):
paypal_user = db.StringProperty(default='')
paypal_password = db.StringProperty(default='')
paypal_signature = db.StringProperty(default='')

bitpay_api_key = db.StringProperty(default='')


@staticmethod
def get():
Expand Down Expand Up @@ -157,7 +157,7 @@ class User(db.Model):
city = db.StringProperty()
state = db.StringProperty()
zipCode = db.StringProperty()

# occupation and employer are logically required for all new users, but we
# don't have this data for everyone. so from a data model perspective, they
# aren't required.
Expand All @@ -173,7 +173,7 @@ class User(db.Model):

# the results of a survey from mayday.us/goodfight
surveyResult = db.StringProperty(required=False)

# this is the nonce for what we'll put in a url to send to people when we ask
# them to update their information. it's kind of like their password for the
# user-management part of the site.
Expand Down Expand Up @@ -206,7 +206,7 @@ def choose(current, new):
return current or new
else:
return new or current

user.first_name = choose(user.first_name, first_name)
user.last_name = choose(user.last_name, last_name)
user.occupation = choose(user.occupation, occupation)
Expand All @@ -215,8 +215,8 @@ def choose(current, new):
user.target = choose(user.target, target)
user.surveyResult = choose(user.surveyResult, surveyResult)
user.address = choose(user.address, address)
user.city = choose(user.city, city)
user.state = choose(user.state, state)
user.city = choose(user.city, city)
user.state = choose(user.state, state)
user.zipCode = choose(user.zipCode, zipCode)

user.mail_list_optin = choose(user.mail_list_optin, mail_list_optin)
Expand All @@ -235,15 +235,15 @@ class TempPledge(db.Model):
employer = db.StringProperty()
target = db.StringProperty()
subscribe = db.BooleanProperty(required=False, default=True)
amountCents = db.IntegerProperty(required=True)
amountCents = db.IntegerProperty(required=True)
firstName = db.StringProperty()
lastName = db.StringProperty()
address = db.StringProperty()
city = db.StringProperty()
state = db.StringProperty()
zipCode = db.StringProperty()
bitcoinConfirm=db.BooleanProperty(required=False, default=False)

team = db.StringProperty()
# all pledge_types for bitpay pledges must be "DONATION"
bitpay_invoice_id = db.StringProperty()
Expand All @@ -267,10 +267,10 @@ class Pledge(db.Model):
# Paypal specific fields
paypalPayerID = db.StringProperty()
paypalTransactionID = db.StringProperty()

#BitPay specific field
bitpay_invoice_id = db.StringProperty()

# when the donation occurred
donationTime = db.DateTimeProperty(auto_now_add=True)

Expand Down Expand Up @@ -393,8 +393,8 @@ def addPledge(email,
first_name, last_name, occupation, employer, phone,
target, team, mail_list_optin, anonymous, surveyResult=None,
stripe_customer_id=None, stripe_charge_id=None,
paypal_txn_id=None, paypal_payer_id=None,
address=None, city=None, state=None, zipCode=None,
paypal_txn_id=None, paypal_payer_id=None,
address=None, city=None, state=None, zipCode=None,
bitpay_invoice_id = None ):
"""Creates a User model if one doesn't exist, finding one if one already
does, using the email as a user key. Then adds a Pledge to the User with
Expand Down Expand Up @@ -556,7 +556,7 @@ def update(cls, newTotal):
else:
newTotalForDB = cls(dollars = newTotal)
newTotalForDB.put()

@classmethod
def get(cls):
total = cls.all().get()
Expand All @@ -565,9 +565,10 @@ def get(cls):
else:
logging.info('No StretchCheckTotal')
return 0

SHARD_KEY_TEMPLATE = 'shard-{}-{:d}'
SHARD_COUNT = 50
STRETCH_CACHE_MISS_TOTAL = 112742800

class ShardedCounter(db.Model):
count = db.IntegerProperty(default=0)
Expand All @@ -586,18 +587,18 @@ def get_count(name):
if counter is not None:
total += counter.count
logging.info("recalculated counter %s to %s", name, total)

# Add the stretch check total which is not reflected elsewhere in the counter
# And is set manually
# And is set manually
# This is here so that is only read out on a cache miss
stretchCheckTotal = StretchCheckTotal.get()
if stretchCheckTotal < 112742800:
stretchCheckTotal = 112742800
if stretchCheckTotal < STRETCH_CACHE_MISS_TOTAL:
stretchCheckTotal = STRETCH_CACHE_MISS_TOTAL

total += stretchCheckTotal

cache.SetShardedCounterTotal(name, total)

return total

@staticmethod
Expand Down
5 changes: 1 addition & 4 deletions unittests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def setUp(self):
handlers.TotalHandler.WP_PLEDGE_TOTAL = 11
handlers.TotalHandler.DEMOCRACY_DOT_COM_BALANCE = 12
handlers.TotalHandler.CHECKS_BALANCE = 13
handlers.TotalHandler.STRETCH_GOAL_MATCH = 14
model.STRETCH_CACHE_MISS_TOTAL = 14

self.balance_baseline = 60

Expand Down Expand Up @@ -508,6 +508,3 @@ def testBitpayNotifications(self):
'expirationTime': 1393950946292, 'id': 'aASDF2jh4ashkASDfh234'}
resp = self.app.post_json('/r/bitcoin_notifications', notification)
# import pdb; pdb.set_trace()



0 comments on commit 0206bfc

Please sign in to comment.