Exemplo n.º 1
0
 def test_users_list_with_study(self):
     study = factory.StudyFactory()
     url = reverse("rest:users-list")
     self.client.force_login(self.admin)
     response = self.client.get(url, {"in_study": study.slug})
     self._check_status(response, status.HTTP_200_OK)
     assert "count" in response.data
Exemplo n.º 2
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     # initialize study for worklist
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.READ, user=cls.user)
     # initialize protocol for worklist
     cls.protocol = factory.ProtocolFactory(name="potato")
     # initialize twenty lines in the study, 1-base index
     cls.lines = [
         factory.LineFactory(name=f"L{i}", study=cls.study)
         for i in range(1, 21)
     ]
     # initialize 3x assays on lines 6, 8, 10, 12, 14 (1-base)
     # assays at times 12, 24, 36
     time = models.MetadataType.system("Time")
     cls.assays = [
         factory.AssayFactory(
             line=cls.lines[line],
             metadata={time.pk: 12 * i},
             name=f"{cls.lines[line].name}-A{i}",
             protocol=cls.protocol,
         ) for line in range(5, 14, 2) for i in range(1, 4)
     ]
Exemplo n.º 3
0
Arquivo: tests.py Projeto: JBEI/edd
 def _writable_study(self):
     study = factory.StudyFactory()
     study.userpermission_set.update_or_create(
         permission_type=edd_models.StudyPermission.WRITE,
         user=self.user,
     )
     return study
Exemplo n.º 4
0
    def test_combinatorial_metadata_parsing(self):
        """
        Tests parsing of combinatorial assay metadata from an Experiment Description file, e.g.
        as used in the Skyline workflow for proteomics.
        """
        ed_file = factory.test_file_path(
            "experiment_description/advanced.xlsx")
        study = factory.StudyFactory()
        # creating *AFTER* setup of testing database records
        cache = ExperimentDescriptionContext()

        importer = CombinatorialCreationImporter(study, self.testuser, cache)
        parser = ExperimentDescFileParser(cache, importer)
        parsed: List[CombinatorialDescriptionInput] = parser.parse_excel(
            ed_file)
        combo_input: CombinatorialDescriptionInput = parsed[0]

        time_meta_type = models.MetadataType.system("Time")
        self.assertDictEqual(
            combo_input.protocol_to_combinatorial_meta_dict,
            {
                self.targeted_proteomics.pk: {
                    time_meta_type.pk: [8.0, 24.0]
                },
                self.metabolomics.pk: {
                    time_meta_type.pk: [4.0, 6.0]
                },
            },
        )
Exemplo n.º 5
0
    def test_single_valued_metadata_parsing(self):
        """
        Tests parsing of single-valued (non-combinatorial) assay metadata from an Experiment
        Description file,  e.g. as used in the Skyline workflow for proteomics.
        """
        lines_iter = iter(
            ("Line Name, Targeted Proteomics Time", "A, 2h", "B, 5h"))
        study = factory.StudyFactory()
        # creating *AFTER* setup of testing database records
        cache = ExperimentDescriptionContext()

        importer = CombinatorialCreationImporter(study, self.testuser, cache)
        parser = ExperimentDescFileParser(cache, importer)
        parsed: List[CombinatorialDescriptionInput] = parser.parse_csv(
            lines_iter)

        time_meta_type = models.MetadataType.system("Time")
        self.assertDictEqual(
            parsed[0].protocol_to_assay_metadata,
            {self.targeted_proteomics.pk: {
                time_meta_type.pk: 2.0
            }},
        )

        self.assertDictEqual(
            parsed[1].protocol_to_assay_metadata,
            {self.targeted_proteomics.pk: {
                time_meta_type.pk: 5.0
            }},
        )
Exemplo n.º 6
0
 def test_metadata_types_list_in_study(self):
     study = factory.StudyFactory()
     url = reverse("rest:metadata_types-list")
     self.client.force_login(self.admin)
     response = self.client.get(url, {"in_study": study.slug})
     self._check_status(response, status.HTTP_200_OK)
     assert response.data["count"] == 0
Exemplo n.º 7
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.study = main_factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.user, permission_type=models.StudyPermission.WRITE)
     cls.protocol = main_factory.ProtocolFactory()
Exemplo n.º 8
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.study = factory.StudyFactory()
     cls.study_kwargs = {"slug": cls.study.slug}
     cls.study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.WRITE, user=cls.user)
