def __init__(self, browser_langs, *a, **kw): FakeAccount.__init__(self, *a, **kw) if browser_langs: lang = browser_langs[0] content_langs = list(browser_langs) # try to coerce the default language if g.lang not in content_langs: content_langs.append(g.lang) content_langs.sort() else: lang = g.lang content_langs = 'all' self._defaults = self._defaults.copy() self._defaults['pref_lang'] = lang self._defaults['pref_content_langs'] = content_langs self._defaults['pref_frame_commentspanel'] = False self._load()
def test_mod_link_hide_event(self): host = "reddit.com" actor = FakeAccount(_id=123456, name="Hider") link = MagicMock(name="link") context = MagicMock(name="context") request = MagicMock(name="request", host=host) request.parsed_agent.app_name = None base_url = '/base/url' request.referrer = "https://www.reddit.com/" link.url = 'https://www.reddit.com/r/testing/comments/13st/test' parent_sr = link.subreddit_slow parent_sr._id = link.sr_id parent_sr.is_moderator = lambda u: MagicMock(name='sr_mod_rel') link_author = link.author_slow g.events.hide_link_event(actor, link, base_url, request=request, context=context) g.events.queue_production.assert_event_item({ 'event_topic': 'flatlist_events', 'event_type': 'ss.post_flatlist', 'payload': { 'app_name': host, 'base_url': base_url, 'is_target_author': False, 'is_sr_moderator': True, 'process_notes': 'hide', 'sr_id': parent_sr._id, 'sr_name': parent_sr.name, 'target_created_ts': 1, 'target_author_name': link_author.name, 'target_fullname': link._fullname, 'target_id': link._id, 'target_url': link.url, 'target_url_domain': 'www.reddit.com', 'user_id': actor._id, 'user_name': actor.name, 'domain': request.host, 'oauth2_client_app_type': context.oauth2_client.app_type, 'obfuscated_data': { 'client_ip': request.ip, }, 'oauth2_client_id': context.oauth2_client._id, 'user_features': context.user.user_features, 'oauth2_client_name': context.oauth2_client.name, 'referrer_domain': self.domain_mock(), 'referrer_url': request.headers.get('Referer'), 'session_referrer_domain': self.domain_mock(), 'user_agent': request.user_agent, 'user_agent_parsed': request.parsed_agent.to_dict(), 'geoip_country': context.location, }, })
def create_account(full_name): name = full_name.replace(' ', '_') retry = 2 # First retry will by name2 username = name while True: # Create a new account try: if dryrun: try: account = Account._by_name(username) if account: raise AccountExists except NotFound: account = FakeAccount() account.name = username else: account = register(username, generate_password(), None) account.ob_account_name = full_name account._commit() except AccountExists: # This username is taken, generate another, but first limit the retries if retry > MAX_RETRIES: raise StandardError("Unable to create account for '%s' after %d attempts" % (full_name, retry - 1)) else: return account username = "******" % (name, retry) retry += 1
def setUp(self): self.logged_in = Account(name="test") self.logged_out = FakeAccount() from r2.lib.memoize import g self.autopatch(g, "memoizecache", NonCache())
def setUp(self): self.logged_in = Account(name="test") self.logged_out = FakeAccount() self.patch_g(memoizecache=NonCache())
def setUp(self): super(PasswordUpdateTests, self).setUp() self.user = FakeAccount(name='fake', password=bcrypt_password(CURRENT_PW))
def setUp(self): self.logged_in = Account(name="test") self.logged_out = FakeAccount()