示例#1
0
  def test_is_valid_user(self):
    self.assertFalse(utils.is_valid_user())

    self.mock_current_user('random', '*****@*****.**')
    self.assertFalse(utils.is_valid_user())

    self.mock_current_user(is_admin=True)
    self.assertTrue(utils.is_valid_user())

    self.mock_current_user('real', '*****@*****.**')
    self.assertTrue(utils.is_valid_user())

    self.mock_current_user('real', '*****@*****.**')
    self.assertTrue(utils.is_valid_user())

    self.mock_current_user('fake', '*****@*****.**')
    self.assertFalse(utils.is_valid_user())

    self.mock_current_user('fake', 'fake@google_com')
    self.assertFalse(utils.is_valid_user())

    self.mock_current_user('fake', '*****@*****.**')
    self.assertFalse(utils.is_valid_user())

    self.mock_current_user('fake', 'fake@chromium_org')
    self.assertFalse(utils.is_valid_user())
示例#2
0
  def get(self):
    if not utils.is_valid_user():
      self.redirect(users.create_login_url('/'))
      return

    try:
      update_record(**parse_request(self.request, {
        'key': parse_record_key,
        'tags': parse_strings,
        'fields': parse_fields,
      }))
    except ValueError as e:
      logging.warning(traceback.format_exc())
      self.response.write(e)
示例#3
0
    def get(self):
        if not utils.is_valid_user():
            self.redirect(users.create_login_url('/'))
            return

        try:
            update_record(**parse_request(
                self.request, {
                    'key': parse_record_key,
                    'tags': parse_strings,
                    'fields': parse_fields,
                }))
        except ValueError as e:
            logging.warning(traceback.format_exc())
            self.response.write(e)
示例#4
0
  def post(self):
    if not utils.is_valid_user() and not self._is_cq_bot():
      self.response.set_status(403)
      return

    try:
      packets = map(json.loads, self.request.get_all('p'))
      for packet in packets:
        if not isinstance(packet, dict):
          raise ValueError('JSON dictionary expected.')
    except ValueError as e:
      logging.warning(traceback.format_exc())
      self.response.write('Invalid packet: %s' % e)
      return

    try:
      for packet in packets:
        update_record(**utils.filter_dict(packet, ('key', 'tags', 'fields')))
    except ValueError as e:
      logging.warning(traceback.format_exc())
      self.response.write(e)
示例#5
0
    def test_is_valid_user(self):
        self.assertFalse(utils.is_valid_user())

        self.mock_current_user('random', '*****@*****.**')
        self.assertFalse(utils.is_valid_user())

        self.mock_current_user('real', '*****@*****.**')
        self.assertTrue(utils.is_valid_user())

        self.mock_current_user('real', '*****@*****.**')
        self.assertTrue(utils.is_valid_user())

        self.mock_current_user('fake', '*****@*****.**')
        self.assertFalse(utils.is_valid_user())

        self.mock_current_user('fake', 'fake@google_com')
        self.assertFalse(utils.is_valid_user())

        self.mock_current_user('fake', '*****@*****.**')
        self.assertFalse(utils.is_valid_user())

        self.mock_current_user('fake', 'fake@chromium_org')
        self.assertFalse(utils.is_valid_user())
示例#6
0
    def post(self):
        if not utils.is_valid_user() and not self._is_cq_bot():
            self.response.set_status(403)
            return

        try:
            packets = map(json.loads, self.request.get_all('p'))
            for packet in packets:
                if not isinstance(packet, dict):
                    raise ValueError('JSON dictionary expected.')
        except ValueError as e:
            logging.warning(traceback.format_exc())
            self.response.write('Invalid packet: %s' % e)
            return

        try:
            for packet in packets:
                update_record(
                    **utils.filter_dict(packet, ('key', 'tags', 'fields')))
        except ValueError as e:
            logging.warning(traceback.format_exc())
            self.response.write(e)
示例#7
0
 def get(self):
     self.response.write(
         open('templates/index.html').read() % {
             'login_url': users.create_login_url(),
             'valid_user': bool(utils.is_valid_user()),
         })
示例#8
0
文件: index.py 项目: eunchong/infra
 def get(self):
   self.response.write(open('templates/index.html').read() % {
     'login_url': users.create_login_url(),
     'valid_user': bool(utils.is_valid_user()),
   })