def put(self, **kwargs): game_id = kwargs.get("game_id") results = ndb.Key(Results, game_id).get() if results is not None: self.abort(409) req_json = json.loads(self.request.body) results_json = json.dumps(req_json['results']) if 'is_public' in req_json: is_public = req_json['is_public'] else: is_public = False key = ndb.Key(urlsafe=game_id) if key.kind() == 'PreGame': pregame = key.get() settings = json.loads(pregame.game_json)['meta'] if 'is_public' in settings: is_public = is_public or settings['is_public'] devices = pregame.device_ids else: devices = [self.device_id] players_ids = [get_device_and_user(device)[1] for device in devices] results = Results(id=game_id) results.results_json = results_json results.players_ids = players_ids results.timestamp = make_timestamp() results.is_public = is_public results.put() self.response.set_status(201)
def test_change_stream_state_handler(self): UserStreams(parent=get_device_and_user('device_id_1')[1], streams=['2', '3']).put() request = webapp2.Request.blank(r'/device_id_1/streams/1/to/true') request.method = 'POST' response = request.get_response(main.app) self.assertEqual(response.status_int, 200)
def dispatch(self): self.device_id = (self.request.route_kwargs.get('device_id', None) or self.request.headers.get('TheHat-Device-Identity', None)) if self.device_id is None: self.response.headers.add("WWW-Authenticate", "device-id") self.abort(401) self.device_key, self.user_key = get_device_and_user(self.device_id) super(AuthorizedAPIRequestHandler, self).dispatch()
def dispatch(self): self.device_id = (self.request.route_kwargs.get('device_id', None) or self.request.headers.get('TheHat-Device-Identity', None)) if self.device_id is None: self.response.headers.add("WWW-Authenticate", "device-id") self.abort(401) self.device_key, self.user_key = get_device_and_user(self.device_id) super(APIRequestHandler, self).dispatch()
def __init__(self, x, cnt): self.word = x.word self.replacement_word = x.replacement_word or '' self.cnt = cnt device, user = get_device_and_user(x.device.get().device_id) if device == user: self.device_id = device.get().device_id else: self.device_id = user.get().user_id
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() self.device, self.user = get_device_and_user("123")