def post(self): data = request.get_json() system_id = data.get('system_id') user_email = data.get('user_email') if None in (system_id, user_email): abort(400) system = System.from_system_id(system_id) user = User.from_email(user_email) if None in (system, user): abort(400) if current_user == user: abort(400) if not Owner.is_owner_of(current_user, system): abort(401) sec_obj = SecondaryModel.create(user, system) sec_obj.put() secondaries = SecondaryModel.from_system(system) if sec_obj not in secondaries: secondaries.append(sec_obj) ret = self.get_response_map_from_secondaries(secondaries) return jsonify(ret)
def get(self, system_id): system = System.from_system_id(system_id) if system is None or not Owner.is_owner_of(current_user, system): abort(400) secondaries = SecondaryModel.from_system(system) ret = self.get_response_map_from_secondaries(secondaries) return jsonify(ret)
def update_device_association(self, serial_number, req_data): system_id = req_data.get("system_id") device = DeviceModel.from_serial_number(serial_number) if device is None: abort(400, 'No such device.') if system_id is not None: system = System.from_system_id(system_id) return self.associate_device(device, system) else: return self.disassociate_device(device)
def get(self, system_id): system = SystemModel.from_system_id(system_id) is_owner = OwnerModel.is_owner_of(current_user, system) is_sec, _ = SecondaryModel.is_secondary_of(current_user, system) if not (is_owner or is_sec): abort(401) frames = system.get_latest_data_frames() devid_loc = { f.device_key.get().serial_num: get_download_url(f.location) for f in frames } return jsonify(devid_loc)
def test_system_from_id_none(): assert System.from_system_id(None) is None
def test_system_from_id(random_system): assert random_system == System.from_system_id( random_system.key.integer_id())