def test_device_delete(self): _device = device.AlexaDevice(-1, "temp_token1234") device_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/citizen/" + str( self._citizen.id) + "/device" device_post_header = { "device": _device.serialize(), "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMjM0IiwidXNlcl9yb2xlIjoidXNlckFkbWluIn0._zMvLSI7elh4ebv-1iaE8nXYdbzjyvpBNlDNhNSJMc0" } _device = device.deserialize( get_response(requests.post(device_uri, headers=device_post_header))) device_delete_header = { "device": _device.serialize(), "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMjM0IiwidXNlcl9yb2xlIjoidXNlckFkbWluIn0._zMvLSI7elh4ebv-1iaE8nXYdbzjyvpBNlDNhNSJMc0" } print("Delete" + str( device.deserialize( get_response( requests.delete(device_uri, headers=device_delete_header))).__dict__)) user_get_header = {"email": "*****@*****.**", "password": "******"} user_get_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/user/" _citizen_response = user.deserialize( get_response(requests.get(user_get_uri, headers=user_get_header))) self.assertEqual(len(_citizen_response.devices), 0)
def _deserialize(self, value, attr, obj): res = [] if not value: return res for d in value: res.append(device.deserialize(str(d))) return res
def lambda_handler(event, context): try: dvc = deserialize(event["device"]) if not dvc: return respond("400", event["device"]) if dvc.devicetype == "appdevice": dvc: device.AppDevice = device.deserialize(event["device"]) if not dvc.arn: # Create arn arn_endpoint = create_endpoint(dvc.token) dvc.arn = arn_endpoint else: # Update arn update_endpoint(dvc.arn, dvc.token) lambda_client = boto3.client( 'lambda', region_name=region_name, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) arg = bytes(json.dumps({"device": dvc.serialize()}), 'utf-8') response = lambda_client.invoke( FunctionName=arn_device_put_endpoint, InvocationType="RequestResponse", Payload=arg) data = response["Payload"].read().decode() res = json.loads(data) if res == "ok": return respond("200", dvc.serialize()) else: return respond("400", event["device"]) except: return respond("400", event["device"])
def lambda_handler(event, context): try: dvc = deserialize(event["device"]) except: return respond("400", event["device"]) if not dvc: return respond("400", event["device"]) dvc.delete() return respond("200", device.Device(-1, "").serialize())
def lambda_handler(event, context): try: dvc = device.deserialize(event["device"]) usr = user.User.get(event["id"]) except: return respond("400", device.Device(-1, "").serialize()) if not all(x is not None for x in [dvc, usr]): return respond("400", device.Device(-1, "").serialize()) id = dvc.post(usr) dvc.id = id return respond("200", dvc.serialize())
def lambda_handler(event, context): try: dvc: device.AppDevice = device.deserialize(event["device"]) if not dvc.arn: # Create arn arn_endpoint = create_endpoint(dvc.token) dvc.arn = arn_endpoint return respond("200", dvc.serialize()) else: # Update arn update_endpoint(dvc.arn, dvc.token) return respond("200", dvc.serialize()) except: return respond("400", "")
def lambda_handler(event, context): try: dvc: device.AlexaDevice = deserialize(event["device"]) if dvc.devicetype == "alexadevice": dvc: device.Device = device.Device.get_from_object(dvc.user_id) usr = dvc.get_owner() return respond("200", usr.serialize()) # TODO: Add more devices else: return respond("400", user.User(-1, "", "", "userAdmin").serialize()) except: return respond("401", user.User(-1, "", "", "userAdmin").serialize())
def lambda_handler(event, context): dvc = device.deserialize(event["device"]) dvc.put() return "ok"