Example #1
0
 def test_step2_sbml_export(self):
     "Second step selects an SBML Template."
     with factory.load_test_file("ExportData_FBA_step2.post") as fp:
         POST = QueryDict(fp.read())
     response = self.client.post(reverse("export:sbml"), data=POST)
     self.assertEqual(response.status_code, codes.ok)
     self.assertEqual(len(response.context["sbml_warnings"]), 5)
Example #2
0
 def _build_import_context(self, base, import_id):
     # load post data broken up across multiple files
     filename = f"{base}.post.context.json"
     with factory.load_test_file(filename, "rt") as context_file:
         context = json.load(context_file)
     # make sure import_id is a string if a raw UUID is passed
     context.update(importId=str(import_id))
     return context
Example #3
0
 def test_post_DescribeView_writer_xlsx(self):
     self.client.force_login(self.user)
     url = reverse("main:describe:describe", kwargs=self.study_kwargs)
     filename = "ExperimentDescription_simple.xlsx"
     with factory.load_test_file(filename) as fp:
         file = io.BytesIO(fp.read())
     file.name = filename
     file.content_type = XLSX_CONTENT_TYPE
     payload = {"file": file}
     response = self.client.post(url, payload)
     self.assertEqual(response.status_code, codes.ok)
     self.assertEqual(self.study.line_set.count(), 2)
Example #4
0
 def _populateTestStrains(cls, registry):
     with factory.load_test_file("ice_entries.csv") as entries_file:
         registry.bulk_upload(entries_file)
     # fetch the part IDs
     it = registry.iter_entries(sort="created", asc="false", limit=10)
     entries = list(itertools.islice(it, 10))
     # set read permissions on some of the created strains
     for entry in entries[:5]:
         entry.set_permission(cls.read_ice_user._ice_id)
     # stash the part IDs for use in tests
     cls.entry_ids = [entry.part_id for entry in entries]
     return entries
Example #5
0
 def _run_parse_view(self, filename, filetype, mode):
     with factory.load_test_file(filename) as fp:
         upload = BytesIO(fp.read())
     upload.name = filename
     response = self.client.post(
         reverse("load_flat:parse"),
         data={
             "file": upload,
             "X_EDD_FILE_TYPE": filetype,
             "X_EDD_IMPORT_MODE": mode,
         },
     )
     self.assertEqual(response.status_code, codes.ok)
     with factory.load_test_file(filename + ".json") as fp:
         reader = codecs.getreader("utf-8")
         target = json.load(reader(fp))
     # check that objects are the same when re-serialized with sorted keys
     self.assertEqual(
         json.dumps(target, sort_keys=True),
         json.dumps(response.json(), sort_keys=True),
     )
     return response
Example #6
0
 def test_post_DescribeView_writer_xlsx_bad_headers(self):
     self.client.force_login(self.user)
     url = reverse("main:describe:describe", kwargs=self.study_kwargs)
     filename = "ExperimentDescription_bad_headers.xlsx"
     with factory.load_test_file(filename) as fp:
         file = io.BytesIO(fp.read())
     file.name = filename
     file.content_type = XLSX_CONTENT_TYPE
     payload = {"file": file}
     response = self.client.post(url, payload)
     self.assertEqual(response.status_code, codes.ok)
     self.assertEqual(self.study.line_set.count(), 2)
     messages = response.json()
     self.assertNotIn("errors", messages)
     self.assertIn("warnings", messages)
     self.assertEqual(messages["warnings"][0]["category"],
                      "User input ignored")