Exemplo n.º 9
0
 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())
Exemplo n.º 10
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.read_only_group = GroupFactory()
     cls.write_only_group = GroupFactory()
     cls.superuser = UserFactory(is_superuser=True)
     cls.unprivileged_user = UserFactory()
     cls.readonly_user = UserFactory()
     cls.write_user = UserFactory()
     cls.group_readonly_user = UserFactory()
     cls.group_readonly_user.groups.add(cls.read_only_group)
     cls.group_write_user = UserFactory()
     cls.group_write_user.groups.add(cls.write_only_group)
     cls.staff_user = UserFactory(is_staff=True)
     cls.staff_user.user_permissions.add(
         *load_permissions(models.Study, "add_study", "change_study", "delete_study")
     )
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.readonly_user, permission_type=models.StudyPermission.READ
     )
     cls.study.userpermission_set.create(
         user=cls.write_user, permission_type=models.StudyPermission.WRITE
     )
     cls.study.grouppermission_set.create(
         group=cls.read_only_group, permission_type=models.StudyPermission.READ
     )
     cls.study.grouppermission_set.create(
         group=cls.write_only_group, permission_type=models.StudyPermission.WRITE
     )
Exemplo n.º 11
0
    def test_advanced_experiment_description_xlsx(self):
        strain, _ = models.Strain.objects.get_or_create(name="JW0111")
        # creating *AFTER* setup of testing database records
        cache = ExperimentDescriptionContext()
        cache.strains_by_pk = {strain.pk: strain}

        advanced_experiment_def_xlsx = factory.test_file_path(
            "experiment_description/advanced.xlsx")
        study = factory.StudyFactory()
        importer = CombinatorialCreationImporter(study, self.testuser, cache)
        parser = ExperimentDescFileParser(cache, importer)
        parsed = parser.parse_excel(advanced_experiment_def_xlsx)
        self.assertEqual(len(parsed), 1,
                         "Expected a single set of parsed input")
        # TODO: following two calls should go away
        self._map_input_strains(parsed, cache, {"JBx_002078": strain})
        importer._query_related_object_context(parsed)
        result = parsed[0].populate_study(study, importer.cache,
                                          ExperimentDescriptionOptions())

        self.assertFalse(importer.errors, "Import generated errors")
        self.assertFalse(importer.warnings, "Import generated warnings")
        for line in result.lines_created:
            self.assertEqual(line.description, "Description blah blah")
            self.assertEqual(line.assay_set.count(), 4)
Exemplo n.º 12
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.user, permission_type=models.StudyPermission.WRITE)
     cls.protocol = factory.ProtocolFactory()
     cls.measurement_type = factory.MeasurementTypeFactory()
Exemplo n.º 13
0
 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)
     # define expected lines for PCAP files
     CREATE_PCAP_LINES(cls.target_study)
Exemplo n.º 14
0
Arquivo: tests.py Projeto: JBEI/edd
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     # initialize study
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.READ, user=cls.user)
     factory.create_fake_exportable_study(cls.study)
Exemplo n.º 15
0
    def test_basic_json(self):
        """
        A simplified integration test that exercises much of the EDD code
        responsible for combinatorial line creation based on a simplified
        input, creating replicates for a single line with some metadata using
        a known strain. Test inputs in this example roughly correspond to the
        sample experiment description file attached to EDD-380.

        Testing the full code path for EDD's experiment description file
        support requires having a corresponding ICE deployment to use as part
        of the test, so it's not addressed here.
        """
        meta = factory.MetadataTypeFactory(for_context=models.MetadataType.LINE)
        # Create strains for this test
        strain, _ = models.Strain.objects.get_or_create(name="JW0111")
        control = models.MetadataType.system("Control")

        # creating *AFTER* setup of testing database records
        cache = ExperimentDescriptionContext()
        cache.strains_by_pk = {strain.pk: strain}

        # define test input
        test_input = {
            "name_elements": {"elements": ["_custom_1", "replicate_num"]},
            "custom_name_elts": {"_custom_1": "181-aceF"},
            "replicate_count": 3,
            "combinatorial_line_metadata": {},
            "common_line_metadata": {
                str(meta.pk): "LB",
                str(control.pk): False,
                str(cache.strains_mtype.pk): [str(strain.uuid)],
            },
        }

        study = factory.StudyFactory()
        importer = CombinatorialCreationImporter(study, self.testuser, cache)
        parser = JsonInputParser(cache, importer)
        parsed = parser.parse(json.dumps(test_input))
        self.assertEqual(len(parsed), 1, "Expected a single set of parsed input")
        # TODO: following two calls should go away
        self._map_input_strains(parsed, cache, {str(strain.uuid): strain})
        importer._query_related_object_context(parsed)
        result = parsed[0].populate_study(
            study, importer.cache, ExperimentDescriptionOptions()
        )

        self.assertFalse(importer.errors, "Import generated errors")
        self.assertFalse(importer.warnings, "Import generated warnings")
        expected_line_names = ["181-aceF-R1", "181-aceF-R2", "181-aceF-R3"]
        expected_meta = {meta.pk: "LB"}
        for line in result.lines_created:
            self.assertIn(line.name, expected_line_names)
            self.assertFalse(line.control)
            strains_list = list(line.strains.values_list("id", flat=True))
            self.assertEqual(strains_list, [strain.pk])
            # because of replicate, the expected metadata is a subset of actual
            assert {*expected_meta.items()}.issubset({*line.metadata.items()})
