def test_notify_on_post(self): actor_ref = api.actor_get(api.ROOT, 'popular') api.post(actor_ref, nick='popular', message='la la la') self.exhaust_queue('popular') # should notify popular and unpopular self.assertEqual(len(xmpp.outbox), 2)
def test_task_post_process_any(self): """ test that api.post creates a task and additional calls resume """ nick = '*****@*****.**' uuid = 'HOWNOW' message = 'BROWNCOW' actor_ref = api.actor_get(api.ROOT, nick) # DROP old_max = api.MAX_FOLLOWERS_PER_INBOX api.MAX_FOLLOWERS_PER_INBOX = 1 try: entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message) self.assertEqual(entry_ref.extra['title'], message) # make sure we can repeat two_entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message) self.assertEqual(entry_ref.uuid, two_entry_ref.uuid) # and that task_process_any works # and run out the queue for i in range(5): api.task_process_any(api.ROOT, nick) self.assertRaises(exception.ApiNoTasks, lambda: api.task_process_actor(api.ROOT, nick)) finally: api.MAX_FOLLOWERS_PER_INBOX = old_max
def create_djangouser_for_user(cls, user): from common import api actor_ref = api.actor_lookup_email(api.ROOT, user.email()) if actor_ref: return actor_ref params = {'nick': user.nickname(), 'password': "******", 'first_name': user.nickname(), 'last_name': user.nickname()} actor_ref = api.user_create(api.ROOT, **params) actor_ref.access_level = "delete" relation_ref = api.email_associate(api.ROOT, actor_ref.nick, user.email()) api.post(actor_ref, nick=actor_ref.nick, message='Joined %s!' % (settings.SITE_NAME), icon='jaiku-new-user') return actor_ref
def test_task_post_process_any(self): """ test that api.post creates a task and additional calls resume """ nick = '*****@*****.**' uuid = 'HOWNOW' message = 'BROWNCOW' actor_ref = api.actor_get(api.ROOT, nick) # DROP old_max = api.MAX_FOLLOWERS_PER_INBOX api.MAX_FOLLOWERS_PER_INBOX = 1 entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message) self.assertEqual(entry_ref.extra['title'], message) # make sure we can repeat two_entry_ref = api.post(actor_ref, nick=nick, uuid=uuid, message=message) self.assertEqual(entry_ref.uuid, two_entry_ref.uuid) # and that task_process_actor works task_more = api.task_process_any(api.ROOT) self.assert_(task_more) # and run out the queue task_more = api.task_process_any(api.ROOT) self.assert_(task_more) task_more = api.task_process_any(api.ROOT) self.assert_(task_more) task_more = api.task_process_any(api.ROOT) self.assert_(task_more) task_more = api.task_process_any(api.ROOT) self.assert_(not task_more) def _nope(): task_more = api.task_process_any(api.ROOT) self.assertRaises(exception.ApiNoTasks, _nope) api.MAX_FOLLOWERS_PER_INBOX = old_max pass
def user_create(service, params, username="", id="", remote_url=""): logging.info("user_create") actor_ref = api.user_create(api.ROOT, **params) actor_ref.access_level = "delete" api.post(actor_ref, nick=actor_ref.nick, message="Joined %s!" % (util.get_metadata("SITE_NAME"))) email = params.get("email", None) if email is not None: api.email_associate(api.ROOT, actor_ref.nick, email) else: key = "emailneeded_%s" % util.display_nick(actor_ref.nick) memcache.client.set(key, True, 360) key = "firsttime_%s" % util.display_nick(actor_ref.nick) memcache.client.set(key, True, 360) external_profile_ref = api.create_external_profile(actor_ref.nick, service, username, id, remote_url) return actor_ref
def join_join(request): if request.user: raise exception.AlreadyLoggedInException() redirect_to = request.REQUEST.get('redirect_to', '/') # get the submitted vars nick = request.REQUEST.get('nick', '') first_name = request.REQUEST.get('first_name', '') last_name = request.REQUEST.get('last_name', '') email = request.REQUEST.get('email', '') password = request.REQUEST.get('password', '') confirm = request.REQUEST.get('confirm', '') homepage = request.REQUEST.get('homepage', '') hide = request.REQUEST.get('hide', '') if request.POST: try: # TODO validate params = util.query_dict_to_keywords(request.POST) if hide: params['privacy'] = 2 validate.email(email) if not mail.is_allowed_to_send_email_to(email): raise exception.ValidationError("Cannot send email to that address") # TODO start transaction if api.actor_lookup_email(api.ROOT, email): raise exception.ValidationError( 'That email address is already associated with a member.') actor_ref = api.user_create(api.ROOT, **params) actor_ref.access_level = "delete" api.post(actor_ref, nick=actor_ref.nick, message='Joined %s!' % (settings.SITE_NAME), icon='jaiku-new-user') # send off email confirmation api.activation_request_email(actor_ref, actor_ref.nick, email) # TODO end transaction welcome_url = util.qsa('/welcome', {'redirect_to': redirect_to}) # NOTE: does not provide a flash message response = http.HttpResponseRedirect(welcome_url) user.set_user_cookie(response, actor_ref) return response except: exception.handle_exception(request) # for legal section legal_component = component.include('legal', 'dummy_legal') legal_html = legal_component.embed_join() # for sidebar sidebar_green_top = True area = "join" c = template.RequestContext(request, locals()) t = loader.get_template('join/templates/join.html') return http.HttpResponse(t.render(c))
def post(self, from_jid, message): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") entry_ref = api.post(jid_ref, nick=jid_ref.nick, message=message)
def post(self, actor_ref): entry_ref = api.post(actor_ref, nick=actor_ref.nick, message='test_message') self.exhaust_queue_any() return entry_ref
def join_join(request): if request.user: raise exception.AlreadyLoggedInException() redirect_to = request.REQUEST.get('redirect_to', '/') account_types = api.get_config_values(api.ROOT, 'account_type') # get the submitted vars nick = request.REQUEST.get('nick', ''); first_name = request.REQUEST.get('first_name', ''); last_name = request.REQUEST.get('last_name', ''); email = request.REQUEST.get('email', ''); password = request.REQUEST.get('password', ''); confirm = request.REQUEST.get('confirm', ''); hide = request.REQUEST.get('hide', ''); country_tag = request.REQUEST.get('country_tag', '') if request.POST: try: # TODO validate params = util.query_dict_to_keywords(request.POST) if hide: params['privacy'] = 2 # XXX: Check if the data come from a openid account # @author: [email protected] fromopenid = request.POST.get('fromopenid', False) and True if fromopenid: try: person = openidgae.get_current_person(request, http.HttpResponse()) except: raise exception.ServiceError email = person.get_email() if email == params['email']: params['password'] = util.generate_password() else: raise exception.ServiceError # ENDXXX validate.email(email) if not mail.is_allowed_to_send_email_to(email): raise exception.ValidationError("Cannot send email to that address") # TODO start transaction if api.actor_lookup_email(api.ROOT, email): raise exception.ValidationError( 'That email address is already associated with a member.') actor_ref = api.user_create(api.ROOT, **params) actor_ref.access_level = "delete" api.post(actor_ref, nick=actor_ref.nick, message='Joined %s!' % (util.get_metadata('SITE_NAME'))) if fromopenid: api.email_associate(api.ROOT, actor_ref.nick, email) else: # send off email confirmation api.activation_request_email(actor_ref, actor_ref.nick, email) logging.info('setting firsttime_%s from register page' % actor_ref.nick) memcache.client.set('firsttime_%s' % nick, True) # TODO end transaction welcome_url = util.qsa('/', {'redirect_to': redirect_to}) # NOTE: does not provide a flash message response = http.HttpResponseRedirect(welcome_url) user.set_user_cookie(response, actor_ref) return response except: exception.handle_exception(request) # for legal section legal_component = component.include('legal', 'dummy_legal') legal_html = legal_component.embed_join() # for sidebar sidebar_green_top = True area = "join" c = template.RequestContext(request, locals()) t = loader.get_template('join/templates/join.html') return http.HttpResponse(t.render(c))
def post(self, sender, message): sender_ref = api.actor_lookup_mobile(api.ROOT, sender) if not sender_ref: raise exception.ValidationError(HELP_SIGN_IN) entry_ref = api.post(sender_ref, nick=sender_ref.nick, message=message)
def join_join(request): if request.user: raise exception.AlreadyLoggedInException() redirect_to = get_clean_redirect(request) # get the submitted vars nick = request.REQUEST.get('nick', '') first_name = request.REQUEST.get('first_name', '') last_name = request.REQUEST.get('last_name', '') email = request.REQUEST.get('email', '') password = request.REQUEST.get('password', '') confirm = request.REQUEST.get('confirm', '') homepage = request.REQUEST.get('homepage', '') hide = request.REQUEST.get('hide', '') if request.POST: try: # TODO validate params = util.query_dict_to_keywords(request.POST) if hide: params['privacy'] = 2 validate.email(email) if not mail.is_allowed_to_send_email_to(email): raise exception.ValidationError( "Cannot send email to that address") # TODO start transaction if api.actor_lookup_email(api.ROOT, email): raise exception.ValidationError( 'That email address is already associated with a member.') actor_ref = api.user_create(api.ROOT, **params) actor_ref.access_level = "delete" api.post(actor_ref, nick=actor_ref.nick, message='Joined %s!' % (settings.SITE_NAME), icon='jaiku-new-user') # send off email confirmation api.activation_request_email(actor_ref, actor_ref.nick, email) # TODO end transaction welcome_url = util.qsa('/welcome', {'redirect_to': redirect_to}) # NOTE: does not provide a flash message response = http.HttpResponseRedirect(welcome_url) user.set_user_cookie(response, actor_ref) return response except: exception.handle_exception(request) # for legal section legal_component = component.include('legal', 'dummy_legal') legal_html = legal_component.embed_join() # for sidebar sidebar_green_top = True area = "join" c = template.RequestContext(request, locals()) t = loader.get_template('join/templates/join.html') return http.HttpResponse(t.render(c))