def test_create_sample(self):
        sample_name = base.random_string(5)
        sample_tags = base.random_string(4)
        ef1 = inv.ExtraField("f1", inv.ExtraFieldType.TEXT, "hello")
        ef2 = inv.ExtraField("f2", inv.ExtraFieldType.NUMBER, 123)

        minTemp = inv.StorageTemperature(1, inv.TemperatureUnit.KELVIN)
        maxTemp = inv.StorageTemperature(4, inv.TemperatureUnit.KELVIN)
        expiry_date = dt.date(2024, 12, 25)
        amount = inv.Quantity(5, qu.QuantityUnit.of("ml"))
        sample = self.invapi.create_sample(
            name=sample_name,
            tags=sample_tags,
            extra_fields=[ef1, ef2],
            storage_temperature_min=minTemp,
            storage_temperature_max=maxTemp,
            expiry_date=expiry_date,
            total_quantity=amount,
            subsample_count=12,
            attachments=[open(base.get_any_datafile(), "rb")],
        )
        self.assertEqual(sample_name, sample["name"])
        self.assertEqual(2, len(sample["extraFields"]))
        self.assertEqual(4, sample["storageTempMax"]["numericValue"])
        self.assertEqual(1, sample["storageTempMin"]["numericValue"])
        self.assertEqual(12, sample["subSamplesCount"])
        self.assertEqual(expiry_date.isoformat(), sample["expiryDate"])
        self.assertEqual(1, len(sample["attachments"]))
        s_ob = inv.Sample(sample)
 def test_move_container_to_list_container(self):
     name = base.random_string() + "_to_move"
     toMove = self.invapi.create_list_container(name)
     name_target = base.random_string() + "_target"
     target = self.invapi.create_list_container(name_target)
     moved = self.invapi.add_items_to_list_container(
         target["id"], toMove["globalId"])
     self.assertTrue(moved.is_ok())
    def test_move_subsamples_to_list_container(self):
        name = base.random_string() + "_to_move"
        toMove = self.invapi.create_sample(name, subsample_count=2)
        name_target = base.random_string() + "_target"
        target = self.invapi.create_list_container(name_target)

        ## get the 2 subsample ids ad move to container
        subsample_ids = [ss["globalId"] for ss in toMove["subSamples"]]
        moved = self.invapi.add_items_to_list_container(
            target["id"], *subsample_ids)
        self.assertTrue(moved.is_ok())
 def test_upload_file(self):
     sample = self.invapi.create_sample(base.random_string())
     data_file = base.get_any_datafile()
     with open(data_file, "rb") as f:
         resp = self.invapi.uploadAttachment(sample["globalId"], f)
         self.assertIsNotNone(resp["id"])
         self.assertTrue(resp["globalId"][0:2] == "IF")
 def test_add_note_to_subsample(self):
     note = " a note about a subsample " + base.random_string()
     sample = self.invapi.create_sample("with_note", subsample_count=1)
     ss = sample["subSamples"][0]
     updated = self.invapi.add_note_to_subsample(ss, note)
     self.assertEqual(1, len(updated["notes"]))
     self.assertEqual(note, updated["notes"][0]["content"])
 def test_equal_split(self):
     name = base.random_string()
     sample = self.invapi.create_sample(name)
     ss = sample["subSamples"][0]
     splits = self.invapi.split_subsample(ss, num_new_subsamples=3)
     self.assertEqual(3, len(splits))
     self.assertAlmostEqual(
         750, sum([x["quantity"]["numericValue"] for x in splits]))
 def test_paginated_containers(self):
     pag = inv.Pagination(page_number=0, page_size=1)
     name = base.random_string()
     c = self.invapi.create_list_container(name)
     c = self.invapi.set_as_top_level_container(c)
     containers = self.invapi.list_top_level_containers(pag)
     self.assertEqual(0, containers["pageNumber"])
     self.assertEqual(1, len(containers["containers"]))
    def test_add_extra_fields(self):
        sample = self.invapi.create_sample(base.random_string())
        ef1 = inv.ExtraField(name="ef1", content="ef1 content")
        ef2 = inv.ExtraField(name="ef2", content="ef2 content")
        updatedS = self.invapi.add_extra_fields(sample["globalId"], ef1, ef2)
        self.assertEqual(2, len(updatedS["extraFields"]))

        container = self.invapi.create_list_container("any list container")
        updatedC = self.invapi.add_extra_fields(container, ef2)
        self.assertEqual(1, len(updatedC["extraFields"]))
    def test_search_sample(self):
        name = base.random_string()
        tags = base.random_string()
        sample = self.invapi.create_sample(name, tags=tags)
        results = self.invapi.search(query=name)
        ## sample and its subsample
        self.assertEqual(2, results["totalHits"])
        results_from_tag = self.invapi.search(query=tags)
        self.assertEqual(1, results_from_tag["totalHits"])

        results2 = self.invapi.search(query=name,
                                      result_type=inv.ResultType.SAMPLE)
        self.assertEqual(1, results2["totalHits"])
        results3 = self.invapi.search(query=name,
                                      result_type=inv.ResultType.SUBSAMPLE)
        self.assertEqual(1, results3["totalHits"])
        results4 = self.invapi.search(query=name,
                                      result_type=inv.ResultType.CONTAINER)
        self.assertEqual(0, results4["totalHits"])
    def test_stream_samples(self):
        onePerPage = inv.Pagination(page_size=1)
        gen = self.invapi.stream_samples(onePerPage)
        # get 2 items
        s1 = next(gen)
        s2 = next(gen)
        self.assertNotEqual(s1["id"], s2["id"])

        unknown_user = base.random_string(15)
        sample_filter = inv.SearchFilter(owned_by=unknown_user)
        gen = self.invapi.stream_samples(onePerPage, sample_filter)
        result_count = 0
        for sample in gen:
            result_count += 1
        self.assertEqual(0, result_count)
    def test_duplicate(self):
        name = base.random_string()

        container = self.invapi.create_list_container("c_to_dup")
        container_dup = self.invapi.duplicate(container, f"{name}-newfromtest")
        self.assertNotEqual(container["id"], container_dup["id"])
        self.assertEqual(f"{name}-newfromtest", container_dup["name"])

        sample = self.invapi.create_sample(name)
        sample_dup = self.invapi.duplicate(sample)
        self.assertNotEqual(sample["id"], sample_dup["id"])

        ss = sample["subSamples"][0]
        ss_dup = self.invapi.duplicate(ss)
        self.assertNotEqual(ss["id"], ss_dup["id"])
    def test_create_list_container(self):
        name = base.random_string()
        ct = self.invapi.create_list_container(name, tags="ab,cd,ef")
        self.assertTrue(ct["cType"] == "LIST")
        self.assertEqual(0, len(ct["parentContainers"]))

        ## create in workbench
        ct_in_wb = self.invapi.create_list_container(name,
                                                     tags="ab,cd,ef",
                                                     location="w")
        self.assertEqual("BE",
                         ct_in_wb["parentContainers"][0]["globalId"][0:2])

        ## create in parent list container
        ct_sub_container = self.invapi.create_list_container(name,
                                                             tags="ab,cd,ef",
                                                             location=ct["id"])
        self.assertEqual(ct["globalId"],
                         ct_sub_container["parentContainers"][0]["globalId"])
    def test_partial_split(self):
        name = base.random_string()
        sample_total = inv.Quantity(5, qu.QuantityUnit.of("ml"))
        ## create 1 sample with 1 ss of 5ml
        sample = self.invapi.create_sample(name, total_quantity=sample_total)
        ss = sample["subSamples"][0]
        bulk_result = self.invapi.split_subsample(ss,
                                                  num_new_subsamples=3,
                                                  quantity_per_subsample=1.2)

        self.assertTrue(bulk_result.is_ok())
        results = bulk_result.data["results"]

        ## should result in original with (5 - (3 *1.2) = 1.4, new ones with 1.2
        ss_to_amount = {}
        for updated_ss in results:
            ss_to_amount[updated_ss["record"]["id"]] = updated_ss["record"][
                "quantity"]["numericValue"]

        self.assertAlmostEqual(1.4, ss_to_amount[ss["id"]])
        ss_to_amount.pop(ss["id"])
        for v in ss_to_amount.values():
            self.assertAlmostEqual(1.2, v)
Beispiel #14
0
 def test_create_document(self):
     nameStr = random_string(10)
     tag_str = random_string(5)
     resp = self.api.create_document(name=nameStr, tags=tag_str)
     self.assertEqual(nameStr, resp["name"])
     self.assertEqual(tag_str, resp["tags"])
 def test_rename_item(self):
     sample = self.invapi.create_sample(base.random_string(5))
     new_name = base.random_string()
     updated = self.invapi.rename(sample["globalId"], new_name)
     self.assertEqual(new_name, updated["name"])
 def test_get_single_sample(self):
     sample = self.invapi.create_sample(base.random_string(5))
     sample2 = self.invapi.get_sample_by_id(sample["id"])
     sample3 = self.invapi.get_sample_by_id(sample["globalId"])
     self.assertEqual(sample["name"], sample2["name"])
     self.assertEqual(sample["name"], sample3["name"])
 def test_transfer_sample_owner(self):
     sample = self.invapi.create_sample(base.random_string(5))
     updated = self.invapi.transfer_sample_owner(sample["id"], "user2b")
     self.assertEqual("user2b", updated["owner"]["username"])
 def test_create_sample_name_only(self):
     sample = self.invapi.create_sample(base.random_string(5))
     self.assertIsNotNone(sample)