Exemplo n.º 16
0
 def _setup_study_with_data_for_export(self):
     # create study and line with 30 assays
     # each assay with one measurement having one value
     self.study = factory.StudyFactory()
     self.line = factory.LineFactory(study=self.study)
     for _i in range(30):
         assay = factory.AssayFactory(line=self.line)
         measurement = factory.MeasurementFactory(assay=assay)
         factory.ValueFactory(measurement=measurement)
Exemplo n.º 17
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     # initialize study for worklist
     study = factory.StudyFactory()
     study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.READ, user=cls.user)
     line = factory.LineFactory(study=study)
     cls.payload = {"lineId": [line.id]}
Exemplo n.º 18
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.user, permission_type=models.StudyPermission.WRITE)
     cls.protocol = factory.ProtocolFactory()
     cls.category = CategoryFactory()
     cls.layout = LayoutFactory()
Exemplo n.º 19
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.target_study = main_factory.StudyFactory()
     cls.target_study.userpermission_set.create(
         user=cls.user, permission_type=models.StudyPermission.WRITE)
     cls.BW1 = main_factory.LineFactory(study=cls.target_study, name="BW1")
     cls.arcA = main_factory.LineFactory(study=cls.target_study,
                                         name="arcA")
     cls.target_kwargs = {"slug": cls.target_study.slug}
     cls.protocol = main_factory.ProtocolFactory()
Exemplo n.º 20
0
 def test_update_load_wrong_study(self):
     # updating loading data on the wrong study is not OK
     wrong = main_factory.StudyFactory()
     load = LoadRequest(study_uuid=wrong.uuid)
     load.store()
     url = rest_reverse("rest:study_load-detail",
                        args=[self.study.pk, load.request])
     payload = self._build_common_payload()
     self.client.force_login(self.user)
     response = self.client.patch(url, payload, format="multipart")
     assert response.status_code == status.HTTP_400_BAD_REQUEST
Exemplo n.º 21
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.protocol = factory.ProtocolFactory()
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.user, permission_type=models.StudyPermission.WRITE)
     cls.arcA = factory.LineFactory(study=cls.study, name="arcA")
     cls.mtype = factory.MeasurementTypeFactory()
     cls.x_unit = factory.UnitFactory()
     cls.y_unit = factory.UnitFactory()
Exemplo n.º 22
0
 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")
Exemplo n.º 23
0
 def setUpTestData(cls):
     super().setUpTestData()
     User = get_user_model()
     cls.admin = User.objects.get(username="******")
     # create study and line with 30 assays
     # each assay with one measurement having one value
     cls.study = factory.StudyFactory()
     cls.line = factory.LineFactory(study=cls.study)
     for _i in range(30):
         assay = factory.AssayFactory(line=cls.line)
         measurement = factory.MeasurementFactory(assay=assay)
         factory.ValueFactory(measurement=measurement)
Exemplo n.º 24
0
 def test_upload_links_admin(self):
     admin_study = factory.StudyFactory()
     admin_study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.WRITE, user=self.admin_ice_user
     )
     response = self._run_upload(self.entry_ids, admin_study, self.admin_ice_user)
     # should return OK from upload
     self.assertEqual(response.status_code, codes.ok, response.content)
     # there should be 10 strains on the study
     self.assertEqual(
         models.Strain.objects.filter(line__study=admin_study).distinct().count(), 10
     )
