changed to use IDs in repository objects
parent
0d3313041e
commit
ec943dad50
|
@ -3,4 +3,4 @@ Feature: Get the active Profile Policy agreement
|
|||
|
||||
Scenario: Multiple versions of an agreement exist
|
||||
When API request for Privacy Policy is made
|
||||
Then version 1 of Privacy Policy is returned
|
||||
Then version 999 of Privacy Policy is returned
|
||||
|
|
|
@ -11,7 +11,8 @@ from selene.data.account import (
|
|||
AccountSubscription,
|
||||
Agreement,
|
||||
AgreementRepository,
|
||||
PRIVACY_POLICY
|
||||
PRIVACY_POLICY,
|
||||
TERMS_OF_USE
|
||||
)
|
||||
from selene.util.db import get_db_connection
|
||||
|
||||
|
@ -33,47 +34,57 @@ def before_feature(context, _):
|
|||
def before_scenario(context, _):
|
||||
|
||||
with get_db_connection(context.client_config['DB_CONNECTION_POOL']) as db:
|
||||
_add_agreement(context, db)
|
||||
_add_agreements(context, db)
|
||||
_add_account(context, db)
|
||||
|
||||
|
||||
def _add_agreement(context, db):
|
||||
context.agreement = Agreement(
|
||||
type='Privacy Policy',
|
||||
version='1',
|
||||
content='this is Privacy Policy version 1',
|
||||
def _add_agreements(context, db):
|
||||
context.privacy_policy = Agreement(
|
||||
type=PRIVACY_POLICY,
|
||||
version='999',
|
||||
content='this is Privacy Policy version 999',
|
||||
effective_date=date.today() - timedelta(days=5)
|
||||
)
|
||||
context.terms_of_use = Agreement(
|
||||
type=TERMS_OF_USE,
|
||||
version='999',
|
||||
content='this is Terms of Use version 999',
|
||||
effective_date=date.today() - timedelta(days=5)
|
||||
)
|
||||
agreement_repository = AgreementRepository(db)
|
||||
agreement_repository.add(context.agreement)
|
||||
agreement_id = agreement_repository.add(context.privacy_policy)
|
||||
context.privacy_policy.id = agreement_id
|
||||
agreement_id = agreement_repository.add(context.terms_of_use)
|
||||
context.terms_of_use.id = agreement_id
|
||||
|
||||
|
||||
def _add_account(context, db):
|
||||
test_account = Account(
|
||||
id=None,
|
||||
context.account = Account(
|
||||
email_address='foo@mycroft.ai',
|
||||
username='foobar',
|
||||
refresh_tokens=None,
|
||||
display_name='foobar',
|
||||
refresh_tokens=[],
|
||||
subscription=AccountSubscription(
|
||||
type='monthly supporter',
|
||||
start_date=None,
|
||||
type='Monthly Supporter',
|
||||
start_date=date.today(),
|
||||
stripe_customer_id='foo'
|
||||
),
|
||||
agreements=[
|
||||
AccountAgreement(name=PRIVACY_POLICY, accept_date=None)
|
||||
AccountAgreement(type=PRIVACY_POLICY, accept_date=date.today())
|
||||
]
|
||||
)
|
||||
|
||||
acct_repository = AccountRepository(db)
|
||||
acct_repository.add(test_account, 'foo')
|
||||
context.account = acct_repository.get_account_by_email(
|
||||
test_account.email_address
|
||||
)
|
||||
account_id = acct_repository.add(context.account, 'foo')
|
||||
context.account.id = account_id
|
||||
|
||||
|
||||
def after_scenario(context, _):
|
||||
with get_db_connection(context.client_config['DB_CONNECTION_POOL']) as db:
|
||||
acct_repository = AccountRepository(db)
|
||||
acct_repository.remove(context.account)
|
||||
bar_acct = acct_repository.get_account_by_email('bar@mycroft.ai')
|
||||
if bar_acct is not None:
|
||||
acct_repository.remove(bar_acct)
|
||||
agreement_repository = AgreementRepository(db)
|
||||
agreement_repository.remove(context.agreement, testing=True)
|
||||
agreement_repository.remove(context.privacy_policy, testing=True)
|
||||
agreement_repository.remove(context.terms_of_use, testing=True)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
Feature: Add a new account
|
||||
Test the API call to add an account to the database.
|
||||
|
||||
Scenario: Successful account addition
|
||||
When a valid new account request is submitted
|
||||
Then the request will be successful
|
||||
And the account will be added to the system
|
|
@ -1,3 +1,4 @@
|
|||
from dataclasses import asdict
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
|
||||
|
@ -16,9 +17,6 @@ def call_agreement_endpoint(context):
|
|||
def validate_response(context, version):
|
||||
assert_that(context.response.status_code, equal_to(HTTPStatus.OK))
|
||||
response_data = json.loads(context.response.data)
|
||||
expected_response = dict(
|
||||
content='this is Privacy Policy version ' + version,
|
||||
type=PRIVACY_POLICY,
|
||||
version=version
|
||||
)
|
||||
expected_response = asdict(context.privacy_policy)
|
||||
del(expected_response['effective_date'])
|
||||
assert_that(response_data, equal_to(expected_response))
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
from dataclasses import asdict
|
||||
from datetime import date
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
|
||||
from behave import given, then, when
|
||||
from hamcrest import assert_that, equal_to
|
||||
from hamcrest import assert_that, equal_to, has_item
|
||||
|
||||
from selene.api.testing import generate_auth_tokens
|
||||
from selene.data.account import PRIVACY_POLICY
|
||||
|
||||
|
||||
@given('an authenticated user')
|
||||
|
@ -26,10 +28,20 @@ def validate_response(context):
|
|||
response_data['emailAddress'],
|
||||
equal_to(context.account.email_address)
|
||||
)
|
||||
assert_that(response_data['id'], equal_to(context.account.id))
|
||||
assert_that(response_data['subscription'], equal_to(
|
||||
dict(type='monthly supporter', startDate=str(date.today()))
|
||||
))
|
||||
assert_that(response_data['agreements'], equal_to(
|
||||
[dict(name='Privacy Policy', acceptedDate=str(date.today()))]
|
||||
))
|
||||
assert_that(
|
||||
response_data['subscription']['type'],
|
||||
equal_to('Monthly Supporter')
|
||||
)
|
||||
assert_that(
|
||||
response_data['subscription']['startDate'],
|
||||
equal_to(str(date.today()))
|
||||
)
|
||||
assert_that(
|
||||
response_data['subscription'], has_item('id')
|
||||
)
|
||||
|
||||
assert_that(len(response_data['agreements']), equal_to(1))
|
||||
agreement = response_data['agreements'][0]
|
||||
assert_that(agreement['name'], equal_to(PRIVACY_POLICY))
|
||||
assert_that(agreement['acceptedDate'], equal_to(str(date.today())))
|
||||
assert_that(agreement, has_item('id'))
|
||||
|
|
Loading…
Reference in New Issue