def account_deleted(context): """Ensure account no longer exists in database.""" acct_repository = AccountRepository(context.db) membership = acct_repository.get_active_account_membership( context.accounts["foo"].id) context.accounts["foo"].membership = membership context.response = context.client.delete("/api/account")
def _get_account(self, device_id: str): """Use the device ID to find the account. :param device_id: The database ID for the device that made this API call """ account_repository = AccountRepository(self.db) return account_repository.get_account_by_device_id(device_id)
def _initialize_skill_settings(self, device_id): """Use default settings or copy from another device in same account.""" _log.info('Initializing settings for skill ' + self.skill.skill_gid) account_repo = AccountRepository(self.db) account = account_repo.get_account_by_device_id(device_id) skill_settings_repo = SkillSettingRepository(self.db) skill_family = extract_family_from_global_id(self.skill.skill_gid) family_settings = skill_settings_repo.get_family_settings( account.id, skill_family) new_settings_values = self.default_settings if family_settings is not None: for settings in family_settings: if settings.settings_values is None: continue if settings.settings_values != self.default_settings: field_names = settings.settings_values.keys() if field_names == self.default_settings.keys(): _log.info( 'Copying settings from another device for skill' + self.skill.skill_gid) new_settings_values = settings.settings_values break else: _log.info('Using default skill settings for skill ' + self.skill.skill_gid) return new_settings_values
def _get_active_membership(self): """Get the currently active membership for the account.""" acct_repository = AccountRepository(self.db) active_membership = acct_repository.get_active_account_membership( self.account.id) return active_membership
def validate_absence_of_membership(context): """Check for the absence of a membership on an account.""" acct_repository = AccountRepository(context.db) membership = acct_repository.get_active_account_membership( context.accounts["foo"].id ) assert_that(membership, none())
def validate_monthly_account(context): acct_repository = AccountRepository(context.db) membership = acct_repository.get_active_account_membership( context.accounts['foo'].id) assert_that(membership.type, equal_to(MONTHLY_MEMBERSHIP)) assert_that(membership.payment_account_id, starts_with('cus')) assert_that(membership.start_date, equal_to(date.today())) assert_that(membership.end_date, none())
def add_account(db, **overrides): acct_repository = AccountRepository(db) account = build_test_account(**overrides) account.id = acct_repository.add(account, 'test_password') if account.membership is not None: acct_repository.add_membership(account.id, account.membership) return account
def put(self): account_id = self.request.json['accountId'] coded_password = self.request.json['password'] binary_password = a2b_base64(coded_password) password = binary_password.decode() acct_repository = AccountRepository(self.db) acct_repository.change_password(account_id, password) return '', HTTPStatus.NO_CONTENT
def _get_account_skill_settings(self): """Get all the permutations of settings for a skill""" account_repo = AccountRepository(self.db) account = account_repo.get_account_by_device_id(self.device_id) skill_settings = ( self.device_skill_repo.get_skill_settings_for_account( account.id, self.skill.id)) return skill_settings
def validate_monthly_account(context): """Check that the monthly membership information for an account is accurate.""" acct_repository = AccountRepository(context.db) membership = acct_repository.get_active_account_membership( context.accounts["foo"].id) assert_that(membership.type, equal_to(MONTHLY_MEMBERSHIP)) assert_that(membership.payment_account_id, starts_with("cus")) assert_that(membership.start_date, equal_to(datetime.utcnow().date())) assert_that(membership.end_date, none())
def _get_account_by_email(self): """Use email returned by the authentication platform for validation""" if self.email_address is None: raise AuthenticationError('could not retrieve email from provider') acct_repository = AccountRepository(self.db) self.account = acct_repository.get_account_by_email(self.email_address) if self.account is None: raise AuthenticationError('no account found for provided email')
def check_db_for_account(context): acct_repository = AccountRepository(context.db) account = acct_repository.get_account_by_email('*****@*****.**') # add account to context so it will deleted by cleanup step context.accounts['bar'] = account assert_that(account, not_none()) assert_that(account.email_address, equal_to('*****@*****.**')) assert_that(len(account.agreements), equal_to(2)) for agreement in account.agreements: assert_that(agreement.type, is_in((PRIVACY_POLICY, TERMS_OF_USE))) assert_that(agreement.accept_date, equal_to(str(date.today())))
def get(self): return_data = dict(accountExists=False, noFederatedEmail=False) if self.request.args['token']: email_address = self._get_email_address() if self.request.args[ 'platform'] != 'Internal' and not email_address: return_data.update(noFederatedEmail=True) account_repository = AccountRepository(self.db) account = account_repository.get_account_by_email(email_address) if account is None: return_data.update(accountExists=False) return return_data, HTTPStatus.OK
def check_db_for_account(context): """Check that the account was created as expected.""" acct_repository = AccountRepository(context.db) account = acct_repository.get_account_by_email("*****@*****.**") # add account to context so it will deleted by cleanup step context.accounts["bar"] = account assert_that(account, not_none()) assert_that(account.email_address, equal_to("*****@*****.**")) assert_that(len(account.agreements), equal_to(2)) utc_date = datetime.utcnow().date() for agreement in account.agreements: assert_that(agreement.type, is_in((PRIVACY_POLICY, TERMS_OF_USE))) assert_that(agreement.accept_date, equal_to(str(utc_date)))
def post(self): event = json.loads(self.request.data) type = event.get('type') if type == 'customer.subscription.deleted': customer = event['data']['object']['customer'] AccountRepository(self.db).end_active_membership(customer) return '', HTTPStatus.OK
def put(self, device_id): """Handle an HTTP PUT request.""" self._authenticate(device_id) self._validate_request() account = AccountRepository(self.db).get_account_by_device_id(device_id) self._send_message(account) return "", HTTPStatus.OK
def _add_account(context, db): test_account = Account(email_address='*****@*****.**', username='******', membership=AccountMembership( type='Monthly Membership', start_date=date.today(), payment_method='Stripe', payment_account_id='foo', payment_id='bar'), agreements=[ 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)
def get(self, device_id): self._authenticate(device_id) arch = self.request.args.get('arch') account = AccountRepository( self.db).get_account_by_device_id(device_id) if account and account.membership: link = self._get_premium_voice_link(arch) response = {'link': link}, HTTPStatus.OK else: response = '', HTTPStatus.NO_CONTENT return response
def get(self, device_id): self._authenticate(device_id) account = AccountRepository( self.db).get_account_by_device_id(device_id) if account: membership = account.membership response = ({ '@type': membership.type if membership is not None else 'free' }, HTTPStatus.OK) else: response = '', HTTPStatus.NO_CONTENT return response
def _build_report(self, date: datetime = None): if date is None: date = datetime.now() user_metrics = AccountRepository(self.db).daily_report(date) email = EmailMessage( sender='*****@*****.**', recipient=os.environ['REPORT_RECIPIENT'], subject='Mycroft Daily Report - {}'.format( date.strftime('%Y-%m-%d')), template_file_name='metrics.html', template_variables=dict(user_metrics=user_metrics)) mailer = SeleneMailer(email) mailer.send(True)