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())
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)
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)
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)
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())
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)
def get(self): self.response.write( open('templates/index.html').read() % { 'login_url': users.create_login_url(), 'valid_user': bool(utils.is_valid_user()), })
def get(self): self.response.write(open('templates/index.html').read() % { 'login_url': users.create_login_url(), 'valid_user': bool(utils.is_valid_user()), })