示例#1
0
  def test_settings_change_avatar(self):
    nick = 'obligated'
    self.login(nick)

    nick = clean.nick(nick)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')

    # TODO(teemu): add more tests for different file types (gif and jpg).
    # Alternatively, test those against api.avatar_upload.
    r = self.client.post('/user/obligated/settings/photo',
                         {
                           'avatar': 'default/animal_9',
                           '_nonce' :
                              util.create_nonce('obligated', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

    new_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)

    self.assertContains(r, 'Avatar changed')
    self.assertTemplateUsed(r, 'settings_photo.html')
    self.assertTemplateUsed(r, 'flash.html')
示例#2
0
  def test_start_stop(self):
    actor_pre_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_pre_ref.extra.get('im_notify', False), False)
  
    r = self.sign_in(self.from_jid, 'hermit')

    self.send(self.from_jid, 'start')

    actor_post_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_post_ref.extra.get('im_notify', False), True)

    self.send(self.from_jid, 'stop')
    
    actor_last_ref = api.actor_get(api.ROOT, 'hermit')
    self.assertEqual(actor_last_ref.extra.get('im_notify', False), False)
示例#3
0
def actor_invite(request, nick, format='html'):
  nick = clean.nick(nick)

  view = api.actor_get(request.user, nick)
  if not view:
    raise exception.UserDoesNotExistError(nick, request.user)

  if not request.user or view.nick != request.user.nick:
    # Bounce the user to their own page (avoids any confusion for the wrong
    # nick in the url).  Perhaps unnecessary.
    return http.HttpResponseRedirect(
        '%s/invite' % request.user.url())
  
  handled = common_views.handle_view_action(
      request,
      { 'invite_request_email': request.path, })
  if handled:
    return handled

  if request.user and request.user.nick == view.nick:
    whose = 'Your'
  else:
    whose = "%s's" % view.display_nick()

  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('invite.html')
    return http.HttpResponse(t.render(c))
示例#4
0
def install_rootuser(request):
  # requires an admin
  user = users.get_current_user()
  if not user:
    return http.HttpResponseRedirect(users.create_login_url('/install'))
  else:
    if not users.is_current_user_admin():
      return http.HttpResponseRedirect('/')
  
  try:
    root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
  except:
    root_user = None

  if request.POST:
    try:
      logging.warning('Making root user: %s', settings.ROOT_NICK)
      validate.nonce(request, 'create_root')
      root_user = api.user_create_root(api.ROOT)
      return util.RedirectFlash('/install', 'Root user created')
    except:
      exception.handle_exception(request)

  redirect_to = '/'

  c = template.RequestContext(request, locals())    
  t = loader.get_template('rootuser.html')
  return http.HttpResponse(t.render(c))
示例#5
0
def authenticate_user_personal_key(nick, key):
  actor_ref = api.actor_get(api.ROOT, nick)
  check_key = generate_personal_key(actor_ref)

  if check_key != key:
    return None

  actor_ref.access_level = api.WRITE_ACCESS
  return actor_ref
示例#6
0
def invite_email(request, code):
  """User has received the invite email, and has followed the link to accept or
     or refuse it."""
  
  if request.user:
    handled = common_views.handle_view_action(
        request,
        {'invite_accept': request.user.url('/overview'),
         'invite_reject': request.user.url('/overview')
         }
        )
    if handled:
      return handled

  # Retrieve the invite
  invite = api.invite_get(api.ROOT, code)
  from_actor = invite.from_actor
  
  # Translate the from_actor into a display name
  from_actor_ref = api.actor_get(api.ROOT, from_actor)
  view = from_actor_ref

  if not from_actor_ref:
    # Corner case: from_actor was deleted since the invite was sent.
    # In this case, do we want to consider the invitation invalid?
    # (probably we do, because it's more likely that it was spam)
    return util.RedirectError("That invite is no longer valid")
    
    
  # We use api.ROOT in the next set of functions because the
  # invite is giving possibly private access to the user
  inbox = api.inbox_get_actor_contacts(api.ROOT,
                                       view.nick,
                                       limit=5)
  entries = api.entry_get_entries(api.ROOT, inbox)
  stream_keys = [e.stream for e in entries]
  streams = api.stream_get_streams(api.ROOT, stream_keys)
  actor_nicks = ([view.nick] +
                 [s.owner for s in streams.values() if s] +
                 [e.owner for e in entries] +
                 [e.actor for e in entries])
  actors = api.actor_get_actors(api.ROOT, actor_nicks)

  streams = display.prep_stream_dict(streams, actors)
  entries = display.prep_entry_list(entries, streams, actors)


  sidebar_green_top = True
  c = template.RequestContext(request, locals())

  t = loader.get_template('email.html')
  return http.HttpResponse(t.render(c))
