def test_job_serializes_to_database(self): """Job_Model: object serializes to database system correctly""" # Create the simulated job and serialize it to storage. new_job = job.Job() new_job.send_to_storage() # Compare what was stored with the original object. stored_row = storage.get_one(job.Job, 'uuid', new_job.get_uuid()) assert new_job.get_uuid() == stored_row[0] assert new_job.get_status() == stored_row[1] assert new_job.get_result() == stored_row[2] assert new_job.get_destination() == stored_row[3]
def from_storage(uuid): """Build a Job object based on an entry in storage. @param[in] uuid UUID of the stored job to reconstruct. @return An instance of Job populated by the specified stored contents. """ row = storage.get_one(Job, "uuid", uuid) if not row: # raise ValueError("UUID '{0}' was not found in storage".format(uuid)) # Let's be a little more gentle. return None new_job = Job(uuid) for tuple in zip(Job._get_field_definitions(), row): # Invoke the 'get_*' method for all keys. attribute_name = tuple[0][0] attribute_value = tuple[1] attribute_setter = getattr(new_job, "set_{0}".format(attribute_name)) attribute_setter(attribute_value) return new_job