def test_component_load(self): _id = "000000000000000000000001" name = "test_component1" # Test load on just _id reference = ComponentReference(_id=_id) component = Component.load(reference) json = component.json json.pop("version", None) json.pop("metadata", None) assert json == self.json_entries[0] del component # Test load on just name refrence = ComponentReference(name=name) component = Component.load(reference) json = component.json json.pop("version", None) json.pop("metadata", None) assert json == self.json_entries[0] del component # Test load on both _id and name reference = ComponentReference(_id=_id, name=name) component = Component.load(reference) json = component.json json.pop("version", None) json.pop("metadata", None) assert json == self.json_entries[0] del component # Test load on both _id and name reference = ComponentReference(value=self.json_entries[0]) component = Component.load(reference) json = component.json json.pop("version", None) json.pop("metadata", None) assert json == self.json_entries[0] del component
def datadump(samplecomponent_ref_json: Dict): samplecomponent_ref = SampleComponentReference(value=samplecomponent_ref_json) samplecomponent = SampleComponent.load(samplecomponent_ref) sample = Sample.load(samplecomponent.sample) component = Component.load(samplecomponent.component) serotype = sample.get_category("serotype") if serotype is None: serotype = Category(value={ "name": "serotype", "component": samplecomponent.component, "summary": { "serotype": "", "antigenic profile": "", "status": "", }, "report": {} }) extract_serotype_results(serotype, samplecomponent["results"], samplecomponent["component"]["name"]) samplecomponent.set_category(serotype) sample.set_category(serotype) samplecomponent.save_files() common.set_status_and_save(sample, samplecomponent, "Success") with open(os.path.join(samplecomponent["component"]["name"], "datadump_complete"), "w+") as fh: fh.write("done")
def test_component_create_from_ref(self): _id = "000000000000000000000001" name = "test_component" component = Component.load( reference=ComponentReference(_id=_id, name=name)) assert component.delete() == True test_component = Component(value=self.json_entries[0]) test_component.save() json = component.json json.pop("version", None) json.pop("metadata", None) assert json == self.json_entries[0]
def initialize(): with open(os.path.join(os.path.dirname(__file__), 'config.yaml')) as fh: config: Dict = yaml.load(fh, Loader=yaml.FullLoader) if not(datahandling.has_a_database_connection()): raise ConnectionError("BIFROST_DB_KEY is not set or other connection error") global COMPONENT try: component_ref = ComponentReference(name=config["name"]) COMPONENT = Component.load(component_ref) if COMPONENT is not None and '_id' in COMPONENT.json: return else: COMPONENT = Component(value=config) install_component() except Exception as e: print(traceback.format_exc(), file=sys.stderr) return
def test_component_delete(self): _id = "000000000000000000000001" name = "test_component" component = Component.load(ComponentReference(_id=_id, name=name)) assert component.delete() == True