示例#7
0
def login_noreally(request):
    if "sso_token" in request.GET:
        sso_token = request.GET["sso_token"]
        redirect_to = request.GET["redirect_to"]
        redirect_to = clean.redirect_to(redirect_to)

        nick, rememberme = cache.get("sso/%s" % sso_token)
        cache.delete("sso/%s" % sso_token)
        actor_ref = api.actor_get(api.ROOT, nick)
        response = http.HttpResponseRedirect(redirect_to)
        response = user.set_user_cookie(response, actor_ref, rememberme)
        return response
    return http.HttpResponseRedirect("/login")
示例#8
0
  def test_settings_upload_avatar(self):
    nick = 'obligated'
    self.login(nick)

    nick = clean.nick(nick)
    old_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick)
    contacts = api.actor_get_contacts(api.ROOT, nick)
    self.assertEquals(len(old_contact_avatars), len(contacts) + 1)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon',
                                                         'avatar_default')
    start_time = api.utcnow()
    no_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick,
                                                              since_time=start_time)
    self.assertEquals(len(no_contact_avatars), 0)

    # TODO(teemu): add more tests for different file types (gif and jpg).
    # Alternatively, test those against api.avatar_upload.
    f = open('testdata/test_avatar.jpg')
    r = self.client.post('/user/obligated/settings/photo',
                         {
                           'imgfile': f,
                           '_nonce' : 
                              util.create_nonce('obligated', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/user/obligated/settings/photo')

    actor_ref = api.actor_get(api.ROOT, nick)
    new_avatar = actor_ref.extra.get('icon', 'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)
    self.assertTrue(actor_ref.avatar_updated_at >= start_time)
    new_contact_avatars = api.actor_get_contacts_avatars_since(api.ROOT, nick,
                                                               since_time=start_time)
    self.assertEquals(len(new_contact_avatars), 1)
    self.assertEquals(new_contact_avatars.pop().nick, nick)

    self.assertContains(r, 'Avatar uploaded')
    self.assertTemplateUsed(r, 'settings_photo.html')
    self.assertTemplateUsed(r, 'flash.html')
示例#9
0
  def test_photo_upload(self):
    nick = 'popular'
    nick = clean.nick(nick)
    old_avatar = api.actor_get(api.ROOT, nick).extra.get('icon', 
                                                         'avatar_default')

    self.login(nick)
    f = open('testdata/test_avatar.jpg')
    r = self.client.post('/welcome/1',
                         {
                           'imgfile': f,
                           '_nonce' :
                              util.create_nonce('popular', 'change_photo'),
                         })
    r = self.assertRedirectsPrefix(r, '/welcome/1?')

    new_avatar = api.actor_get(api.ROOT, nick).extra.get('icon', 
                                                         'avatar_default')
    self.assertNotEquals(old_avatar, new_avatar)

    self.assertContains(r, 'Avatar uploaded')
    self.assertTemplateUsed(r, 'welcome_photo.html')
    self.assertTemplateUsed(r, 'flash.html')
示例#10
0
def get_api_user_from_oauth_request(oauth_request):
  oauth_token = oauth_request.get_parameter('oauth_token')
  oauth_consumer = oauth_request.get_parameter('oauth_consumer_key')
  
  if oauth_token == ROOT_TOKEN.key:
    return api.ROOT
  
  token_ref = api.oauth_get_access_token(api.ROOT, oauth_token)
  if not token_ref:
    return None
  
  actor_ref = api.actor_get(api.ROOT, token_ref.actor)
  actor_ref.access_level = token_ref.perms
  return actor_ref
示例#11
0
  def test_login_user_cleanup(self):
    log = 'broken'
    pwd = self.passwords[clean.nick(log)]
    
    actor_ref_pre = api.actor_get(api.ROOT, log)
    self.assert_(not actor_ref_pre.normalized_nick)
    self.assertRaises(exception.ApiException, 
                      api.stream_get_presence,
                      api.ROOT, 
                      log)
    self.assertRaises(exception.ApiException, 
                      api.stream_get_comment,
                      api.ROOT, 
                      log)

    r = self.client.post('/login', {'log': log, 'pwd': pwd})
    r = self.assertRedirectsPrefix(r, '/user/broken/overview')
  

  
    actor_ref_post = api.actor_get(api.ROOT, log)
    self.assert_(actor_ref_post.normalized_nick)
    self.assert_(api.stream_get_presence(api.ROOT, log))
    self.assert_(api.stream_get_comment(api.ROOT, log))
示例#12
0
  def test_invite_email_link(self):
    self.login('popular')
    popular_ref = api.actor_get(api.ROOT, '*****@*****.**')
    r = self.client.post(
        '/user/popular/invite',
        {'email': '*****@*****.**',
         'nick': '*****@*****.**',
         '_nonce': util.create_nonce(popular_ref, 'invite_request_email'),
         'invite_request_email': ''
         }
        )
    r = self.assertRedirectsPrefix(r, '/user/popular/invite')
    self.assertContains(r, 'Invitation sent')
    self.assertTemplateUsed(r, 'invite.html')
    self.assertEqual(len(mail.outbox), 1)

    sent_mail = mail.outbox[0]
    url = tests.get_relative_url(sent_mail.body)
    
    r = self.login_and_get('hermit', url)
    self.assertTemplateUsed(r, 'email.html')
示例#13
0
def badge_badge(request, format, nick):
  view = api.actor_get(request.user, nick)
  
  presence = api.presence_get(request.user, view.nick)
  
  if not presence:
    # look offline please
    line = 'Offline'
    light = 'gray'
    location = ''
  else:
    line = presence.extra.get('status', 'Offline')
    light = presence.extra.get('light', 'gray')
    location = presence.extra.get('location', '')

  if format == 'image':
    return http.HttpResponseRedirect('/images/badge_%s.gif' % light)

  if format == 'js-small':
    multiline = len(line) > 17
    truncated_line = len(line) > 30 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = 'js_small.js'
  elif format == 'js-medium' or format == 'js-large':
    truncated_line = len(line) > 40 and "%s..." % (line[:27]) or line
    content_type = 'text/javascript'
    template_path = '%s.js' % format.replace('-', '_')
  elif format == 'json':
    content_type = 'text/javascript'
    template_path = 'badge.json'

  elif format == 'xml':
    content_type = 'application/xml'
    template_path = 'badge.xml'

  c = template.RequestContext(request, locals())
  t = loader.get_template('%s' % template_path)
  r = http.HttpResponse(t.render(c))
  r['Content-type'] = content_type
  return r
示例#14
0
  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)
    task_more = api.task_process_any(api.ROOT)
    task_more = api.task_process_any(api.ROOT)
    task_more = api.task_process_any(api.ROOT)

    def _nope():
      task_more = api.task_process_any(api.ROOT)
    
    self.assertRaises(exception.ApiNoTasks, _nope)

    api.MAX_FOLLOWERS_PER_INBOX = old_max  

    pass
示例#15
0
 def setUp(self):
   super(ThrottleTest, self).setUp()
   self.popular = api.actor_get(api.ROOT, '*****@*****.**')
示例#16
0
  def test_task_crud(self):
    # make a fake task for posting a simple message
    nick = '*****@*****.**'
    action = 'post'
    uuid = 'forever'
    message = 'more'
    
    actor_ref = api.actor_get(api.ROOT, nick)

    # STOP TIME! OMG!
    test_util.utcnow = lambda: self.now

    # makin
    l = profile.label('api_task_create')
    task_ref = api.task_create(actor_ref, 
                               nick, 
                               action, 
                               uuid,
                               args=[],
                               kw={'nick': nick,
                                   'message': message,
                                   'uuid': uuid
                                   }
                               )
    l.stop()
    
    # grabbin
    l = profile.label('api_task_get (unlocked)')
    task_ref = api.task_get(actor_ref, nick, action, uuid)
    l.stop()
    
    # grab again, LOCK VILLE
    def _again():
      task_ref = api.task_get(actor_ref, nick, action, uuid)
    
    
    l = profile.label('api_task_get (locked)')
    self.assertRaises(exception.ApiLocked, _again)
    l.stop()

    # increment time
    new_now = self.now + self.delta
    test_util.utcnow = lambda: new_now

    # grab again, EXPIRED
    task_ref = api.task_get(actor_ref, nick, action, uuid)

    # locked if we try again
    self.assertRaises(exception.ApiLocked, _again)

    # updatin
    l = profile.label('api_task_update')
    task_ref = api.task_update(actor_ref, nick, action, uuid, '1')
    l.stop()
    self.assertEqual(task_ref.progress, '1')
    
    # grab again, FRESH AND CLEAN
    task_ref = api.task_get(actor_ref, nick, action, uuid)
    self.assertEqual(task_ref.progress, '1')

    # removin
    l = profile.label('api_task_remove')
    api.task_remove(actor_ref, nick, action, uuid)
    l.stop()

    # grab again, NOT FOUND
    def _not_found():
      task_ref = api.task_get(actor_ref, nick, action, uuid)

    self.assertRaises(exception.ApiNotFound, _not_found)