def setup_creator(_account): user = _account['user'] pwd = _account['pwd'] token = Token() token.fetch_token(username=user, password=pwd) if token.has_valid_credentials(username=user, password=pwd): return PostcardCreator(token)
def _get_pcc_wrapper(stop_on_first_valid=True): pcc_wrappers = [] try_again_after = '' for account in settings.POST_ACCOUNTS: token = Token() if token.has_valid_credentials(account.get('username'), account.get('password')): pcc = PostcardCreator(token) if pcc.has_free_postcard(): pcc_wrappers.append(pcc) logger.info('account {} is valid'.format(account.get("username"))) if stop_on_first_valid: break else: next_quota = pcc.get_quota().get('next') if next_quota < try_again_after or try_again_after is '': try_again_after = next_quota logger.debug('account {} is invalid. '.format(account.get("username")) + 'new quota available after {}.'.format(next_quota)) else: logger.warning('wrong user credentials ' 'for {}'.format(account.get("username"))) return pcc_wrappers, try_again_after
def create_token(): global adapter_token adapter_token = requests_mock.Adapter() Token._create_session = create_mocked_session return Token(_protocol='mock://')
def login(): token = Token() token.fetch_token(username=os.environ['POSTUSER'], password=os.environ['POSTPASSWORD']) token.has_valid_credentials(username=os.environ['POSTUSER'], password=os.environ['POSTPASSWORD']) return token
def check_quota(_account): token = Token() token.fetch_token(username=_account['user'], password=_account['pwd']) if token.has_valid_credentials(username=_account['user'], password=_account['pwd']): return PostcardCreator(token).get_quota()['available']