Applying camel case and fixing query used to get the active membership

pull/79/head
Matheus Lima 2019-03-14 20:26:16 -03:00
parent a367c1d07c
commit 9f75bf93c4
4 changed files with 28 additions and 23 deletions

View File

@ -27,19 +27,15 @@ free_membership = {
}
monthly_membership = {
'support': {
'membership': 'Monthly Membership',
'payment_method': 'Stripe',
'payment_token': 'tok_visa'
}
'membership': 'Monthly Membership',
'paymentMethod': 'Stripe',
'paymentToken': 'tok_visa'
}
yearly_membership = {
'support': {
'membership': 'Yearly Membership',
'payment_method': 'Stripe',
'payment_token': 'tok_visa'
}
'membership': 'Yearly Membership',
'payment_method': 'Stripe',
'payment_token': 'tok_visa'
}
@ -61,7 +57,7 @@ def create_account_free_account(context):
def update_membership(context):
context.client.patch(
'/api/account',
data=json.dumps(monthly_membership),
data=json.dumps({'support': monthly_membership}),
content_type='application_json'
)
@ -75,13 +71,17 @@ def request_account(context):
@then('the account should have a monthly membership')
def monthly_account(context):
account = context.response_account
assert_that(account.membership.type, equal_to(monthly_membership['support']['membership']))
assert_that(account.membership.type, equal_to(monthly_membership['membership']))
assert_that(account.membership.payment_account_id, starts_with('cus'))
@given('a user with a monthly membership')
def create_monthly_account(context):
new_account_request['membership'] = monthly_membership
new_account_request['support'].update(
membership=monthly_membership['membership'],
paymentMethod=monthly_membership['paymentMethod'],
paymentToken=monthly_membership['paymentToken']
)
context.client.post(
'/api/account',
data=json.dumps(new_account_request),
@ -113,7 +113,7 @@ def free_account(context):
def change_to_yearly_account(context):
context.client.patch(
'/api/account',
data=json.dumps(yearly_membership),
data=json.dumps({'support': {'membership': yearly_membership['membership']}}),
content_type='application_json'
)
@ -121,5 +121,5 @@ def change_to_yearly_account(context):
@then('the account should have a yearly membership')
def yearly_account(context):
account = context.response_account
assert_that(account.membership.type, equal_to(yearly_membership['support']['membership']))
assert_that(account.membership.type, equal_to(yearly_membership['membership']))
assert_that(account.membership.payment_account_id, starts_with('cus'))

View File

@ -67,8 +67,8 @@ class AddMembership(Model):
required=True,
choices=(MONTHLY_MEMBERSHIP, YEARLY_MEMBERSHIP)
)
payment_method = StringType(required=True, choices=[STRIPE_PAYMENT])
payment_token = StringType(required=True)
paymentMethod = StringType(required=True, choices=[STRIPE_PAYMENT])
paymentToken = StringType(required=True)
class UpdateMembership(Model):
@ -250,7 +250,7 @@ class AccountEndpoint(SeleneEndpoint):
membership_repository = MembershipRepository(db)
active_membership = membership_repository.get_active_membership_by_account_id(self.account.id)
if active_membership:
active_membership.end_date = datetime.now()
active_membership.end_date = datetime.utcnow()
# TODO: use the subscription id to delete the membership on stripe
membership_repository.finish_membership(active_membership)
add_membership = UpdateMembership(self.request_data.get('support'))
@ -269,7 +269,7 @@ class AccountEndpoint(SeleneEndpoint):
add_membership.validate()
support = self.request_data['support']
membership_type = support['membership']
token = support['payment_token']
token = support['paymentToken']
membership = self._get_plan(membership_type)
stripe_id, start_date = self._create_stripe_subscription(
None,

View File

@ -19,7 +19,6 @@ class AccountMembership(object):
payment_method: str
payment_account_id: str
id: str = None
account_id: str = None
end_date: date = None

View File

@ -1,6 +1,12 @@
SELECT
*
acc_mem.id,
mem.type,
LOWER(acc_mem.membership_ts_range) start_date,
acc_mem.payment_method,
payment_account_id
FROM
account.account_membership
account.account_membership acc_mem
INNER JOIN
account.membership mem ON acc_mem.membership_id = mem.id
WHERE
account_id = %(account_id)s and membership_ts_range @> '[now,)'
account_id = %(account_id)s AND UPPER(acc_mem.membership_ts_range) IS NULL