Exemplo n.º 25
0
 def test_add_remove_experiment_link(self):
     with self.registry.login(self.admin_ice_user):
         study = factory.StudyFactory()
         study_url = f"https://edd.example.org/s/{study.slug}/"
         entry = self.registry.get_entry(self.entry_ids[3])
         entry.add_link(study.name, study_url)
         # verify link exists on a given entry
         found_links = list(entry.list_links())
         assert len(found_links) == 1
         # verify that removal works
         for link in found_links:
             entry.remove_link(link[0])
         found_links = list(entry.list_links())
         assert len(found_links) == 0
Exemplo n.º 26
0
 def test_upload_links_none(self):
     none_study = factory.StudyFactory()
     none_study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.WRITE, user=self.none_ice_user
     )
     # should return 400 error on uploading admin-only strains
     response = self._run_upload(self.entry_ids, none_study, self.none_ice_user)
     self.assertEqual(response.status_code, codes.bad_request, response.content)
     # should return 400 error on uploading reader-only strains
     response = self._run_upload(self.entry_ids[:5], none_study, self.none_ice_user)
     self.assertEqual(response.status_code, codes.bad_request)
     # there should be 0 strains on the study
     self.assertEqual(
         models.Strain.objects.filter(line__study=none_study).distinct().count(), 0
     )
Exemplo n.º 27
0
 def test_add_remove_experiment_link(self):
     admin_auth = HmacAuth("edd", self.admin_ice_user.email)
     ice = IceApi(admin_auth)
     ice.write_enabled = True
     study = factory.StudyFactory()
     study_url = f"https://edd.example.org/s/{study.slug}/"
     for entry_id in self.db_ids:
         ice.add_experiment_link(entry_id, study.name, study_url)
     # verify link exists on a given entry
     found_links = list(ice.fetch_experiment_links(self.db_ids[3]))
     self.assertEqual(len(found_links), 1)
     # verify that removal works
     ice.unlink_entry_from_study(self.db_ids[3], study_url)
     found_links = list(ice.fetch_experiment_links(self.db_ids[3]))
     self.assertEqual(len(found_links), 0)
Exemplo n.º 28
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.readonly_user = UserFactory()
     cls.study = factory.StudyFactory()
     cls.study.userpermission_set.create(
         user=cls.readonly_user,
         permission_type=models.StudyPermission.READ)
     cls.strains = [
         factory.StrainFactory(),
         factory.StrainFactory(),
         factory.StrainFactory(),
     ]
     for i in range(10):
         line = factory.LineFactory(study=cls.study)
         line.strains.add(cls.strains[i % len(cls.strains)])
Exemplo n.º 29
0
 def test_upload_links_reader(self):
     reader_study = factory.StudyFactory()
     reader_study.userpermission_set.update_or_create(
         permission_type=models.StudyPermission.WRITE,
         user=self.read_ice_user)
     # should return 500 error on uploading admin-only strains
     # skip testing this until ICE-90 is resolved
     # response = self._run_upload(self.part_ids, reader_study, self.read_ice_user)
     # self.assertEqual(response.status_code, codes.server_error)
     # should return OK on uploading readable strains
     response = self._run_upload(self.part_ids[:5], reader_study,
                                 self.read_ice_user)
     self.assertEqual(response.status_code, codes.ok)
     # there should be 5 strains on the study
     self.assertEqual(
         models.Strain.objects.filter(
             line__study=reader_study).distinct().count(), 5)
Exemplo n.º 30
0
    def setUpTestData(cls):
        super().setUpTestData()

        # create a test user and give it permission to write to the study
        User = get_user_model()
        cls.write_user = User.objects.create(username='******')
        cls.unprivileged_user = User.objects.create(
            username='******')

        cls.user_write_study = main_factory.StudyFactory(
            name='User-writeable study')
        permissions = cls.user_write_study.userpermission_set
        permissions.update_or_create(
            permission_type=edd_models.UserPermission.WRITE,
            user=cls.write_user)
        cls.url = reverse('edd.rest:study-imports-detail',
                          kwargs={
                              'study_pk': cls.user_write_study.pk,
                              'pk': 15
                          })