Example #7
0
 def _populateTestStrains(cls, ice):
     # create a BulkUpload object
     response = ice.session.put(ice_url("/uploads"),
                                json={"type": "strain"})
     upload_id = response.json()["id"]
     # add file data to the BulkUpload
     with factory.load_test_file("ice_entries.csv") as entries:
         response = ice.session.post(
             ice_url(f"/uploads/{upload_id}/file"),
             files={
                 "type": "strain",
                 "file": entries
             },
         )
     # set upload to approved to create (click "submit" button)
     response = ice.session.put(
         ice_url(f"/uploads/{upload_id}/status"),
         json={
             "id": upload_id,
             "status": "APPROVED"
         },
     )
     # fetch the part IDs
     response = ice.session.get(
         ice_url("/collections/available/entries"),
         params={
             "sort": "created",
             "asc": "false"
         },
     )
     entries = response.json()["data"][:10]
     cls.part_ids = [p["partId"] for p in reversed(entries)]
     cls.db_ids = [p["id"] for p in reversed(entries)]
     # set read permissions on some of the created strains
     for idx in range(5):
         response = ice.session.post(
             ice_url(f"/parts/{cls.part_ids[idx]}/permissions"),
             json={
                 "article": "ACCOUNT",
                 "articleId": cls.read_ice_user._ice_id,
                 "type": "READ_ENTRY",
                 "typeId": cls.db_ids[idx],
             },
         )
Example #8
0
 def test_post_DescribeView_writer_xlsx_double_import(self):
     # run test_post_DescribeView_writer_xlsx
     self.test_post_DescribeView_writer_xlsx()
     # then do its insides again, checking for errors
     url = reverse("main:describe:describe", kwargs=self.study_kwargs)
     filename = "ExperimentDescription_simple.xlsx"
     with factory.load_test_file(filename) as fp:
         file = io.BytesIO(fp.read())
     file.name = filename
     file.content_type = XLSX_CONTENT_TYPE
     payload = {"file": file}
     response = self.client.post(url, payload)
     self.assertEqual(response.status_code, codes.bad_request)
     self.assertEqual(self.study.line_set.count(), 2)
     messages = response.json()
     self.assertIn("errors", messages)
     self.assertEqual(len(messages["errors"]), 1)
     self.assertEqual(messages["errors"][0]["category"],
                      "Non-unique line names")
Example #9
0
File: tests.py Project: JBEI/edd
    def test_upload_experiment_description_xlsx_adds_entry(self):
        study = self._writable_study()
        filename = "ExperimentDescription_simple.xlsx"
        with factory.load_test_file(filename) as fp:
            file = io.BytesIO(fp.read())
        file.name = filename
        file.content_type = (
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        )

        self.client.post(
            reverse("main:describe:describe", kwargs={"slug": study.slug}),
            {"file": file},
        )

        qs = self._find_log(event=StudyLog.Event.DESCRIBED, study=study)
        assert qs.count() == 1
        sl = qs.get()
        assert sl.detail == {"count": 2}
Example #10
0
 def test_post_DescribeView_writer_xlsx_bad_values(self):
     self.client.force_login(self.user)
     url = reverse("main:describe:describe", kwargs=self.study_kwargs)
     filename = "ExperimentDescription_bad_values.xlsx"
     with factory.load_test_file(filename) as fp:
         file = io.BytesIO(fp.read())
     file.name = filename
     file.content_type = XLSX_CONTENT_TYPE
     payload = {"file": file}
     response = self.client.post(url, payload)
     self.assertEqual(response.status_code, codes.bad_request)
     self.assertEqual(self.study.line_set.count(), 0)
     messages = response.json()
     self.assertIn("errors", messages)
     self.assertIn("warnings", messages)
     self.assertEqual(len(messages["errors"]), 2)
     self.assertEqual(
         {"Incorrect file format", "Invalid values"},
         {err["category"]
          for err in messages["errors"]},
     )
Example #11
0
 def _build_import_pages(self, base):
     # load series data, slicing it up into pages if requested
     filename = f"{base}.post.series.json"
     with factory.load_test_file(filename, "rt") as series_file:
         yield from self._slice_series_pages(series_file)
Example #12
0
 def test_step3_sbml_export(self):
     "Third step maps metabolites to species/reactions, and selects an export timepoint."
     with factory.load_test_file("ExportData_FBA_step3.post") as fp:
         POST = QueryDict(fp.read())
     response = self.client.post(reverse("export:sbml"), data=POST)
     self.assertEqual(response.status_code, codes.ok)