def setUpTestData(cls): super().setUpTestData() cls.user = UserFactory() cls.target_study = factory.StudyFactory() cls.target_study.userpermission_set.create( user=cls.user, permission_type=models.StudyPermission.WRITE ) # IDs are hard-coded in FBA files in main/tests/files line1 = factory.LineFactory(id=998, study=cls.target_study, name="BW1") met1 = factory.MetaboliteFactory(id=898, type_name="D-Glucose") met2 = factory.MetaboliteFactory(id=899, type_name="Acetate") # optical density already defined in bootstrap od = models.MeasurementType.objects.get( uuid="d7510207-5beb-4d56-a54d-76afedcf14d0" ) values = zip(cls.TIMES, cls.GLUCOSE_VALUES) cls._build_measurements( 1000, models.Protocol.CATEGORY_HPLC, line1, met1, values ) values = zip(cls.TIMES, cls.ACETATE_VALUES) cls._build_measurements( 1001, models.Protocol.CATEGORY_HPLC, line1, met2, values ) values = zip(cls.TIMES, cls.OD_VALUES) cls._build_measurements(1002, models.Protocol.CATEGORY_OD, line1, od, values) factory.SBMLTemplateFactory(id=666, uuid=uuid.uuid4())
def setUpTestData(cls): super().setUpTestData() cls.user = UserFactory() cls.target_study = factory.StudyFactory() cls.target_study.userpermission_set.create( user=cls.user, permission_type=models.StudyPermission.WRITE) # TODO: IDs are hard-coded in the *.post.*.json files # measurement ID of Optical Density is set to 1 in bootstrap factory.LineFactory(id=998, study=cls.target_study, name="BW1") factory.LineFactory(id=999, study=cls.target_study, name="arcA") factory.MetaboliteFactory(id=898, type_name="D-Glucose") factory.MetaboliteFactory(id=899, type_name="Acetate")
def test_simple_import(self): """Test an import where everything is already resolved.""" line = factory.LineFactory(study=self.target_study) protocol = factory.ProtocolFactory() assay = factory.AssayFactory(line=line, protocol=protocol) mtype = factory.MetaboliteFactory() unit = factory.UnitFactory() # no measurements exist before import self.assertEqual( models.Measurement.objects.filter( study_id=self.target_study.pk).count(), 0) self._set_permission(permission_type=models.StudyPermission.WRITE) run = TableImport(self.target_study, self.user) added, updated = run.import_series_data([{ "line_id": line.id, "assay_id": assay.id, "measurement_id": mtype.id, "comp_id": models.Measurement.Compartment.UNKNOWN, "units_id": unit.id, "metadata": {}, "data": [[0, 0]], }]) # after the self-reported add/update are correct self.assertEqual(added, 1) self.assertEqual(updated, 0) # and the counts are correct self.assertEqual( models.Measurement.objects.filter( study_id=self.target_study.pk).count(), 1)
def test_resolve_broad_type_with_pubchem_existing(self): broad = factory.CategoryFactory() type_A = main_factory.MetaboliteFactory(pubchem_cid="9999") tr = TypeResolver(self.user, broad) # on_commit hook will never trigger in test # but check that something should / should-not happen with patch("main.models.measurement_type.transaction") as hook: found = tr.lookup_type("CID:9999") assert found.pk == type_A.pk hook.on_commit.assert_not_called()
def test_resolve_metabolite_type(self): metabolomics = factory.CategoryFactory( type_group=models.MeasurementType.Group.METABOLITE) type_A = main_factory.MetaboliteFactory(pubchem_cid="9999") tr = TypeResolver(self.user, metabolomics) # on_commit hook will never trigger in test # but check that something should / should-not happen with patch("main.models.measurement_type.transaction") as hook: found = tr.lookup_type("CID:9999") assert found.pk == type_A.pk hook.on_commit.assert_not_called()