Fixing tests after rebase

pull/57/head
Matheus Lima 2019-03-02 20:08:50 -03:00
parent d599fb9540
commit a90833f178
6 changed files with 19 additions and 19 deletions

View File

@ -13,8 +13,8 @@ class DeviceSubscriptionEndpoint(SeleneEndpoint):
with get_db_connection(self.config['DB_CONNECTION_POOL']) as db: with get_db_connection(self.config['DB_CONNECTION_POOL']) as db:
account = AccountRepository(db).get_account_by_device_id(device_id) account = AccountRepository(db).get_account_by_device_id(device_id)
if account: if account:
subscription = account.subscription membership = account.membership
response = {'@type': subscription.type if subscription is not None else 'free'}, HTTPStatus.OK response = {'@type': membership.type if membership is not None else 'free'}, HTTPStatus.OK
else: else:
response = '', HTTPStatus.NO_CONTENT response = '', HTTPStatus.NO_CONTENT
return response return response

View File

@ -24,7 +24,7 @@ account = Account(
AccountAgreement(type=PRIVACY_POLICY, accept_date=date.today()), AccountAgreement(type=PRIVACY_POLICY, accept_date=date.today()),
AccountAgreement(type=TERMS_OF_USE, accept_date=date.today()) AccountAgreement(type=TERMS_OF_USE, accept_date=date.today())
], ],
subscription=None membership=None
) )
wake_word = WakeWord( wake_word = WakeWord(

View File

@ -6,7 +6,7 @@ from http import HTTPStatus
from behave import when, then from behave import when, then
from hamcrest import assert_that, has_entry, equal_to from hamcrest import assert_that, has_entry, equal_to
from selene.data.account import AccountRepository, AccountSubscription from selene.data.account import AccountRepository, AccountMembership
from selene.util.db import get_db_connection from selene.util.db import get_db_connection
@ -25,9 +25,9 @@ def validate_response(context):
@when('the subscription endpoint is called for a monthly account') @when('the subscription endpoint is called for a monthly account')
def get_device_subscription(context): def get_device_subscription(context):
membership = AccountSubscription(start_date=date.today(), type='Monthly Supporter', stripe_customer_id='test_monthly') membership = AccountMembership(start_date=date.today(), type='Monthly Supporter', stripe_customer_id='test_monthly')
with get_db_connection(context.client_config['DB_CONNECTION_POOL']) as db: with get_db_connection(context.client_config['DB_CONNECTION_POOL']) as db:
AccountRepository(db).add_membership(context.account.id, membership) AccountRepository(db)._add_membership(context.account.id, membership)
context.subscription_response = context.client.get('/device/{uuid}/subscription'.format(uuid=context.device_id)) context.subscription_response = context.client.get('/device/{uuid}/subscription'.format(uuid=context.device_id))

View File

@ -146,7 +146,8 @@ for schema in SCHEMAS:
template_db.close_db() template_db.close_db()
print('Copying template to new database.') print('Copying template to new database.')
postgres_db = PostgresDB(dbname='postgres', user='chrisveilleux') # Copy template to new database.
postgres_db = PostgresDB(dbname='postgres', user='postgres')
postgres_db.execute_sql(get_sql_from_file('create_mycroft_db.sql')) postgres_db.execute_sql(get_sql_from_file('create_mycroft_db.sql'))
postgres_db.close_db() postgres_db.close_db()

View File

@ -446,7 +446,7 @@ end = time.time()
print('Time to load CSVs {}'.format(end - start)) print('Time to load CSVs {}'.format(end - start))
print('Importing the skills table') print('Importing the skills table')
"""
start = time.time() start = time.time()
print('Importing account table') print('Importing account table')
fill_account_table() fill_account_table()
@ -463,6 +463,5 @@ fill_device_category_table()
print('Importing device table') print('Importing device table')
fill_device_table() fill_device_table()
fill_skills_table() fill_skills_table()
"""
end = time.time() end = time.time()
print('Time to import: {}'.format(end-start)) print('Time to import: {}'.format(end-start))

View File

@ -31,32 +31,32 @@ WITH
WHERE WHERE
dev.id = %(device_id)s dev.id = %(device_id)s
), ),
subscription AS ( membership AS (
SELECT SELECT
json_build_object( json_build_object(
'id', asub.id, 'id', acc_mem.id,
'type', s.subscription, 'type', mem.type,
'start_date', lower(asub.subscription_ts_range)::DATE, 'start_date', lower(acc_mem.membership_ts_range)::DATE,
'stripe_customer_id', asub.stripe_customer_id 'stripe_customer_id', acc_mem.stripe_customer_id
) )
FROM FROM
account.account_subscription asub account.account_membership acc_mem
INNER JOIN INNER JOIN
account.subscription s ON asub.subscription_id = s.id account.membership mem ON acc_mem.membership_id = mem.id
INNER JOIN INNER JOIN
account.account acc ON asub.account_id = acc.id account.account acc ON acc_mem.account_id = acc.id
INNER JOIN INNER JOIN
device.device dev ON acc.id = dev.account_id device.device dev ON acc.id = dev.account_id
WHERE WHERE
dev.id = %(device_id)s dev.id = %(device_id)s
AND upper(asub.subscription_ts_range) IS NULL AND upper(acc_mem.membership_ts_range) IS NULL
) )
SELECT SELECT
json_build_object( json_build_object(
'id', acc.id, 'id', acc.id,
'email_address', acc.email_address, 'email_address', acc.email_address,
'username', acc.username, 'username', acc.username,
'subscription', (SELECT * FROM subscription), 'membership', (SELECT * FROM membership),
'refresh_tokens', (SELECT * FROM refresh_tokens), 'refresh_tokens', (SELECT * FROM refresh_tokens),
'agreements', (SELECT * FROM agreements) 'agreements', (SELECT * FROM agreements)
) as account ) as account